欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle 实现类似SQL Server中自增字段的一个办法

程序员文章站 2023-11-17 10:46:34
相关代码如下: 1. 创建sequence: 复制代码 代码如下:create sequence sequ_data_datainfo increment by 1 sta...
相关代码如下:
1. 创建sequence:
复制代码 代码如下:

create sequence sequ_data_datainfo increment by 1 start with 1 nocycle nocache noorder;

2. 创建触发器:
复制代码 代码如下:

create or replace trigger trig_test
before insert on table1
for each row
declare
tmpvar number;
begin
tmpvar := 0;
select sequ_proc_associateinfo.nextval into tmpvar from dual;
:new.procid:=tmpvar;
exception
when others then
-- consider logging the error and then re-raise
raise;
end;