Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Edgar.

Asked: March 09, 2018 - 7:11 pm UTC

Last updated: March 13, 2018 - 2:11 am UTC

Version: 12c

Viewed 1000+ times

You Asked

hi tom, i hava a question about the feature oracle 12c (field invisible). Why if i to do create a new field with condition invisible and not null constrain this failure when insert values into the table, but dont is enable for set values to new field on statements.

Example my practice:

create table temporal (campo1 number(12) not null,
                       campo2 varchar2(10) not null);

alter table temporal add (campo3 number(12) invisible not null);


insert into temporal values(1, 'ROW 1');

ORA-01400: cannot insert NULL into (squema.TEMPORAL.CAMPO3);


insert into temporal values(1, 'ROW 1', 1);

ORA-00913: too many values 

--

the feature are field with invisible property joined to null value constrain always? or do i doing some wrong?

with LiveSQL Test Case:

and Connor said...

The objective behind an invisible column is typically to add or remove a column from a table without impacting existing (or perhaps new) application code.

Obviously if that new column is NOT NULL, then by definition, you are demanding that *all* application code be aware of it. Typically, this would not be the case, because only *new* application that knows about the existence of the new column would be populating it.

If you needed to ensure that the new application was not making a mistake an inserting nulls, you could temporarily have a constraint that implements a nullness check for *just* the new application. For example, the new application could set a context variable and the constraint would be:

alter table T
  add constraint chk check ( new_col is not null or sys_context('MY_CONTEXT','APP_VERSION') = '[old version]' );


When all of the application code has been migrated over *and* historical data has been updated, then you could then change the constraint to be a standard not null constraint.


Rating

  (2 ratings)

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

Comments

So whole check constraint must not be null

Gh, March 11, 2018 - 7:30 am UTC

Since the evaluation of the constraint must not make this column non nullable, Oracle must do his check at the ddl level and hence returns an error say " ora-nnn Invisible column constraints must not make the column deterministically not null"
Connor McDonald
March 11, 2018 - 11:53 am UTC

Sorry, I don't understand the point you're making

Edgar Corona, March 12, 2018 - 11:47 am UTC

hi, Tom.

Perfecto, muchas gracias por tu tiempo y por esa excelente soluciĆ³n.

Saludos
Connor McDonald
March 13, 2018 - 2:11 am UTC

de nada

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.