|
从不sequential的sequence
来源:不详 作者 佚名 点击数: 录入时间:07-12-20 15:39:42
遇到过好多问题关于如何在ORACLE 中创建类似SQLSERVER或ACCESS中自增长字段。答案多是先建立一个Sequence,然后在Trigger中将Sequence的NEXTVAL的取值赋予所需要的列。看上去还不错。
但是一切真的那么顺利吗?Sequence 真的可以做到提供一序列连续没有遗漏的序列数值吗?
不妨作个实验:
SQL> create sequence test_seq start with 1;
Sequence created.
SQL> create table test_tab ( x int) ;
Table created.
SQL> insert into test_tab values (test_seq.nextval) ;
1 row created.
SQL> insert into test_tab values (test_seq.nextval) ;
1 row created.
SQL> insert into test_tab values (test_seq.nextval) ;
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test_tab ;
X ---------- 1 2
3
SQL> conn / as sysdba; Connected. SQL> alter system flush shared_pool ;
System altered.
SQL> conn user1/user1 Connected. SQL> insert into test_tab values (test_seq.nextval) ;
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test_tab ;
X ---------- 1 2
3 21
&nb[1] [2] [3] [4] [5] [6] 下一页
|