1.创建序列sequence
create sequence seq_uid increment by 1 start with 1 nomaxvalue nocycle cache 10 ;
其中:"seq_uid"表示自定义的序列名称;
"start with 1"表示序列值从1开始;
"increment by 1"表示序列每次增加的值为1。
序列的使用方法:
select seq_uid.nextval id from dual
这样就得到了序列的下一个值,将这个语句放在触发器中,就可以实现类似sql server中id自增的功能。
create trigger tri_uid before insert on [tablename] for each row when (new.[columnname] is null) begin select seq_uid.nextval into:new.[columnname] from dual; end;
其中:"tri_uid"表示自定义的触发器名称;
"seq_uid"表示要使用的序列名称;
"[columnname]"表示要实现自增的列;
"[tablename]"表示要实现自增的列所在的数据表。
如对本文有疑问, 点击进行留言回复!!
Oracle 基本概念 Dadabase,schema,user,table...
dbeaver连接Oracle中文乱码的解决方案--druid
Oracle常用语句(时间格式、去重、去特殊符号、查询表空间等)
网友评论