错误(3,1):PL / SQL:忽略SQL语句

时间:2014-01-13 20:25:33

标签: sql oracle stored-procedures

CREATE or replace TRIGGER Maxscore
BEFORE INSERT ON grade
REFERENCING NEW AS new
FOR EACH ROW
DECLARE 
  mins INT;
BEGIN
  SELECT min_score 
  INTO   mins
  FROM   courses
  WHERE  id = new.course_id
  ;
  IF new.grade < mins   
  THEN
    new.grade := 100 - mins;
  END IF;
END;

我不知道为什么会收到此错误:

Error(3,1): PL/SQL: SQL Statement ignored

我运行以下查询,但它不返回任何行:

select * 
from user_errors 
where name = 'maxscore' and type = 'TRIGGER';

1 个答案:

答案 0 :(得分:4)

where name=中的名称必须为大写,默认情况下,Oracle的所有对象名称都是大写的,除非明确引用(一般来说这是个坏主意)。 更好的是:

select err.name
,      err.type
,      err.line
,      err.position
,      err.text
from   user_errors err
join   user_objects ojt
on     ojt.object_name = err.name
and    ojt.object_type = err.type
where  attribute != 'WARNING'
and    message_number not in (905,304,364)
and    lower(err.text) not like '%ignored%'
and    lower(err.text) not like '%terminated%'
and    lower(err.text) not like '%triggering view is invalid%'
and    lower(err.text) not like '%has errors%'
order
by     ojt.last_ddl_time desc
,      err.name
,      err.line
/

带触发器的行号在触发器定义之后开始,因此在声明。

实际问题

在EACH引用之前添加冒号,如下所示:

drop table grade

create table grade(a number, grade number, course_id number)

CREATE or replace TRIGGER Maxscore
BEFORE INSERT ON grade
REFERENCING NEW AS new
FOR EACH ROW
DECLARE 
  mins INT;
BEGIN
  SELECT min_score
  INTO   mins
  FROM   courses
  where  id = :new.course_id
  ;
  IF :new.grade < mins   
  THEN
    :new.grade := 100 - mins;
  END IF;
END;