时间:2021-07-01 10:21:17 帮助过:11人阅读
当然也支持12c之前的版本所采用的方案:sequence+trigger的方案
1 SQL> 2 SQL> create table t_test (id number,name varchar2(100)); 3 Table created 4 SQL> create sequence t_test_sequence 5 2 increment by 1 6 3 minvalue 1 7 4 nomaxvalue 8 5 start with 1 9 6 cache 20 10 7 order; 11 Sequence created 12 SQL> create or replace trigger t_test_id 13 2 before insert on t_test 14 3 for each row 15 4 begin 16 5 select t_test_sequence.nextval into :new.id from dual; 17 6 end; 18 7 / 19 Trigger created 20 SQL> insert into t_test(name) values(‘hello1‘); 21 1 row inserted 22 SQL> insert into t_test(name) values(‘hello2‘); 23 1 row inserted 24 SQL> insert into t_test(name) values(‘hello3‘); 25 1 row inserted 26 27 SQL> select * from t_test; 28 ID NAME 29 ---------- -------------------------------------------------------------------------------- 30 1 hello1 31 2 hello2 32 3 hello3 33 34 SQL> drop table t_test; 35 Table dropped 36 37 SQL>
查阅文档:
http://www.xifenfei.com/2015/03/oracle-12c-%E6%96%B0%E7%89%B9%E6%80%A7identity-columns-%E5%AE%9E%E7%8E%B0oracle%E8%87%AA%E5%A2%9E%E9%95%BF%E5%88%97%E5%8A%9F%E8%83%BD.html
Oracle12c:支持通过创建identity columen来实现创建自增列
标签:hello star 创建 char begin name with constrain mysql