我收到此错误,这似乎是列拼写的问题。但是,我百分之九十九确定我拼写的一切都是正确的,但我看不出有任何理由得到我做的错误......
这是来源:
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
这给出了:
12/12 PLS-00049: bad bind variable 'V_NEW_QOH'
我尝试用以下组合替换第12行:
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;
但它仍然给我错误。
产品表如下所示:
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)
);
提前感谢您的帮助。
答案 0 :(得分:16)
将更新更改为:
UPDATE products
SET qoh = v_new_qoh
WHERE id = :new.product_id;
即。 v_new_qoh前面没有冒号。
行号(12)是指PL / SQL块的行号。 该块以单词DECLARE开头,因此第12行是以:
开头的行SET qoh = :v_new_qoh
答案 1 :(得分:8)
和new.quantity
应为:new.quantity
答案 2 :(得分:0)
用于将相同的sample_insp_id值插入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;
答案 3 :(得分:-1)
创建或替换触发器
"BI_PROJECT_PART_SAMPLE_INSP"
插入之前
"PROJECT_PART_SAMPLE_INSP"
每行
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;