12C supports creating a sequence first, and then specifying the sequence as the default expression for the value of a column.
and "identity column" have the following different points:
• No limit on the number of columns
sequence must be defined before the column definition
• If sequence is removed, the following insert error is caused
• The owner of the table, and the user must have SELECT permission on the sequence
• You can manually insert and update the column (without using sequence-generated values)
Sql>drop sequence test_seq; SQL> Create sequence test_seq start with1; SQL>drop table Sequence_test_tab; SQL> CREATE table Sequence_test_tab (ID numberdefaulttest_seq.nextval); SQL> INSERT into Sequence_test_tab values (NULL); SQL> INSERT into Sequence_test_tab values (NULL); SQL> INSERT into Sequence_test_tab values (default); SQL> INSERT into Sequence_test_tab values (default); SQL> INSERT into Sequence_test_tab values (10000); SQL>commit;--The result shows that you can insert null and literal values without using the sequence value. The value of sequence is used when inserting the default value. SQL>Select* fromSequence_test_tab; ID----------1 2 10000SQL>SelectCOUNT (*) fromSequence_test_tab; COUNT (*)----------5SQL>--when inserting data, if the column is not specified, the sequence value is also used to insert the ALTER TABLE Sequence_test_tab Add (col_2 number) by default; INSERT INTO Sequence_test_tab ( col_2) VALUES ( About); SQL>Select* fromSequence_test_tab; ID col_2---------- ----------1 2 10000 3 About6rows selected. SQL>
Oracle 12C-The default value for sequence-based columns