Table,View Or Sequence reference 'SEQUENCE.NEXTVAL' not allowed in this context

mounaim picture mounaim · Mar 19, 2014 · Viewed 9k times · Source

I'm having this error while trying to compile the following trigger :

CREATE OR REPLACE TRIGGER INCREMENTER_ID_CONSISTANCE 

BEFORE INSERT ON BD.CONSISTANCE 
for each row
BEGIN
:new.code := ID_CONSISTANCE.nextval;
END;  


**ERROR** : Table,View Or Sequence reference 'ID_CONSISTANCE.nextval' not allowed in
this context  

What is the problem here ? and how can I fix this ?

Answer

a_horse_with_no_name picture a_horse_with_no_name · Mar 19, 2014

This syntax is only allowed in Oracle 11 or later.

The (unsupported and outdated) 9i version did not support direct assignment of a sequence value.

You need to use a select into instead:

select ID_CONSISTANCE.nextval
  into :new.code 
FROM dual;

And you should really plan an upgrade to a current version of Oracle (11.x or 12.x)