SQL> connect scott/tiger
SQL> drop table gtt;
SQL> create global temporary 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 with 1 session;
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 * from scott.gtt;
ID SEQ_NUMBER
---------- ----------
1 1
2 2
SQL>
commit;
SQL> select * from scott.gtt;
no rows selected
SQL>
insert into gtt values(1,seq_session.nextval);
insert into gtt values(2,seq_session.nextval);
SQL> select * from scott.gtt;
ID SEQ_NUMBER
---------- ----------
1 3
2 4
SQL>
继续测试。
--会话结束,sequence的值会被重置
SQL>conn tiger/tiger
SQL>drop synonym gtt;
SQL>drop synonym seq_session;
SQL>create synonym gtt for scott.gtt;
SQL>create synonym seq_session for scott.seq_session;
SQL> select * from gtt;
no rows selected
SQL>
SQL> insert into gtt values(1,seq_session.nextval);
SQL> insert into gtt values(2,seq_session.nextval);
--在11g中,这里查询结果是5,6
SQL> select * from gtt;
ID SEQ_NUMBER
---------- ----------
1 1
2 2
SQL>
SQL> commit;
SQL> select * from gtt;
no rows selected
SQL>
SQL> conn scott/tiger
SQL> insert into gtt values(1,seq_session.nextval);
SQL> insert into gtt values(2,seq_session.nextval);
--在11g中,这里查询结果是7,8
SQL> select * from gtt;
ID SEQ_NUMBER
---------- ----------
1 1
2 2
SQL>