Oracle 实现类似SQL Server中自增字段的一个办法
程序员文章站
2023-12-06 12:45:52
相关代码如下: 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;
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;
上一篇: Oracle 当前用户下所有表的记录总数