开发者

Oracle SQL PLS-00049: bad bind variable

I'm getting this error which seems to be an issue with column spelling. However I am 99% percent sure I have spelled everything correc开发者_开发技巧t, 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


for inserting same value of sample_insp_id in to Sir_no:-

update TRIGGER "PT"."BI_PROJECT_PART_SAMPLE_INSP"   
  before insert on "PROJECT_PART_SAMPLE_INSP"               
  for each row  
begin   
  if :NEW."SAMPLE_INSP_ID" is null then
    select "PROJECT_PART_SAMPLE_INSP_SEQ".nextval into :NEW."SAMPLE_INSP_ID",:NEW."SIR_NO"from dual;
  end if;
end; 


Create or replace trigger

"BI_PROJECT_PART_SAMPLE_INSP"   

before insert on

"PROJECT_PART_SAMPLE_INSP"               

for each row

begin   
    if :NEW."SAMPLE_INSP_ID" is null then
        select "PROJECT_PART_SAMPLE_INSP_SEQ".nextval into :NEW."SAMPLE_INSP_ID" from dual;
        :NEW."SIR_NO":= :NEW."SAMPLE_INSP_ID";
    end if;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜