我的触发器如下,
create or replace trigger ABCD
before update on A
for each row
declare
CON number;
begin
if updating('parent_menu') = true then
if :old.parent_menu <> :new.parent_menu then
select count(*) into CON from A
where menu = :new.parent_menu;
if CON=0 then
raise_application_error(-20001,'父节点不存在!');
end if;
end if;
end if;
end TRG_SYSMGR_MENU_TREE_UPD;表中数据如下
parent_menu menu
1 2
1 3
2 4
3 5当我把以上最后一条的数据 parent_menu=3、menu=5这条记录的parent_menu改为2的时候,
在第9行(红色行处)报错:触发器/函数不能读取请教高手!
create or replace trigger ABCD
before update on A
for each row
declare
CON number;
begin
if updating('parent_menu') = true then
if :old.parent_menu <> :new.parent_menu then
select count(*) into CON from A
where menu = :new.parent_menu;
if CON=0 then
raise_application_error(-20001,'父节点不存在!');
end if;
end if;
end if;
end TRG_SYSMGR_MENU_TREE_UPD;表中数据如下
parent_menu menu
1 2
1 3
2 4
3 5当我把以上最后一条的数据 parent_menu=3、menu=5这条记录的parent_menu改为2的时候,
在第9行(红色行处)报错:触发器/函数不能读取请教高手!
触发器内不能执行select ... from A
不知道是不是表锁住了,反正状况类似
where menu = :new.parent_menu; 不能在触发器中查询被触发的表
楼主想想其他方式解决(比如调用存储过程执行更新操作,在存储过程中判断是否存在父节点),用触发器肯定不行
鉴于楼主要求明确的报错信息,可以如下变通:
方法一、应用首先使用select查询,判断父节点是否存在;不存在,输入报错;存在执行后面的update语句;
方法二、将方法一的功能集成为存储过程,方便应用直接调用。