oracle自增

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunhuwh/article/details/79467885
create sequence S_USER;
/

create trigger tib_USER before insert
on USER for each row
declare
    integrity_error  exception;
    errno            integer;
    errmsg           char(200);
    dummy            integer;
    found            boolean;

 begin
    --  Column id uses sequence S_USER
    select S_USER.NEXTVAL INTO :new.objectid from dual;

--  Errors handling
exception
    when integrity_error then
       raise_application_error(errno, errmsg);
end;
/

有几个地方注意,先创建序列create sequence S_USER。
再创建触发器,创建触发器的时候:
select S_USER.NEXTVAL INTO :new.objectid from dual;
new.objectid,objectid就是自增字段

阅读更多
换一批

没有更多推荐了,返回首页