Adsense Ad

Tuesday, 3 September 2019

Oracle 12c New Features " Identity Columns "

A column in a table can be marked as identity column which generates its value by itself. Oracle implicitly creates a sequence of default configuration for the identity column. For each insert operation, the current value of the sequence gets automatically assigned to the identity column. 

The feature syntax is as below.

SQL> create table t_id_col ( x number
generated by default as identity
( start with 10 increment by 15 ) primary key,
y varchar2(30))
/
Table created.

SQL> insert into t (x,y) values ( 1, ‘hello1’ );
1 row created.

SQL> insert into t (x,y) values ( default, ‘hello2’ );
1 row created.

SQL> insert into t (y) values ( ‘hello3’ );
1 row created.

SQL> select * from t;

    X          Y
—————————— ———————————
    1        hello1
    10       hello2
    25       hello3

No comments: