Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Update table with 'default on null'-fields

3410314Aug 10 2017 — edited Aug 11 2017

Hey folks!

I have created a table with default values for fields like

CREATE TABLE T_EXAMPLE (

   "VALUE" NUMBER(10,2) DEFAULT ON NULL 0

   ...

)

The compiler automatically adds 'NOT NULL ENABLE' so it looks like below:

CREATE TABLE T_EXAMPLE (

   "VALUE" NUMBER(10,2) DEFAULT ON NULL 0 NOT NULL ENABLE

   ...

)

So when I insert null, 0 is actually inserted into the table - null is invalid as a value. This however does not seem to work when updating the table, as I get ORA-01407 error, if the update value is null. Why is that (Edit: Why is it implemented like that on a meta level)?

My solution was to add the coalesce()-function to the update command, to enforce the default value. This seems suboptimal to me when it comes to maintenance, as I have to change both, code and table-defaults, in case. Is there a preferable solution?

Thanks in advance.

This post has been answered by Frank Kulash on Aug 10 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 7 2017
Added on Aug 10 2017
6 comments
8,241 views