【发布时间】:2019-05-07 16:04:48
【问题描述】:
我创建了一个触发器,每当我更新不同表中的列时,它都会更新我创建的表。到目前为止,我的触发器已编译,但当我更新列时,触发器似乎没有触发或执行任何操作。
谁能帮帮我?
CREATE TABLE bb_sales_sum (
idProduct number(2) NOT NULL,
total number(6,2),
quantity number);
CREATE OR REPLACE TRIGGER BB_SALESUM_TRG
AFTER UPDATE OF orderplaced on bb_basket
FOR EACH ROW
WHEN (NEW.orderplaced = 1)
DECLARE
lv_count Number;
BEGIN
if :new.orderplaced = 1 then
for item in
(select idproduct, (quantity * price) AS total, quantity
from bb_basketitem
where idbasket = :old.idbasket)
loop
select count(*)
into lv_count
from bb_sales_sum where idProduct = item.idproduct;
if lv_count = NULL then
INSERT INTO bb_sales_sum
VALUES (item.idproduct, item.total, item.quantity);
else
update bb_sales_sum
set quantity = item.quantity where
idProduct = item.idproduct;
end if;
end loop;
end if;
END;
/
update bb_basket
set orderplaced = 1
where idbasket = 14;
select * from bb_sales_sum;
【问题讨论】:
-
my answer 对您之前对同一问题提出的问题有什么问题?你试过了吗?请注意,
if lv_count = NULL永远不会是真的。count(*)始终返回 0 或实际计数。此外,即使是真的,something = NULL也不是比较null的正确方法 -
我对合并一点也不熟悉。想知道是否有其他方法可以做到这一点?
-
我非常感谢您的帮助。