2H -> H -> F -> HB -> B -> 2B H means Hard (hard-tipped) B means Bold (soft-tipped) F means Fine Info: from left to right, writing is thicker on the paper.
Generally, it would say that H (Hard) is designed for drafting and S (Soft) is designed for writing.
After every DDL operation, implicit commit occurs such as while defining a new table. e.g. CREATE TABLE HR.EXAMPLE(ABC char(1)); Also we call it as "auto commit" operation.
BLOB (binary large objects) stores unstructured binary large objects. It is often used for graphic images, video clips, and sounds. The BLOB data type stores the content inside the Oracle database. BFILE (binary file) is also used to large binary file stored outside the database. Oracle can read the file only, not modify it. Oracle requires appropriate operating system level read permissions on the file. Ref: Oracle SQL Interactive Workbook (Alice Rischert)
CTAS stands for Create Table As Select e.g. SQL> CREATETABLE HR.EMPLOYEES_NEW AS SELECT * FROM HR.EMPLOYEES; -> By default, only "NOT_NULL" constraints copy to new table (HR.EMPLOYEES_NEW) if it has (HR.EMPLOYEES). (PK, FK, index, etc. does not copy) CTAS is faster because UNDO and REDO data does not generate. (It use NOLOGGING AND PARALEL methods)
-> HR.EMPLOYEES will be test table. SQL> DESC HR.EMPLOYEES; e.g. To populate all data SQL> SELECT * FROM HR.EMPLOYEES; To manipulate data by "COMMISSION_PCT" column descending order. SQL> SELECT * FROM HR.EMPLOYEES ORDER BY COMMISSION_PCT DESC; -> This is wrong query cause "NULL" columns show on top. Therefore, "NULLS LAST" keyword should be used. SQL> SELECT * FROM HR.EMPLOYEES ORDER BY COMMISSION_PCT DESC NULLS LAST;
Preparation SQL> create table A (id number, soid number); SQL> create table B (id number); Action SQL> alter table A add constraint SOID_B_FK foreign key (soid) references B (id); Error ORA-02270: no matching unique or primary key for this column-list Reason Parent table (B) does not have any primary key for matching with child table (A) Solution SQL> alter table B add constraint ID_PK primary key (id);
Action SQL> CREATE TABLE HR.EXAMPLE(ABC char(1)); Error ORA-00959: tablespace '_$deleted$40$0' does not exist Reason Defined default tablespace is not available any more for HR user. Solution SQL> ALTER USER HR DEFAULT TABLESPACE NEW_USERS;
Preparation SQL> -- A table is child table create table A (id number, soid number);
SQL> -- B table is parent table create table B (id number); SQL> alter table B add constraint ID_B_PK primary key (id); SQL> alter table A add constraint ID_A_PK primary key (id); SQL> alter table A add constraint SOID_B_FK foreign key (soid) references B (id); Action SQL> drop table B; Error ORA-02449: unique/primary keys in table referenced by foreign keys Solution SQL> drop table B cascade constraints; Result By "cascade constraints" keywords, only SOID_B_FK foreign key removed from Table A, ID_A_PK primary key remains for Table A.
Preparation "employees" table exists in HR schema "v_employees" view exists in HR2 schema; SQL> grant select on hr.employees_new to hr2; SQL> create view hr2.v_employees as select * from hr.employees; User wants to see H2.V_EMPLOYEES view with HR3 user. Action SQL> grant select on hr2.v_employees to hr3; Error ORA-01720: grant option does not exist for 'HR.EMPLOYEES' Solution Append grant option to HR.EMPLOYEES table for HR2 user SQL> grant select on hr.employees to hr2 with grant option; Then, grant select permission to HR3 user SQL> grant select on hr2.v_employees to hr3; Result SQL> select * from HR2.v_employees;
e.g. If there are only 32 bit Linux distro in the OS list, you should enable virtualization support in BIOS * BIOS -> CMOS Setup Utility -> Virtualization Technology -> [Enabled]
SET TIMING ON / CREATE TABLE HR.EMPLOYEES_TEST AS SELECT * FROM HR.EMPLOYEES WHERE ROWNUM < 0; / DECLARE TYPE TABLE_TYP IS TABLE OF HR.EMPLOYEES%ROWTYPE; TABLE_ROWS TABLE_TYP := TABLE_TYP (); CURSOR TEST_CURSOR IS SELECT * FROM HR.EMPLOYEES; V_COUNT NUMBER; BEGIN SELECT COUNT (1) INTO V_COUNT FROM HR.EMPLOYEES; DBMS_OUTPUT.PUT_LINE ('TOTAL NUMBER OF ROWS: ' || V_COUNT); OPEN TEST_CURSOR; LOOP FETCH TEST_CURSOR BULK COLLECT INTO TABLE_ROWS LIMIT 10; FORALL A IN TABLE_ROWS.FIRST .. TABLE_ROWS.LAST INSERT INTO HR.EMPLOYEES_TEST VALUES TABLE_ROWS (A); COMMIT; DBMS_OUTPUT.PUT_LINE ( 'Looping, TEST_CURSOR%rowcount = ' || TEST_CURSOR%ROWCOUNT); EXIT WHEN TEST_CURSOR%NOTFOUND; --EXIT WHEN TEST_CURSOR%ROWCOUNT > 1000000; END LOOP; DBMS_OUTPUT.PUT_LINE ( 'Exited, TEST_CURSOR%rowcount = ' || TEST_CURSOR%ROWCOUNT); CLOSE TEST_CURSOR; END; /
index -> [SHORT_TABLE_NAME]_[SHORT_COLUMN_NAME]_[INDEX_TYPE] e.g. EMP_DEPARTMENT_IX constraint -> [SHORT_TABLE_NAME]_[SHORT_COLUMN_NAME]_[CONSTRAINT_TYPE] e.g. NOT NULL const. -> EMP_EMAIL_NN FOREIGN KEY (Referential Integrity) const. Source table: EMPLOYEES Column name of source table: DEPARTMENT_ID -> EMP_DEPT_FK trigger -> [TABLE_NAME]_TRG e.g. HR.EMPLOYEES_TRG sequence -> [TABLE_NAME]_SEQ e.g. HR.EMPLOYEES_SEQ type -> [TABLE_NAME]_TYP e.g. HR.EMPLOYEES_TYP
e.g. Toad for Oracle -> Type HR.EMPLOYEES then Press F4 in Editor -> Select desired columns by CTRL key-> Drag and drop to Editor by mouse -> Columns should show in Editor
Purpose The purpose of optimizer_index_cost_adj parameter is to force use index even the cost is high. (decides large-table full-table scans or index range scans) Usage Current setting: SQL> show parameter optimizer_index_cost_adj; -- default is 100 -- ranges between 1 and 10000 (options like -> 10 | 100 | 1000) Change setting permanently: add this into init.ora file; *.optimizer_index_cost_adj=10 -- "10" is to force it uses index -- "100" is the default value -- "1000" is not to force and it tries to different method (large-table full-table) to search data Then restart the instance to perform. Change setting for current instance - temporary: SQL> alter system set optimizer_index_cost_adj = 10; Result SQL> show parameter optimizer_index_cost_adj; -- output; 10
e.g. steps; lock table -> add new column for primary key -> update data with counter -> define sequence -> define trigger -> lastly, define primary key -> recompile invalid objects (optional) SQL> LOCK TABLE HR.EMPLOYEES_NEW IN EXCLUSIVE MODE NOWAIT / ALTER TABLE HR.EMPLOYEES_NEW ADD (ID NUMBER) / DECLARE str_exec VARCHAR2 (250); counter NUMBER := 0; last_seq_id NUMBER; BEGIN FOR cur_node IN ( SELECT ROWID, id FROM HR.EMPLOYEES_NEW ORDER BY HIRE_DATE ASC) LOOP BEGIN str_exec := 'update HR.EMPLOYEES_NEW set id = ' || counter || ' where rowid = ' || '''' || cur_node.ROWID || ''''; --DBMS_OUTPUT.put_line (str_exec); EXECUTE IMMEDIATE str_exec; COMMIT; counter := counter + 1; END; END LOOP; SELECT ID INTO last_seq_id FROM ( SELECT ID FROM HR.EMPLOYEES_NEW WHERE ID IS NOT NULL ORDER BY ID DESC) WHERE ROWNUM < 2; str_exec := 'CREATE SEQUENCE HR.EMPLOYEES_NEW_ID_SEQ START WITH ' || last_seq_id || ' MAXVALUE 999999999999999999999999999999 MINVALUE ' || last_seq_id || ' NOCYCLE NOCACHE NOORDER'; --DBMS_OUTPUT.put_line (str_exec); EXECUTE IMMEDIATE str_exec; END; / CREATE OR REPLACE TRIGGER HR.TRG_EMPLOYEES_NEW_ID BEFORE INSERT ON HR.EMPLOYEES_NEW FOR EACH ROW BEGIN IF :new.ID IS NULL THEN :new.ID := HR.EMPLOYEES_NEW_ID_SEQ.NEXTVAL; END IF; END TRG_EMPLOYEES_NEW_ID; / ALTER TABLE HR.EMPLOYEES_NEW ADD CONSTRAINT EMPLOYEES_NEW_PK PRIMARY KEY (ID) ENABLE VALIDATE / EXEC SYS.UTL_RECOMP.recomp_parallel(4) /