Tuesday 21 April 2015

Few New features in Oracle 12C  (As published in asktheoracle.net)

1)Cascading Truncates:-


If you've been using Oracle for a while you probably already know about cascading deletes - when the parent record is deleted any child records are also deleted. This is enabled by specifying the clause ON DELETE CASCADE when defining the foreign key constraints. Here's an (artificial) example using employees and departmnets just to refresh your memory.
CREATE TABLE departments (
department_id NUMBER PRIMARY KEY
,department_name VARCHAR2 (30));
CREATE TABLE employees (
employee_id NUMBER PRIMARY KEY
,employee_name VARCHAR2 (30)
,department_id NUMBER,
CONSTRAINT fk_emp_dept FOREIGN KEY (department_id) REFERENCES departments(department_id) ON DELETE CASCADE);

INSERT INTO departments VALUES (1,'one');

INSERT INTO employees VALUES (1,'one',1);

DELETE departments ;

SELECT * FROM employees;
The select statememnt returns no rows because the employee record (the child) was deleted (silently) when we deleted the department (the parent) record. Without the ON DELETE CASCADE clause we would get the error ORA-02292: integrity constraint (HR.FK_EMP_DEPT) violated - child record found.
If we attempt to truncate the table we also get an error message -ORA-02266: unique/primary keys in table referenced by enabled foreign keys. However in Oracle 12c we can add the clauseCASCADE to the TRUNCATE statement like so:
TRUNCATE TABLE departments CASACDE
to do a fast, unlogged and, therefore, irreversible, delete on departments and employees as long as the foreign key constraint has been declared with the ON DELETE CASCADE clause, otherwise we getORA-14705: unique or primary keys referenced by enabled foreign keys in table "HR"."EMPLOYEES2".

2)Session-level sequences:-

In Oracle 12c the CREATE SEQUNCE has a new clause to specify the scope of the sequence - either GLOBAL the default, or SESSION. For example CREATE SEQUNCE sec1 SESSION. Session-level sequnces are designed to be used with global temporary tables and generate values that are unique only within the session. Also, as soon as the session ends, the state of the sequence is lost so a new session would generate values starting from the initial value defined for the sequence again.


3)DDL Logging:-

DDL logging means logging of SQL data definition language (DDL) commands and is not to be confused with redo logging of DML commands (insert/update/delete/ctas). In Oracle 12c there is a new initialization parameter ENABLE_DDL_LOGGINGwhich can be set to TRUE or FALSE by use of the ALTER SYSTEMand ALTER SESSIOM commands for database-wide logging or just sesion loging, respectively. When set this has the effect of logging all DDL commands executed in the database to an XML file located in c:\app\oracle\diag\rdbms\orcl\orcl\log\ddl.