简体   繁体   中英

SQL Statement Ignored and Missing Expression

I am trying to debug a trigger in Oracle SQL Developer, but I don't really understand the compiler's errors. I trying to follow the templates that I have seen, but it doesn't seem to be working out no matter what I try.

CREATE OR REPLACE TRIGGER audit_movie_insert_trig
REFERENCING NEW AS newRow
AFTER INSERT ON audit_movie 
FOR EACH ROW
BEGIN
INSERT INTO audit_movie VALUES(audit_seq.nextval,  newRow.title,  newRow.m_year,  newRow.m_length, newRow.genre, newRow.studio_name, newRow.producer, SYSDATE, 'Insert');
END;

The errors that I am getting are:

Error(2,7): PL/SQL: SQL Statement ignored
Error(2,83): PL/SQL: ORA-00936: missing expression

Any help would be great.

.m_length,

Please watch out.. it starts with a "." .. u miss the alias name!

You have clauses the wrong way round, as the syntax diagram shows . You should referencing clause after the after insert clause.

You also need to have a colon before newRow references. And you seem to be inserting in the same table the trigger is against, but it looks like your main table is probably just called movie ?

CREATE OR REPLACE TRIGGER audit_movie_insert_trig
AFTER INSERT ON movie 
REFERENCING NEW AS newRow
FOR EACH ROW
BEGIN
  INSERT INTO audit_movie (id, title, m_year, m_length, genre, studio_name,
    producer, when, what)
  VALUES(audit_seq.nextval, :newRow.title, :newRow.m_year, :newRow.m_length,
    :newRow.genre, :newRow.studio_name, :newRow.producer, SYSDATE, 'Insert');
END;

I've guessed the column names. As mentioned in a comment, you should specify the column names to avoid issues when the table definition is modified, and it makes it more obvious if you try to insert the wrong values into the wrong columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM