In the previous Oracle Database versions, you have to create triggers when you need to populate a table column especially primary key column with unique IDs. With Oracle Database 12c, the new sequence default and identity column features make this much easier.
Using Sequence Default
For the sequence default feature, you can specify with the "default <sequence>.nextval" along with the column definition shown as follows:
For the sequence default feature, you can specify with the "default <sequence>.nextval" along with the column definition shown as follows:
SQL> create sequence db12c_doc_id_seq incremented by 2; Sequence created. SQl> create table db12c_doc_tbl( doc_id int default db12c_doc_id_seq.nextval primary key, file_name varchar2(30)); Table created. SQL> insert into db12c_doc_tbl(file_name) values('Oraclc_RAC_12c_Overview.pptx'); 1 row created. SQL> insert into db12c_doc_tbl(file_name) values('Oraclc_TEXT_12c_Overview.pptx'); 1 row created. SQL> select * from db12c_doc_tbl; DOC_ID FILE_NAME ---------- ------------------------------ 1 Oraclc_RAC_12c_Overview.pptx 2 Oraclc_TEXT_12c_Overview.pptx
Using Identity Default
For the identity column, you can define it as follows:
For the identity column, you can define it as follows:
SQL> --drop table db12c_doc_tbl; SQL> create table db12c_doc_tbl 2 ( doc_id int generated by default as identity 3 (start with 1 increment by 2), 4 file_name varchar2(30)); Table created. SQL> insert into db12c_doc_tbl(file_name) values('Oraclc_RAC_12c_Overview.pptx'); 1 row created. SQL> insert into db12c_doc_tbl(file_name) values('Oraclc_TEXT_12c_Overview.pptx'); 1 row created. SQL> select * from db12c_doc_tbl; DOC_ID FILE_NAME ---------- ------------------------------ 1 Oraclc_RAC_12c_Overview.pptx 3 Oraclc_TEXT_12c_Overview.pptx