create table TN_TEST(
username varchar2(32),
userpass varchar2(32),
version number
)
要求一:
TN_TEST表中字段version
每次修改TN_TEST表则讲version自动加一
建立触发器语句:
create trigger add_ver before update on TN_TEST for each row begin
:new.version:=:old.version+1;
end;
要求二:
用触发器和序列实现自增
/*首先创建序列*/
create sequence SEQ_TN_TEST increment by 1 start with 1 MAXVALUE 9999999
/*创建触发器实现自增*/
Create Trigger up_ver Before
Update On TN_TEST
For Each Row begin
select SEQ_TN_TEST.nextval into :new.version
from dual;
end up_ver;
/*触发器结束*/