Oracle 12c New Features : Identity Columns


IDENTITY COLUMNS

Oracle 12c Release1 introduces identity columns in the tables, if table column is marked as IDENTITY, it will automatically generate an increment numeric value at the time of record creation.

Before release of Oracle 12c, developers has to create additional sequence and assign it to the column to make unique. The new feature simplifies code writing and benefits the migration of non-oracle database to oracle

/* Create a table for demonstration purpose */

CREATE TABLE invoice_header 
(invoice_id NUMBER GENERATED AS IDENTITY,
invoice_no VARCHAR2(30),
invoice_date DATE,
invoice_amt NUMBER );

Identity column metadata can be queried from the data dictionary views USER_TAB_COLS and USER_TAB_IDENTITY_COLS. Note that oracle implicitly creates a sequence to generate the number values of column. The custom sequence configuration is listed under IDENTITY_OPTIONS in USER_TAB_IDENTITY_COLS view:

/* Query identity column information in USER_TAB_COLS */
SELECT column_name, data_default, user_generated, identity_column
FROM user_tab_cols
WHERE table_name = 'invoice_header'
/

/*Check the sequence configuration from USER_TAB_IDENTITY_COLS view*/ SELECT table_name,column_name, generation_type, REGEXP_SUBSTR(identity_options,'[^,]+', 1, LEVEL) identity_options FROM user_tab_identity_cols WHERE table_name = 'T_ID_COL' CONNECT BY REGEXP_SUBSTR(identity_options,'[^,]+',1,level) IS NOT NULL /

Comments

Popular posts from this blog

How to use lexical parameters in Data template (XML document) R12

Query to get FSG report details with row/column set

Sub Inventory Transfer API.