mounaim
mounaim

Reputation: 1180

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

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 ?

Upvotes: 2

Views: 9844

Answers (1)

user330315
user330315

Reputation:

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)

Upvotes: 10

Related Questions