12c New Feature: Session level sequences


12c_logo_breit

In 12c a new SESSION level sequence can be created to support sequence values at session level. This feature can be usefull if you are working with global temporary tables that have session level existence.

If you create a session level sequence you can create a unique range of values in your active session not across other sessions. If the session ends also the generated values are reset.

For a small example i will create a table and insert some rows.

SQL> CREATE SEQUENCE sess_seq START WITH 1 INCREMENT BY 1 SESSION;
Sequence created.

SQL> CREATE GLOBAL TEMPORARY TABLE seq_test (id NUMBER(38))
  2      ON COMMIT PRESERVE ROWS ;
Table created.

SQL> insert into seq_test  select sess_seq.nextval from user_tables;
8 rows created.

SQL> commit;
SQL> select sess_seq.nextval from dual;

   NEXTVAL
----------
     9



As you can see, my current value in this session is 9, but if i do the same command from a other session.

SQL> select sess_seq.nextval from dual;

   NEXTVAL
----------
     1

 

Advertisements

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s