I'm getting this error which seems to be an issue with column spelling. However I am 99% percent sure I have spelled everything correct, but I can't see any reason to be getting the error I do...
Here's the source:
CREATE OR REPLACE TRIGGER update_qoh_trigger
AFTER INSERT ON sales
FOR EACH ROW
DECLARE
v_qoh products.qoh%TYPE;
v_new_qoh products.qoh%TYPE;
BEGIN
SELECT qoh INTO v_qoh
FROM products
WHERE id = :new.product_id;
v_new_qoh := v_qoh - new.quantity; // ERROR HERE
UPDATE products
SET qoh = :v_new_qoh
WHERE id = :new.product_id;
END;
/
sho err
And that gives a:
12/12 PLS-00049: bad bind variable 'V_NEW_QOH'
I have tried replacing line 12 with the following combinations:
v_new_qoh := :v_qoh - :new.quantity;
:v_new_qoh := :v_qoh - :new.quantity;
:v_new_qoh = :v_qoh - :new.quantity;
:v_new_qoh := v_qoh - :new.quantity;
:v_new_qoh := :v_qoh - new.quantity;
v_new_qoh := v_qoh - :new.quantity;
But it still gives me the error.
The products table looks like this:
CREATE TABLE products (
id NUMBER,
name VARCHAR2,
price NUMBER,
qoh NUMBER(2)
);
CREATE TABLE sales (
id NUMBER(10) AUTO_INCREMENT,
customer_id NUBMER(3),
product_id NUMBER(3),
quantity NUMBER(2),
price NUMBER(5,2),
sale_date DATE,
despatch_id NUMBER(10)
);
Thanks in advance for your help.
Change the update to:
UPDATE products
SET qoh = v_new_qoh
WHERE id = :new.product_id;
i.e. no colon in front of v_new_qoh.
The line number (12) refers to the line number of the PL/SQL block. The block begins with the word DECLARE, so the 12th line is the one starting with:
SET qoh = :v_new_qoh
and new.quantity
should be :new.quantity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With