17,090
社区成员
发帖
与我相关
我的任务
分享
--1.先创建序列
scott@YPCOST> create sequence orderNo_seq start with 100 increment by 1 maxvalue 999;
序列已创建。
scott@YPCOST> create table test(id number,name varchar2(20));
表已创建。
--2、再加触发器
scott@YPCOST> ed
已写入 file afiedt.buf
create or replace trigger insert_tri
before insert on test
for each row
declare
begin
select orderNo_seq.nextval into :new.id from dual;
end;
scott@YPCOST> /
触发器已创建
scott@YPCOST> insert into test(name) values('tom');
已创建 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from test;
ID NAME
-------------------- --------------------
100 tom