我正在使用Oracle SQL Developer,但不能弄清楚如何实现我的任务。
下面是我的代码,它不能正常工作:
CREATE OR REPLACE TRIGGER TRIGGER1
AFTER DELETE OR INSERT OR UPDATE OF AXLE, DIFERANTIAL, SHAFTS
ON WAREHOUSE_PRODUCTS
BEGIN
SELECT
SUM(Shaft) AS shaftot,
SUM(AXLE) AS axletot,
SUM(diferantial) AS diftot
FROM
warehouse_products;
UPDATE total_stocks
SET shafts_stock = shafts_stock + shaftot,
axle_stock = axle_stock + axletot,
differential_stock = differential_stock + diftot
WHERE
shafts_stock = shafts_stock
AND axle_stock = axle_stock
AND diferantial_stock = diferantial_stock;
END;
当指定的列受到插入、更新或删除影响时,我正在尝试将总和与另一个表列相等。
1条答案
按热度按时间jjjwad0x1#
不要使用触发器,使用视图:
如果你必须使用触发器,那么你的
total_stocks
表应该只有一行,你可以将所有内容合并到一个MERGE
语句中:至于你的代码:
SHAFTS
,在主体中使用SHAFT
。INTO
子句的查询。fiddle