oraacle觸發器語法sql
CREATE [OR REPLACE] TIGGER 觸發器名測試
[before|after] --觸發時間spa
[insert|update|delete] --觸發事件事件
ON 表名rem
[FOR EACH ROW]it
BEGINtable
sql語句test
ENDdate
建立一個關於逐漸id遞增的 觸發器select
--建立一個測試表
create table tab_user(
id number(11) primary key,
username varchar(50),
password varchar(50)
);
select t.*, t.rowid from TAB_USER t;
-- 建立一個序列
create sequence MY_SEQ increment by 1 start with 1 nomaxvalue nocycle cache 20;
-- 建立逐漸遞增觸發器
create or replace trigger MY_TGR
before insert on tab_user for each row
declare
next_id number;
begin
select MY_SEQ.nextval into next_id from dual;
:new.id:=next_id;
end;
--向表插入數據;
insert into tab_user(username,password) values('admin','admin'); insert into tab_user(username,password) values('fgz','fgz'); insert into tab_user(username,password) values('test','test');