New features of Oracle 12C-sequence

Source: Internet
Author: User

If you use global temporary tables and sequence, you may encounter some problems. Because global temporary tables are associated with sessions (or transactions in a session), sequence is related to the database level.

In 12C, you can create a sequence that is used only for a given session.

--When the global temporary table GTT is emptied in a session (such as commit), the value of sequence is not reset. The next call to the sequence will use its nextval value.

Sql> Connect scott/Tigersql>drop table GTT; SQL> CreateGlobaltemporary table GTT (ID number,seq_number number); SQL>Grant all on GTT to Tiger; SQL>drop sequence seq_session; SQL> Create sequence seq_session start with1session; SQL>Grant all on seq_session to Tiger; SQL> INSERT into GTT values (1, Seq_session.nextval); SQL> INSERT into GTT values (2, Seq_session.nextval); SQL>Select* fromSCOTT.GTT; ID Seq_number---------- ----------1          1         2          2SQL>commit; SQL>Select* fromscott.gtt;no rows Selectedsql>INSERT into GTT values (1, seq_session.nextval); insert into GTT values (2, Seq_session.nextval); SQL>Select* fromSCOTT.GTT; ID Seq_number---------- ----------1          3         2          4SQL>

Continue the test.
--end of session, sequence value will be reset

Sql>conn tiger/Tigersql>drop synonym GTT; SQL>drop synonym seq_session; SQL>create synonym GTT forSCOTT.GTT; SQL>create synonym Seq_session forscott.seq_session; SQL>Select* fromgtt;no rows Selectedsql>sql> INSERT INTO GTT values (1, Seq_session.nextval); sql> INSERT into GTT values (2, Seq_session.nextval);
-In 11g, the query result here is 5,6sql>Select* fromGTT; ID Seq_number---------- ----------1 1 2 2SQL>sql> commit; SQL>Select* fromgtt;no rows Selectedsql>Sql> Conn Scott/tigersql> INSERT INTO GTT values (1, Seq_session.nextval); sql> INSERT into GTT values (2, Seq_session.nextval);
-In 11g, the query result here is 7,8sql>Select* fromGTT; ID Seq_number---------- ----------1 1 2 2SQL>

New features of Oracle 12C-sequence

Related Article

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.