Oracle 12C-The default value for sequence-based columns

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.