最近在写触发器的时候预到了这个问题,经多方查找,得出
1.于after 类型的 for each row 级别的triggers,不论哪种insert语句触发了trigger,都不允许在 trigger 中访问本trigger所依赖的table的
2.对于before 类型的 for each row 级别的triggers,如果使用 insert into ... values 语句触发此trigger ,则在trigger 中访问本table没有问题;
但如果使用 insert into select .. from 语句触发此trigger ,则在trigger 中访问本table就报ora-04091错误;
解决方法,用oracle的自治事务
create or replace trigger twininfo_trriger
after insert on twininfo for each row
declare
PRAGMA AUTONOMOUS_TRANSACTION;--开启自治事务
begin
IF INSERTING THEN
if :new.lotno='T01012' then
update twininfo set info='100_234100_100,1_1_1300;2_1_600;3_1_6500;4_1_13000;5_1_1900;6_1_19500;7_1_117000;8_1_7800;9_1_54000;10_1_9000;11_1_2600;12_1_900'
where lotno= :new.lotno and batchcode= :new.batchcode;
dbms_output.put_line(:new.lotno||'====='||:new.batchcode);
commit;
dbms_output.put_line('提交'||'=====');
end if;
if :new.lotno='T01001' then
update twininfo set info='8442562400_2232960500_13276345700,1_0_0;2_37_12540700;3_61_1856200;4_133_300000;5_3439_60000;6_12371_10000;7_153408_1000;8_1830877_500;11_0_0;12_8_7524400;13_16_1113700;14_33_150000;15_1021_30000;16_3624_5000;17_46687_500;18_10312_6000'
where lotno= :new.lotno and batchcode= :new.batchcode;
commit;
end if;
END IF;
end;
其实最简单应该是:
create or replace trigger twininfo_trriger
before insert on twininfo for each row
begin
IF INSERTING THEN
if :new.lotno='T01012' then
:new.info :='100_234100_100,1_1_1300;2_1_600;3_1_6500;4_1_13000;5_1_1900;6_1_19500;7_1_117000;8_1_7800;9_1_54000;10_1_9000;11_1_2600;12_1_900';
end if;
if :new.lotno='T01001' then
:new.info :='8442562400_2232960500_13276345700,1_0_0;2_37_12540700;3_61_1856200;4_133_300000;5_3439_60000;6_12371_10000;7_153408_1000;8_1830877_500;11_0_0;12_8_7524400;13_16_1113700;14_33_150000;15_1021_30000;16_3624_5000;17_46687_500;18_10312_6000';
end if;
END IF;
end;
别人的例子:
create or replace trigger TR_U_ID_SYNCH
before update on COMPANY referencing old as old_value
new as new_value
for each row
declare
tId company.id%type;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
if :new_value.U_ID is not null and :new_value.U_ID!=ld_value.U_ID then
select t.t_id into tId from company t where t.id= :new_value.U_ID;
:new_value.P_ID :=:new_value.U_ID;
:new_value.T_ID :=tId;
end if;
COMMIT;
end TR_CO_GB_ID_SYNCH;
分享到:
相关推荐
Oracle 11gr2连Oracle 19c 报ORA-28040 ORA-01017解决方法
ora-00604 错误 解决 方法 ora-00604 错误 解决 方法 ora-00604 错误 解决 方法 ora-00604 错误 解决 方法 ora-00604 错误 解决 方法ora-00604 错误 解决 方法
使用工具IMPDP导入数据时ORA-39002、ORA-39070错误排查。使用工具IMPDP导入数据时ORA-39002、ORA-39070错误排查 使用工具IMPDP导入数据时ORA-39002、ORA-39070错误排查
创建物化视图ORA-12014错误解决方法 创建物化视图ORA-12014错误解决方法
Drop goldengate用户时,报ORA-00604 ORA-20782 ORA-06512错误
oracle启动失败,ORA-00702报错,windows,linux系统下解决办法
oracle数据库ora-01152和ora-01110的解决办法
Oracle RAC环境修改字符集遇到ORA-00205解决方法.rar
oracle网络配置(listener_ora-sqlnet_ora-tnsnames_ora).mht
oracle 11g中ora-28056错误的解决方法
ORA-12541 TNSno listener 的解决方案 ORA-12541 TNSno listener 的解决方案
离线误删空间文件导致的ORA-01033及ORA-01145问题的解决办法,在解决ORA-01033的过程中,又出现ORA-01145 * 第 1 行出现错误: ORA-01145: 除非启用了介质恢复, 否则不允许立即脱机 接着的解决步骤
win 8 升级 win 10 后,oracle 11g 无法启动及客户端连接,命令行sqlplus登录,startup 时报 ORA-00119 和 ORA-00132 的错误。 1. sqlplus /nolog 2. conn / as sysdba 3. startup 报错: ORA-00119 和 ORA-00132
ora-01033:oracle initialization or shutdown in progress 解决方法 ora-01033:oracle initialization or shutdown in progress 解决方法 ora-01033:oracle initialization or shutdown in progress 解决方法 ora-...
用oracle数据库新建连接时遇到ora-12505,此问题解决后又出现ora-12519错误,郁闷的半天,经过一番折腾问题解决,下面小编把我的两种解决方案分享给大家,仅供参考。 解决方案一: 今天工作时在新建连接的时候遇到...
ora-01720 授权选项对于'xxxx'不存在的解决方法,希望有帮助。
ORACLE ORA-00132 ORA-00214
ORA-01157解决方案
客户端进行连接的时候,系统不定期出现ora-12520,ora-12516的连接问题, 问题解决方案建议: 1、增加process和session的连接数。 2、检查连接的应用,是不是有没有释放的连接。 3、将修改参数local_listener中的vip为...
在运行查询SELECT * FROM V$SESSION 会出现ORA-29275:部分多字节字符的错误,这是什么原因开始我不得其解,网上也没有介绍什么好办法。本文给出答案。