【发布时间】:2012-12-18 17:29:14
【问题描述】:
-
表 1:客户
cust_no | cust_credbal |信用状态
-
表 2:customer_credittopup
cust_no |交易金额
我有上面两张表,我在插入Table2后写了一个更新触发器来更新Table1。因此,Table1cust_credbal 中的金额在 Tabl1 中添加 cust_credbal + Table2 中 trans_amount 中的新值后更新。如何在更新后添加 if 语句以检查 cust_credbal 是否大于 20,然后 cred_status 设置为“有效”,否则为“已用完”
我的触发器显示此错误:第 8 行错误:PLS-00049: bad bind variable 'NEW.CUST_CREDITBAL'
CREATE OR REPLACE TRIGGER after_insert_credittopup
AFTER INSERT ON customer_credittopup
FOR EACH ROW
DECLARE
credit number(11);
BEGIN
UPDATE customers
SET cust_creditbal=cust_creditbal +:new.trans_amount
WHERE cust_no=:new.cust_no;
SELECT Cust_creditbal INTO credit
FROM customers WHERE cust_no=:new.cust_no;
IF(:new.cust_creditbal>0) THEN
UPDATE customers
SET Cust_credstatus='Valid'
WHERE cust_no=:new.cust_no;
end if;
end;
/
【问题讨论】:
-
哪个表有 'cust_creditbal' 字段?如果它在
customers中,则:new.cust_creditbal仅在customers表上的触发器内才有意义。
标签: sql database oracle triggers