2011-03-04 119 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

相关问题