Top Oracle 12c New Features for developers

Last updated on May 16th, 2019 at 04:37 am

Oracle has released 12c with lot of new features. Here in this article,I would presenting the top Oracle 12c New Features for developers

I have categorized the features in the broad category to make it easier to understand and use


1) Top-N feature
A Top-N query allows us to retrieve the top or bottom N rows from an ordered set. Combining two Top-N queries gives you the ability to page through an ordered set

SELECT value
FROM mytable

select * from my_test order by name fetch first 3 rows only;

Pre Oracle 12c we need to write queries like this to achieve it

select … from (select … from … order by …) where rownum <= 20
The optimizer uses analytic function under the cover to make it work

Pagination can also happen with this feature with the use offset syntax

– offset 10 rows fetch first 10 rows only

select * from my_test order by id
offset 10 rows fetch next 10 rows only;
– offset 10 rows fetch first 0.1 percent rows only

select * from my_test order by id

offset 10 rows first 0.1 percent rows only

– offset 10 rows fetch first 0.1 percent rows with ties
1)If you have a SELECT statement with FOR UPDATE, you can’t use it.
2)The SELECT statement can’t CURRVAL or NEXTVAL of sequences
3) If the query of the Materialized Views has this clause, then you can’t do an incremental refresh of that MV


2) Extended Outer Join

Oracle 12c extends the power of outer join to make it more useful
Now you can use outer join for multiple table and column

select *
from x,y,z
where x.uid = y.uid
and x.uid = z.uid(+)
and y.uid = z.uid(+);

The above query will give error pre 12c but execute successfully in 12c

3) Lateral Inline Views,Cross apply and Outer apply Extension
Oracle 12c introduced the LATERAL inline view syntax, as well as CROSS APPLY and OUTER APPLY joins into the SELECT syntax.

Lateral Inline View

Normally, it is not possible to reference tables outside of an inline view definition.

SELECT dept_no, emp_no
FROM dept d,
(SELECT emp_no
FROM emp e
WHERE e.dept_no = d.dept_no);WHERE e.dept_no = d.dept_no)
ERROR at line 5:
ORA-00904: "D"."DEPT_NO": invalid identifier

A LATERAL inline view allows you to reference the table on the left of the inline view definition in the FROM clause, allowing the inline view to be correlated.

SELECT dept_no, emp_no
FROM dept d,
Lateral (SELECT emp_no
FROM emp e
WHERE e.dept_no = d.dept_no);

Cross apply

It works like normal join between two tables.The CROSS APPLY join is a variant of the ANSI CROSS JOIN. It returns all rows from the left hand table, where at least one row is returned by the table reference or collection expression on the right. The right side of the APPLY can reference columns in the FROM clause to the left

select * from test1 a cross apply
(select *
from test2 b
where b.uid=a.uid);

Outer apply

It works like left outer join between tables. The usage is similar to the CROSS APPLY join, but it returns all rows from the table on the left side of the join. If the right side of the join returns no rows, the corresponding columns in the output contain Nulls.

select * from test1 a outer apply
(select *
from test2 b
where b.uid=a.uid);

If you look at the explain plan for each of these, then these are normal oracle joins only

4) With Clause improvement
In Oracle 12c, we can declare PL/SQL functions in the WITH Clause of a select statement and use it as an ordinary function. Using this construct results in better performance as compared with schema-level functions

SELECT add_func_test(5)
FROM dual

5) Cascade for TRUNCATE and EXCHANGE partition.
With Oracle Database 12c, The TRUNCATE can be executed with CASCADE option which will also delete the child records.

When you truncate a parent table with child tables,
you get:

ORA-02266: unique/primary keys in table referenced by enabled foreign keys

In Oracle 12c, you can use:

truncate table <Parent> cascade;

Must have defined the Foreign key as ON DELETE CASCADE.
Otherwise ORA-14705: unique or primary keys referenced by enabled foreign keys in table will result
6)EXPAND_SQL_TEXT procedure

New procedure EXPAND_SQL_TEXT of package DBMS_UTILITY helps to recursively replace any view references in the input SQL query with the corresponding view subquery.

What if you need to analyze following query

select * from test3;

With new procedure it’s piece of cake

set serveroutput on
v_in_view clob := 'select * from TEST3';
v_out_view clob;
dbms_utility.expand_sql_text(v_in_view, v_out_view);
/anonymous block completed
<view query will come here>

7) sql support in RMAN

In Oracle 12c release 1 most of SQL and PL/SQL commands are supported in RMAN. We dont require any SQL prefix or quotes .DESCRIBE is also supported

Pre 12c

RMAN> sql 'SELECT username,machine FROM v$session';

With 12c

RMAN> SELECT username,machine FROM v$session;

Schema Level New features in 12c

1. Sequence as Default Value
With Oracle Database 12c, we can directly assign sequence nextval as a default value for a column, So you no longer need to create a trigger to populate the column with the next value of sequence, you just need to declare it with table definition.It is a sort of auto increment feature for a column in oracle just like MySQL

create sequence tech_test_seq start with 1 increment by 1 nocycle;
create table test
id number default tech_test_seq.nextval primary key
name varchar(30)

2). Invisible column:
With 12c ,you can make Invisible column . A Column defined as invisible, will not appear in generic queries (select * from). An Invisible Column need to be explicitly referred to in the SQL statement or condition. Also invisible column must be explicitly referred in INSERT statement to insert the database into invisible columns.

create table my_test
id number,
name varchar2(100),
dept varchar2(100),
password varchar2(100) INVISIBLE
age varchar2(100)
Firstname varchar2(100)
lastname varchar2(100)

Important points

The table will be created with password column invisible

Select * from my_test ;

It will show all the column except password

Describe will not show invisible column

To make column visible in sql, we can set “set col invisible on”

To make column visible from invisible

ALTER TABLE my_test MODIFY (password visible);

we can create index on invisible column

3) Multiple indexes on the same column
Before Oracle Database 12c, we could not have multiple indexes on a single column. In Oracle Database 12c a column may have multiple indexes but all should be of different types i.e if B tree is already defined then you can create bitmap index on the same column. Like a column may have B-Tree and Bitmap Index both. But, only one index will be used at a given time.

SQL> create table test (id number, name varchar2(100));
Table created.
SQL> create index test_idx1 on test(id);
Index created.
SQL> create index test_idx2 on test(id);
create index test_idx2_02 on test(id)
ERROR at line 1:
ORA-01408: such column list already indexed
SQL> create bitmap index test_idx2_02 on test(id) invisible;Index created.

Here we could create the index as it has different type and it is also invisible

4) VARCHAR2 length up to 32767
Until Oracle 11g SQL, the maximum precision allowed for a string type column was 4000. In Oracle 12c, the precision has been increased up-to 32767 bytes or 32 K. The new string data types will be known as Extended String Types in Oracle 12c. The feature is controlled by an initialization parameter MAX_STRING_SIZE. Increasing the allotted size for these data types allows users to store more information in character data types before switching to large objects (LOBs).

Procedure to enable the feature

shutdown immediate
startup upgrade
alter system set max_string_size=EXTENDED scope=both;
Shutdown immediate

5) IDENTITY Columns
In Oracle Database 12c, We can define Table columns with SQL keyword IDENTITY which is a American National Standards Institute (ANSI) SQL keyword. Which are auto-incremented at the time of insertion (like in MySQL).

create table test
id number generated as identity,
name varchar2(100),
email varchar2(100),
password varchar2(100)firstname varchar2(100)lastname varchar2(100)

Related article

Auto Increment Column – Sequence as Default Value in Oracle and mysql
6) Session sequences

With Oracle Database 12c new keywords SESSION, GLOBAL are available that can be specified during a sequence creation

Global Session
creates standard sequence well known in previous release. This is the default. creates new type session sequence, which is a special type of sequence that is specifically designed to be used with global temporary tables that have session visibility. Session sequence returns a unique range of sequence numbers only within a session, but not across sessions. Another difference is that session sequences are not persistent. If a session goes away, so does the state of the session sequences that were accessed during the session.

7) Temporary Undo
Before Oracle Database 12c, undo records of temporary tables used to be stored in undo tablespace. With the temporary undo feature in Oracle Database 12c, the undo records of temporary tables can now be stored in a temporary table instead of stored in undo tablespace. The main benefits of temporary undo are

1) Low undo tablespace usages

2) less redo data generation. For using this feature Compatibility parameter must be set to 12.0.0 or higher and TEMP_UNDO_ENABLED initialization parameter must be Enabled.

Administration New Features

1) Online RENAME/MOVE of Datafiles

A data file migration or renaming in Oracle database 12c R1 no longer requires a number of steps i.e. putting the tablespace in READ ONLY mode, followed by data file offline action. In 12c R1, a data file can be renamed or moved online simply using the ALTER DATABASE MOVE DATAFILE SQL statement. While the data file is being transferred, the end user can perform queries, DML and DDL tasks. Additionally, data files can be migrated between storage e.g. from non-ASM to Oracle ASM and vice versa.

Oracle Database 12c has provided a simple way to online renamed or moved data files by simply “ALTER DATABASE MOVE DATAFILE” command. Data files can also be migrated online from ASM to NON-ASM and NON-ASM to ASM easily now.

Rename datafile:
SQL> ALTER DATABASE MOVE DATAFILE '/u01/app/oracle/TEST/oradata/applsysd.dbf' TO '/u02/app/oracle/TEST/oradata/indx_01.dbf';
Move Datafile:
SQL> ALTER DATABASE MOVE DATAFILE '/u01/app/oracle/TEST/oradata/indx.dbf' TO '/u02/app/oracle/TEST/oradata/indx.dbf';
SQL> ALTER DATABASE MOVE DATAFILE '/u01/app/oracle/TEST/oradata/indx.dbf' TO '+DATA01';

2) Move table partition to different Tablespace online

Migration of a table partition or sub-partition to a different tablespace no longer requires a complex procedure in Oracle 12c R1. In a similar way to how a heap (non-partition) table online migration was achieved in the previous releases, a table partition or sub-partition can be moved to a different tablespace online or offline. When an ONLINE clause is specified, all DML operations can be performed without any interruption on the partition|sub-partition which is involved in the procedure. In contrast, no DML operations are allowed if the partition|sub-partition is moved offline.From Oracle 12c, it become very easy to move Table Partition to different tablespace and does not require complex steps


3) DDL logging
By using the ENABLE_DDL_LOGGING initiation parameter in Oracle Database 12c, we can now log the DDL action into xml and log files to capture when the drop or create command was executed and by whom under the $ORACLE_BASE/diag/rdbms/DBNAME/log|ddl location. The parameter can be set at the database or session levels.


Oracle Database 12c has provided us a way to limit PGA by PGA_AGGREGATE_LIMIT parameter. Before Oracle Database 12c there was no option to limit and control the PGA size. Oracle will automatically abort the session that holds the most untenable PGA memory when PGA limits exceeds the defined value.

5) Turning off redo for Data Pump the import
The new TRANSFORM option, DISABLE_ARCHIVE_LOGGING, to the impdp command line causes Oracle Data Pump to disable redo logging when loading data into tables and when creating indexes. This feature provides a great relief when importing large tables, and reduces the excessive redo generation, which results in quicker imports. This attribute applies to tables and indexes.

impdp directory=mydir dumpfile=mydmp.dmp logfile=mydmp.log tables=test TRANSFORM=DISABLE_ARCHIVE_LOGGING:Y table_exists_action=append
. . imported "TECH"."TEST"

6) More online operations







Some More interesting Oracle 12c New Features for developers

  1. Temporal Validity
    Temporal Validity is very interesting feature in Oracle 12c that provides ability to scan effectively Gantt data
    1)adds (one or more) “time dimension” to a table by using current columns or using columns automatically created by database
    2) enable using simple SQL syntax to filter the columns to access only active data using Oracle flashback technology
  2. EBR Improvements
    EBR was introduced in 11gR2. 12c gave more power to EBR. It removes some of the limitation. Now materialized view and types can be editioned
  3. Data redaction

This is one of the top features in Oracle 12c. Data Redaction in simple terms means, masking of data. You can setup a Data Redaction policy, for example salary field in a Employee table can be masked. This is called redaction.

When you do a select * from employee, it will show that the Salary is masked.
The new data masking will use a package called DBMS_REDACT. It is the extension to the FGAC and VPD present in earlier versions.

I hope you like the compilation of Oracle 12c New Features for developers . Please do provide feedback

Oracle 12c Resource

Oracle Database 12c – Multitenant Architecture

Oracle database 12c:How to create Pluggable database in 12c database

Oracle database 12c: Container Database (CDB) and Pluggable Database (PDB)

Oracle Database 12c:How to Create the container database

Oracle 12c documentation

Oracle Sql Resource

how to create table in oracle

Oracle views

Joins Method in Oracles

Oracle sql and plsql


Leave a Reply