2011-03-04 135 views
-1
CREATE TRIGGER update_orderline 

AFTER INSERT OR UPDATE ON ORDERS 

FOR EACH ROW 

BEGIN 

    INSERT INTO ORDERLINE(orderline_no, qty, order_no, product_no) 

    VALUES (ol_no.nextval, :new.qty, :new.order_no, :new.product_no); 

END; 

我試圖創建一個觸發器,在新記錄插入訂單後更新orderline表。但我得到這個錯誤:觸發器更新另一個表

Error(3,26): PLS-00049: bad bind variable 'NEW.QTY' 

Error(3,51): PLS-00049: bad bind variable 'NEW.PRODUCT_NO' 
+0

你能給我們ORDERS表的結構嗎?和ORDERLINE? – Xavinou 2011-03-04 18:05:40

+0

@ Xavinou:order_no,employee_no,branch_no,order_date,ship_date,shipping_method,tax_status,小計,tax_amt,shipping_charge,total_amt,customer_no – tbrown 2011-03-04 18:10:36

+0

您能解釋業務邏輯嗎?數量從哪裏來?使用封裝了訂單的插入/更新的存儲過程或order_line – 2011-03-05 04:12:35

回答

0

我想我找到了。

看吧:http://www.tek-tips.com/viewthread.cfm?qid=1556226&page=14

You have inadvertently discovered why, in the "Oracle World" it is generally bad form to code user-defined names within double quotes. You see, whenever you define a name in Oracle using double quotes and any alpha character that is not UPPER CASE, then you must always use double quotes and the same mixed-case configuration. If you do not use double-quotes, then Oracle presumes that regardless of your case in the code, that your Oracle name is uppercase !

So, when your referred, in your code, to "...INTO :new.user_idx...", Oracle looks for "USER_IDX", which it cannot find, since you defined that column as *"user_idx"* -- "user_idx" <> "USER_IDX".

If you sanitize your code of all double quotes, then your problem(s) should disappear.

+0

@ Xavinou可能會更好:謝謝,但雙引號對我來說不是問題。我檢查了我的創建腳本以確保。 :( – tbrown 2011-03-04 18:21:37

1

如果我猜的訂單表沒有名爲「order_no」和「product_no」列。我可以在這種情況下重現錯誤並獲取綁定變量消息。那麼訂單表的列名是什麼?

更新:沒有什麼可以根據您的評論爲order_no或product_no或那個問題獲取新值。你期望價值從何而來?

UPDATE:Accordin你更新你在Orders表的列:

order_no,
employee_no,
branch_no,
order_date,
ship_date,
shipping_method,
tax_status,
subtotal,
tax_amt,
shipping_charge,
total_amt,
customer_no

在列該名單我沒有看到product_no或數量。 Order_no在那裏。

+0

@ jschoen:我認爲新的值將被插入到orders表中,例如,假設一個新行被插入到了命令中,那麼觸發器應該根據新記錄是什麼來更新命令行所以,新的記錄也會有產品號和數量 – tbrown 2011-03-04 18:25:15

+0

@ jschoen:糟糕!你說得對,沒有product_no。所以,這意味着,product_no必須來自產品表 – tbrown 2011-03-04 18:33:23

+0

@tbrown也許你正在這樣做向後,也許你的訂單行表應該有一個觸發器,它會在更新時插入或更新訂單表,可能不會,你可能需要將這種類型的功能轉移到你的業務邏輯ode中,而不是試圖通過觸發器來做到這一點 – 2011-03-04 18:35:10

相關問題