无法调用并插入函数在触发器内返回的值,是否有任何我缺少的东西?

时间:2014-06-03 12:46:37

标签: function plsql triggers

我想在表上使用触发器,每次插入,更新,删除行时都会触发该触发器。我写了类似这样的内容:遗憾的是,我调用的函数不起作用,它给出了java.sql.SQLSyntaxErrorException :ora-04098 : trigger Compiere3.test01 is invalid and failed re-validation.

CREATE OR REPLACE TRIGGER test001
   AFTER INSERT OR UPDATE OR DELETE
   ON m_transaction
   FOR EACH ROW
DECLARE
   Availableqty   NUMBER;
BEGIN
   Availableqty := BOMQTYAVAILABLE (:old.m_product_id, 1000000, 1000000);

   INSERT INTO MonitorTable (m_transaction_id, m_product_id, Availableqty)
        VALUES (OLD.m_transaction_id, OLD.m_product_id, Availableqty);
END;

2 个答案:

答案 0 :(得分:1)

最后我找到了解决方案,正确的语法如下:

CREATE OR REPLACE TRIGGER test001
   AFTER INSERT OR UPDATE OR DELETE
   ON m_transaction
   FOR EACH ROW
DECLARE
   Availableiqty   NUMBER;
BEGIN
   Availableiqty := BOMQTYAVAILABLE (:new.m_product_id, 1000000, 1000000);

   INSERT INTO MonitorTable (m_transaction_id, m_product_id, Availableqty)
        VALUES (:new.m_transaction_id, :new.m_product_id, Availableiqty);
END;

答案 1 :(得分:0)

在你的列名子句中,也许Availableqty应该是m_availableqty?基于您明显的命名约定。它期待一个列名并获得一个变量。