首页 / ORACLE / oracle列自增实现
oracle列自增实现
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了oracle列自增实现,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2712字,纯文字阅读大概需要4分钟。
内容图文
![oracle列自增实现](/upload/InfoBanner/zyjiaocheng/498/6bc450cc83fe4d56897481e860b893c5.jpg)
CREATE SEQUENCE 序列名
[INCREMENT BY n]
[START WITH n]
[{MAXVALUE/MINVALUE n|NOMAXVALUE}]
[{CYCLE|NOCYCLE}]
[{CACHE n|NOCACHE}];
创建测试表
sys@newtestCDB> CREATE TABLE TEST(
2 ID NUMBER (10) NOT NULL,
3 DESCRIPTION VARCHAR2 (50) NOT NULL,
4 CONSTRAINT test_pk PRIMARY KEY (ID)
5 );
Table created.
Elapsed: 00:00:00.14
sys@newtestCDB> CREATE SEQUENCE test_seq;
Sequence created.
Elapsed: 00:00:00.02
Elapsed: 00:00:00.38
sys@newtestCDB> CREATE OR REPLACE TRIGGER test_before_insert
2 BEFORE INSERT ON test
3 FOR EACH ROW
4 BEGIN
5 SELECT test_seq.NEXTVAL INTO :new.id FROM dual;
6 END;
7 /
Trigger created.
Elapsed: 00:00:00.12
sys@newtestCDB> INSERT INTO TEST (DESCRIPTION) VALUES (‘不指定ID‘);
1 row created.
Elapsed: 00:00:00.08
sys@newtestCDB> INSERT INTO TEST (ID, DESCRIPTION) VALUES (TEST_USER.DEPT_SEQ.NEXTVAL, ‘指定ID‘);
INSERT INTO TEST (ID, DESCRIPTION) VALUES (TEST_USER.DEPT_SEQ.NEXTVAL, ‘指定ID‘)
*
ERROR at line 1:
ORA-02289: sequence does not exist
Elapsed: 00:00:00.01
sys@newtestCDB> INSERT INTO TEST (ID, DESCRIPTION) VALUES (TEST_SEQ.NEXTVAL, ‘指定ID‘);
1 row created.
Elapsed: 00:00:00.01
sys@newtestCDB> SELECT * FROM TEST;
ID DESCRIPTION
1 不指定ID
3 指定ID
Elapsed: 00:00:00.03
2.DEFAULT Values Using Sequences
sys@newtestCDB> INSERT INTO TEST (description) VALUES (‘DESCRIPTION only‘);
1 row created.
Elapsed: 00:00:00.01
sys@newtestCDB> INSERT INTO TEST (id, description) VALUES (999, ‘ID=999 and DESCRIPTION‘);
1 row created.
Elapsed: 00:00:00.00
sys@newtestCDB> INSERT INTO TEST (id, description) VALUES (NULL, ‘ID=NULL and DESCRIPTION‘);
1 row created.
Elapsed: 00:00:00.01
sys@newtestCDB> SELECT * FROM test;
ID DESCRIPTION
4 DESCRIPTION only
999 ID=999 and DESCRIPTION
ID=NULL and DESCRIPTION
Elapsed: 00:00:00.02
sys@newtestCDB> CREATE TABLE TEST(
2 ID NUMBER (10) DEFAULT ON NULL test_seq.NEXTVAL,
3 DESCRIPTION VARCHAR2 (50) NOT NULL
4 );
Table created.
Elapsed: 00:00:00.02
sys@newtestCDB> INSERT INTO TEST (description) VALUES (‘DESCRIPTION only‘);
1 row created.
Elapsed: 00:00:00.01
sys@newtestCDB> INSERT INTO TEST (id, description) VALUES (999, ‘ID=999 and DESCRIPTION‘);
1 row created.
Elapsed: 00:00:00.01
sys@newtestCDB> INSERT INTO TEST (id, description) VALUES (NULL, ‘ID=NULL and DESCRIPTION‘);
1 row created.
Elapsed: 00:00:00.01
sys@newtestCDB> SELECT * FROM test;
ID DESCRIPTION
5 DESCRIPTION only
999 ID=999 and DESCRIPTION
6 ID=NULL and DESCRIPTION
Elapsed: 00:00:00.02
3.看上一篇里面
oracle列自增实现
标签:follow erro href esc sys constrain min tab rem
本文系统来源:http://blog.51cto.com/shurk/2061598
内容总结
以上是互联网集市为您收集整理的oracle列自增实现全部内容,希望文章能够帮你解决oracle列自增实现所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。