今天写了一个触发器,报ORA-04088错误.
在网上查阅是说:
for each row的, 执行过程中, 不能 SELECT / UPDATE / DELETE 当前的被触发的表.
感觉很经典的一句话.
网上有其他方案:感觉不太好用.
------解决方案--------------------
不能对基表进行操作。
用自治事务试下,在declare里面加入
PRAGMA AUTONOMOUS_TRANSACTION;
------解决方案--------------------
贴一下我的触发器,这里面就出现了当前被触发的表,所以有问题:
-
create or replace trigger trig_t_felix_resource
-
after insert or delete or update on t_felix_resource for each row--每更新一行就会触发一次
-
-
begin
-
declare
-
-
cursor deptments is
-
select * from PF_ORG_DEPARTMENT t where t.name like '%电业局' or t.code ='SGSBB';
-
-
cursor types is
-
select * from T_NAME_MAPPING m where m.type = '物理资源类' and m.code != '链路';
-
-
v_deptName VARCHAR2(20);--地市的名称
-
v_typeName VARCHAR2(20);
-
v_devNum number;
-
-
begin
-
--获取地市的名称
-
for v_dept in deptments loop--for循环时v_dept不需要申明
-
v_deptName := substr(v_dept.name,0,2);
-
if (v_deptName = 'xx') then
-
v_deptName := 'yyy';
-
end if;
-
--获取资源的六大类型
-
for v_type in types loop
-
v_typeName := v_type.code;
-
-
select count(t.id) into v_devNum
-
from t_resourceinfo t, t_felix_resource t1
-
where t.org_code in (select t.code
-
from pf_org_department t
-
start with t.id = v_dept.id
-
connect by prior id = parent_id)
-
and t.bus_res_type_id in
-
(select ty.id
-
from t_resource_type ty
-
start with ty.id = v_type.name
-
connect by prior id = pid)
-
and t.id = t1.resource_id;
-
--删除对应的一条记录
-
delete from t_trig_dev_station ttds
-
where ttds.location=v_deptName and ttds.devtype=v_typeName;
-
--插入对应的一条新记录
-
insert into t_trig_dev_station (id, location, devtype, devnum)
-
values (sys_guid(), v_deptName, v_typeName, v_devNum);
-
end loop;
-
end loop;
-
end;
-
end;
阅读(4887) | 评论(0) | 转发(0) |