CREATE OR REPLACE TRIGGER UPDATE_FAC_CUS_MST_MREC_TRG BEFORE UPDATE
OF CUST_CODE ON fac_cus_mst FOR EACH ROW
DECLARE
v_cust_code VARCHAR2(25);
BEGIN
SELECT cust_code
INTO v_cust_code
FROM fac_cus_mst
WHERE cust_code = :new.cust_code;
UPDATE money_rec
SET cust_code = v_cust_code
WHERE REF = :new.REF;
END;
/
我尝试过此代码,但是没有奏效,返回错误 喜欢
10/18 PLS-00049:错误的绑定变量'NEW.REF'SQL>创建或
更新之前
替换触发器UPDATE_FAC_CUS_MST_MREC_TRG 2 CUST_CODE ON fac_cus_mst 3 FOR EACH ROW 4 DECLARE 5
v_cust_code VARCHAR2(25); 6 BEGIN 7 SELECT客户代码8
INTO v_cust_code 9从fac_cus_mst 10在哪里
cust_code =:new.cust_code 11更新money_rec 12
SET cust_code = v_cust_code 13 WHERE REF =:new.REF; 14 END; 15 /警告:由于编译错误而创建的触发器。
SQL> show error Errors for TRIGGER UPDATE_FAC_CUS_MST_MREC_TRG:
LINE/COL ERROR
-------- ----------------------------------------------------------------- 4/5 PL/SQL: SQL Statement ignored 8/8 PL/SQL: ORA-00933: SQL command
not properly ended 10/18 PLS-00049: bad bind variable 'NEW.REF'
SQL>
CREATE OR REPLACE TRIGGER UPDATE_FAC_CUS_MST_MREC_TRG BEFORE UPDATE
OF CUST_CODE ON fac_cus_mst FOR EACH ROW
DECLARE
v_cust_code VARCHAR2(25); BEGIN
SELECT cust_code
INTO v_cust_code
FROM fac_cus_mst
WHERE cust_code = :new.cust_code;
UPDATE money_rec
SET cust_code = v_cust_code
WHERE REF = :new.REF;
END;
/
答案 0 :(得分:0)
不管显示的错误是什么,触发器都有问题。您无法在触发器内的同一表上写查询,否则将导致"Table is mutating"错误。
CREATE OR REPLACE TRIGGER UPDATE_FAC_CUS_MST_MREC_TRG
BEFORE UPDATE
OF CUST_CODE ON fac_cus_mst FOR EACH ROW
BEGIN
UPDATE money_rec
SET cust_code = :new.cust_code
WHERE REF = :new.REF;
END;
/
您只需要一个简单的更新语句,并直接在其中引用:new.cust_code
。
关于错误PLS-00049: bad bind variable 'NEW.REF'
,看来您的money_rec
表 显然没有 REF
列。在其位置使用正确的列名,您的触发器应能正常工作。