database PL/SQL:SQL 语句被忽略?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16509335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:57:37  来源:igfitidea点击:

PL/SQL: SQL Statement ignored?

databaseoracleplsqltriggers

提问by Richard Clare

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'

我收到的错误是“第 4 行错误:PL/SQL:SQL 语句被忽略 0.10 秒”

Anyone any guesses why?

有没有人猜到为什么?

thanks for the help

谢谢您的帮助

回答by Alex Poole

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:

显示的错误只是最高级别。根据您运行它的位置,您应该能够看到堆栈跟踪。客户将确切地确定如何做到这一点;无论如何,SQL*Plus 或 SQL Developer 会向您展示更多,但我并不真正了解其他客户。如果您在客户端中看不到详细信息,则可以使用以下命令查询它们:

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 referencingclause has be preceded by a colon, so :OLDin this case. As you're doing already in the insert ... values()clause.

当从表中引用旧(或新)值时,referencing子句中指定的名称前面有一个冒号,所以:OLD在这种情况下。正如你在insert ... values()条款中所做的那样。

(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).

(从评论中,我的假设证明是错误的 - 以及缺少冒号的问题,表名确实是placed_order,没有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 triggerwhich introduces the referencingclause.

似乎您从上一个问题的两个答案中复制了代码,而没有真正了解他们在做什么。您可能需要查看触发器设计指南(特别是关于不重复数据库功能的指南)和引入该子句的语法create triggerreferencing