create or replace trigger popo_user_info_update_triggers before update of nickname on emp for each row declare -- local variables here begin if :new.nickname<>:old.nickname then
:new.updatenamedate:=sysdate; end if; EXCEPTION WHEN OTHERS THEN RAISE_APPLICATION_ERROR(-20000, 'Error in "PLATE_BI_IDGEN": ' || SQLERRM); end popo_user_info_update_triggers;
unix 时间戳 addtime number; select (sysdate - to_date('1970-1-1','yyyy-mm-dd'))*86400- TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600 INTO addtime from dual;
create or replace trigger tri before insert on b1 for each row declare tname varchar2(10); begin select a2 into tname from a1 where a1=:new.b1; :new.b2 := tname; end tri; 从别人那拷贝过来的,自己试验了一下。 可以
而触发器中又修改这个表,所以再次引发触发器,无限循环了,兄弟。
before update of nickname on emp
for each row
declare
-- local variables here
begin
if :new.nickname<>:old.nickname then
:new.updatenamedate:=sysdate;
end if;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000, 'Error in "PLATE_BI_IDGEN": ' || SQLERRM);
end popo_user_info_update_triggers;
addtime number;
select (sysdate - to_date('1970-1-1','yyyy-mm-dd'))*86400- TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600 INTO addtime from dual;
before insert on b1
for each row
declare
tname varchar2(10);
begin
select a2 into tname from a1 where a1=:new.b1;
:new.b2 := tname;
end tri;
从别人那拷贝过来的,自己试验了一下。 可以
解决变异表问题。
1. 使用自治事务 pragma autonomous_transaction 结合commit;
2. 使用全局变量
3. 使用复合触发器(Oracle 11g 才有)
自治事务不安全,
全局变量代码太多繁琐
复合触发器简单方法,但有其版本限制。
如果楼主是11g建议用复合触发器。如果不是11g只能采用第一种和第二种方法。
http://topic.csdn.net/u/20110804/17/e9768529-0a76-4f66-a393-5d4722675615.html