Skip to Main Content
  • Questions
  • Need help to overcome ORA 00936 error

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: August 06, 2021 - 7:33 pm UTC

Last updated: August 16, 2021 - 4:44 am UTC

Version: Oracle 11g

Viewed 1000+ times

You Asked

I have added a column to an existing table and then wanted to make it NOT NULL one so gave the below query to DBA
alter table table_name modify(column_name DEFAULT on null column_name.nextval);
It gave the ORA 00936 - missing expression error.

NOTE - the column is a sequence and self-incrementing.

and Connor said...

The facility to use a sequence as a default only comes in 12c onwards.

Its time to upgrade!

(Otherwise you need to do it with a trigger) and the migration would be along the lines of

- create sequence
- alter table add column NULLABLE
- update table set col = seq.nextval
- alter table modify column not null
- create trigger to populate column if null.

or .... upgrade :-)



Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

anu, August 13, 2021 - 12:05 pm UTC

Thank you so much for your answer. It really helped!
Would you please be able to advise if a Before Insert trigger would suffice, as I will have to do it in 11g now.
Connor McDonald
August 16, 2021 - 4:44 am UTC

Yes, a BEFORE INSERT FOR EACH ROW trigger

if :new.pk_col is null then
  :new.pk_col := seq.nextval;
end if;

More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database