1
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;

I do not no why I get this error:

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

I run the following query, but it does not return any rows:

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

1 Answer 1

4

The name in where name= must be uppercase, Oracle by default has all object names in uppercase unless explicitly quoted (which is a bad idea to do in general). Better is something like:

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
/

The line numbers with triggers start AFTER the trigger definition, so at declare.

Actual problem

Add colon before EACH reference to new in trigger definition as in:

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;
Sign up to request clarification or add additional context in comments.

3 Comments

thank you so much,it worked ,and trigger compiled without errors
but when i insert values into grade ,this error happens :SQL Error: ORA-04098: trigger 'SYSTEM.FAILED' is invalid and failed re-validation 04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation" *Cause: A trigger was attempted to be retrieved for execution and was found to be invalid. This also means that compilation/authorization failed for the trigger. *Action: Options are to resolve the compilation/authorization errors, disable the trigger, or drop the trigger.
Sounds like a trigger in the system schema. Check 'select * from dba_triggers where owner='SYSTEM'. Is it valid? If not, make it valid. As editor you can use TOAD or Invantive Query Tool. Or drop it after saving the script using `drop trigger system.failed'. Create script using F4 in TOAD or query tool.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.