3 回答
TA贡献1757条经验 获得超7个赞
这样应该就可以了,不过自治事务用在业务比较复杂的数据库里面是要慎用的,很容易引发死锁,
create
or
replace
trigger
stu_upd
after
update
on
score
referencing
old
as
old
new
as
new
for
each
row
declare
pragma
autonomous_transaction
;
t_savg
number(6,2);
begin
select
avg(score)
into
t_savg
from
score
where
sno=:new.sno;
update
student
set
savg=t_savg
where
sno=:new.sno;
commit
;
end;
TA贡献1820条经验 获得超9个赞
主要原因是调用biu_document
触发器时,没有commit,所以执行
select
sum(money)
into
countmoney
from
(select
sto.counts
*
sto.price
money
from
stock
sto
where
sto.document_id
=
:new.document_id)
stock_moeny
时,返回的是null值。
触发器之间也不能传递参数,这里建议写存储过程吧
在biu_stock触发器中调用存储过程分别向document,affairs写数据。
TA贡献1801条经验 获得超8个赞
用select into 如果 查询出来的是null值,应该会报错吧
试试下面这个:
CREATE OR REPLACE TRIGGER BI_STO
BEFORE INSERT OR UPDATE
ON STOCK
FOR EACH ROW
declare
v_count int;
BEGIN
select count(*)
into v_count
from STORAGE STO
WHERE STO.WARE_ID = :NEW.WARE_ID;
if v_count > 0 then
UPDATE STORAGE
SET STORAGE_COUNTS = (STORAGE_COUNTS +:NEW.STOCK_COUNTS)
WHERE WARE_ID = :NEW.WARE_ID;
else
INSERT INTO STORAGE
VALUES(:NEW.WARE_ID,:NEW.STOCK_COUNTS);
end if;
END;
- 3 回答
- 0 关注
- 97 浏览
添加回答
举报