我创建了以下表格:
create table products
(
code varchar(9),
group_code varchar(9),
price number,
CONSTRAINT pk_code PRIMARY KEY (code)
);
我创建了一个触发器,因为每组产品的价格不超过100美元:
create or replace trigger nomore100
before insert or update on products
for each row
declare
cursor c_total is
select group_code, sum(price) as total_price
from products
where group_code=:new.group_code
group by group_code;
v_total c_total%rowtype;
begin
for v_total in c_total loop
if v_total.total_price+:new.price > 100 then
raise_application_error(-20150,'No more than 100 dollars');
end if;
end loop;
end nomore100;
/
触发器适用于插入,但是当我尝试进行更新时:
update products set price=120 where code='PX1';
Oracle返回:
"表%s。%s正在变异,触发/功能可能看不到它"
感谢您提出任何建议或答案,祝您有个愉快的一天!