You are on page 1of 7

http://www.oracle.

com/us/corporate/press/1967380
http://www.oracle.com/us/corporate/features/database-12c/index.html

http://www.oracle.com/us/products/database/overview/index.html

http://www.infoworld.com/d/data-management/oracle-database-12c-review-finally-true-cloud-
database-221549

Enhancements in Oracle Database 12c Release 1 (12.1)
Extended Data Types
Prior to Oracle 12c, regardless of the character semantics used, the maximum size of
a VARCHAR2, NVARCHAR2 and RAW columns in a database are as follows.
VARCHAR2 : 4000 bytes
NVARCHAR2 : 4000 bytes
RAW : 2000 bytes
Oracle 12c optionally increases these maximum sizes.
VARCHAR2 : 32767 bytes
NVARCHAR2 : 32767 bytes
RAW : 32767 bytes
o The extended data types functionality is controlled using
the MAX_STRING_SIZE initialization parameter
o The process of switching to the extended data types is a one-way operation
Identity Columns
there was no direct equivalent of the AutoNumber or Identity functionality of other
database engines. this behaviour had to be implemented using a combination of sequences
and triggers.
Oracle 12c introduces two alternatives
identity columns
sequence pseudocolumns as default values
The syntax is show below.
GENERATED
[ ALWAYS | BY DEFAULT [ ON NULL ] ]
AS IDENTITY [ ( identity_options ) ]

CREATE TABLE identity_test_tab (
id NUMBER GENERATED ALWAYS AS IDENTITY,
description VARCHAR2(30)
);

Using BY DEFAULT allows you to use the identity if the column isn't referenced in the insert
statement
Using BY DEFAULT ON NULL allows the identity to be used if the identity column is referenced,
but a value of NULL is specified.
Not surprisingly, trigger-based test performs much worse than the others. The direct use of a
sequence and the 12c identity column give comparable results, which are typically an order of
magnitude faster than using a trigger to populate the ID column.
Implicit Statement Results
Background
T-SQL Developer: How do I pass results out of a stored procedure?
Oracle Developer: You use an out parameter.
T-SQL Developer: But I want to return a resultset.
Oracle Developer: No problem, make the out parameter a ref cursor and you're laughing.
T-SQL Developer: So I have to define out parameters for each of the resultsets I want to
pass out?
Oracle Developer: Yes.
T-SQL Developer: Oh man! Oracle Sucks!
because Transact-SQL allows implicit returns of results from queries
CREATE PROCEDURE Get_My_Results
( @p_id int )
AS
SELECT description, created_date FROM t1 WHERE id = @p_id
RETURN 0
GO
In oracle
CREATE OR REPLACE PROCEDURE get_my_results (p_id IN NUMBER DEFAULT NULL)
AS
l_cursor_1 SYS_REFCURSOR;
BEGIN
OPEN l_cursor_1 FOR
SELECT description, created_date
FROM t1
WHERE id = p_id;

DBMS_SQL.RETURN_RESULT(l_cursor_1);
END;
/
SQL> EXEC get_my_results(1);

PL/SQL procedure successfully completed.

ResultSet #1

DESCRIPTION CREATED_DATE
------------------------------ --------------------
The value 1 06-JUL-2013 21:19:45

1 row selected.

ResultSet #2

COUNT(*)
----------
3

1 row selected.

SQL> EXEC get_my_results;

PL/SQL procedure successfully completed.

ResultSet #1

COUNT(*)
----------
3

1 row selected.
DEFAULT Values for Table Columns
o DEFAULT Values Using Sequences
In Oracle 12c, it is now possible to specify the CURRVAL and NEXTVAL sequence
pseudocolumns as the default values for a column.
CREATE SEQUENCE t1_seq;

CREATE TABLE t1 (
id NUMBER DEFAULT t1_seq.NEXTVAL,
description VARCHAR2(30)
);

INSERT INTO t1 (description) VALUES ('DESCRIPTION only');
INSERT INTO t1 (id, description) VALUES (999, 'ID=999 and DESCRIPTION');
INSERT INTO t1 (id, description) VALUES (NULL, 'ID=NULL and DESCRIPTION');

SELECT * FROM t1;

ID DESCRIPTION
---------- ------------------------------
1 DESCRIPTION only
999 ID=999 and DESCRIPTION
ID=NULL and DESCRIPTION

The fact we can use both the NEXTVAL and CURRVAL pseudocolumns gives us the
ability to auto-populate master-detail relationships.
o DEFAULT Values On Explicit NULLs
If the column is referenced, even when supplying the value NULL, the default value is not
used. Oracle 12c allows you to modify this behaviour using the ON NULL clause in the default
definition.
CREATE SEQUENCE default_seq;
CREATE SEQUENCE default_on_null_seq;

CREATE TABLE t2 (
col1 NUMBER DEFAULT default_seq.NEXTVAL,
col2 NUMBER DEFAULT ON NULL default_on_null_seq.NEXTVAL,
description VARCHAR2(30)
);

INSERT INTO t2 (description) VALUES ('DESCRIPTION only');
INSERT INTO t2 (col1, col2, description) VALUES (999, 999,
'999,999,DESCRIPTION');
INSERT INTO t2 (col1, col2, description) VALUES (NULL, NULL,
'NULL,NULL,DESCRIPTION');

SELECT * FROM t2;

COL1 COL2 DESCRIPTION
---------- ---------- ------------------------------
1 1 DESCRIPTION only
999 999 999,999,DESCRIPTION
2 NULL,NULL,DESCRIPTION

o Metadata-Only DEFAULT Values
Prior to Oracle 11g, adding a new column to an existing table required all rows in
that table to be modified to add the new column.
Oracle 11g introduced the concept of metadata-only default values. Adding
a NOT NULL column with a DEFAULT clause to an existing table involved just a metadata
change, rather than a change to all the rows in the table. Queries of the new column were
rewritten by the optimizer to make sure the result was consistent with the default
definition.
Oracle 12c takes this a step further, allowing metadata-only default values of
both mandatory and optional columns. As a result, adding a new column with
a DEFAULT clause to an existing table will be handled as a metadata-only change,
regardless of whether that column is defined as NOT NULL or not. This represents both a
space saving and performance improvement.
Truncate table CASCADE
In the previous releases, there wasnt a direct option provided to truncate a master table while it is
referred to by the child tables and child records exist. The TRUNCATE
TABLE with CASCADE option in 12c truncates the records in the master table and automatically
initiates recursive truncate on child tables too, subject to foreign key reference as DELETE ON
CASCADE. There is no CAP on the number of recursive levels as it will apply on all child, grand
child and great grandchild etc.
This enhancement gets rid of the prerequisite to truncate all child records before truncating a
master table. The newCASCADE clause can also be applied on table partitions and sub-
partitions etc.
SQL> TRUNCATE TABLE <table_name> CASCADE;

SQL> TRUNCATE TABLE <table_name> PARTITION <partition_name> CASCADE;
An ORA-14705 error will be thrown if no ON DELETE CASCADE option is defined with the
foreign keys of the child tables.

ROW limiting for Top-N result queries
There are various indirect approaches/methods exist to fetch Top-N query results for top/bottom rows in
the previous releases. In 12c, retrieving Top-N query results for top/bottom rows simplified and become
straight forward with the new FETCH FIRST|NEXT|PERCENT clauses.
In order to retrieve top 10 salaries from EMP table, use the following new SQL statement:
SQL> SELECT eno,ename,sal FROM emp ORDER BY SAL DESC
FETCH FIRST 10 ROWS ONLY;
The following example fetches all similar records of Nth row. For example, if the 10th row has salary of
5000 value, and there are other employees whose salary matches with the Nth value, the will also be
fetched upon mentioningWITH TIES clause.
SQL> SELECT eno,ename,sal FROM emp ORDER BY SAL DESC
FETCH FIRST 10 ROWS ONLY WITH TIES;
The following example limits the fetch to 10 per cent from the top salaries in the EMP table:
SQL> SELECT eno,ename,sal FROM emp ORDER BY SAL DESC
FETCH FIRST 10 PERCENT ROWS ONLY;
The following example offsets the first 5 rows and will display the next 5 rows from the table:
SQL> SELECT eno,ename,sal FROM emp ORDER BY SAL DESC
OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY;
All these limits can be very well used within the PL/SQL block too.
BEGIN
SELECT sal BULK COLLECT INTO sal_v FROM EMP
FETCH FIRST 100 ROWS ONLY;
END;
Session level sequences
A new SESSION level database sequence can be created now in 12c to support the session level
sequence values. These types of sequences are most useful and suitable on global temporary tables that
have session level existence.
Session level sequences produce a unique range of values that are limited within the session, not across
the sessions. Once the session ends, the state of the session sequences also goes away. The following
example explains creating a session level sequence:
SQL> CREATE SEQUENCE my_seq START WITH 1 INCREMENT BY 1 SESSION;

SQL> ALTER SEQUENCE my_seq GLOBAL|SESSION;
The CACHE, NOCACHE, ORDER or NOORDER clauses are ignored for SESSION level sequences.

You might also like