PL/SQL: SQL Statement ignored?

跟風遠走 提交于 2020-01-05 10:09:18

问题


Hi everyone getting this error message when trying to create a trigger and its got me a little stumped. Here is my trigger code.

CREATE OR REPLACE TRIGGER CUSTOMER_AD
  AFTER DELETE ON CUSTOMER
  REFERENCING OLD AS OLD
  FOR EACH ROW
DECLARE
  nPlaced_order_count  NUMBER;
BEGIN
  SELECT COUNT(*)
    INTO nPlaced_order_count
    FROM PLACED_ORDERS p
    WHERE p.FK1_CUSTOMER_ID = OLD.CUSTOMER_ID;
IF nPlaced_order_count > 0 THEN
INSERT into previous_customer
(customer_id,
first_name,
last_name,
address,
AUDIT_USER,
AUDIT_DATE)
VALUES
(:old.customer_id,
:old.first_name,
:old.last_name,
:old.address,
UPPER(v('APP_USER')),
SYSDATE);
END IF;
END CUSTOMER_AD;

And the error I'm getting 'Error at line 4: PL/SQL: SQL Statement ignored 0.10 seconds'

Anyone any guesses why?

thanks for the help


回答1:


The error shown is only the highest level. Depending where you're running it you should be able to see the stack trace. The client will determine exactly how to do that; SQL*Plus or SQL Developer would show you more than this anyway, but I don't really know about other clients. If you can't see the details in your client then you can query for them with:

select * from user_errors where name = 'CUSTOMER_AD' and type = 'TRIGGER'

Assuming the tables all exist, it's probably this line:

WHERE p.FK1_CUSTOMER_ID = OLD.CUSTOMER_ID;

which should be:

WHERE p.FK1_CUSTOMER_ID = :OLD.CUSTOMER_ID;

When referencing the old (or new) value from the table, the name as specified in the referencing clause has be preceded by a colon, so :OLD in this case. As you're doing already in the insert ... values() clause.

(From comments, my assumption turned out to be wrong - as well as the missing colon problem, the table name is really placed_order, without an s).

Seems like you copied code from both answers to your previous question without really understanding what they were doing. You might want to look at the trigger design guidelines (particularly the one about not dupicating database functionality) and the syntax for create trigger which introduces the referencing clause.



来源:https://stackoverflow.com/questions/16509335/pl-sql-sql-statement-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!