strange constraint behavior

  • From: Anton Bushmelev <djeday84@xxxxxxxxx>
  • To: oracle-l@xxxxxxxxxxxxx
  • Date: Mon, 10 Oct 2016 16:48:14 +0300

hello, look at new patch from developer and found strange construction, here 
I’ll try to reproduce what they want to do:

create table tt as select level id from dual connect by level <=100; 
alter table tt add flag varchar2(50)  default '' not null ;
Table altered.

select dump (flag,8 ) as dmp from tt ;

DMP
----------
NULL
NULL
…..
NULL


 select count (*) from tt where flag is null;

  COUNT(*)
----------
         0

select count (*) from tt where flag is not null;

  COUNT(*)
----------
       100


How it is possible ? =)))


ps: if I add default null, then all goes well:
 
 alter table tt add flag varchar2(50)  default null not null ;
alter table tt add flag varchar2(50)  default null not null
            *
ERROR at line 1:
ORA-01758: table must be empty to add mandatory (NOT NULL) column 
 
create table tt as select level id from dual connect by level <=100;
 alter table tt add flag varchar2(50)  default null not null ;
alter table tt add flag varchar2(50)  default null not null
            *
ERROR at line 1:
ORA-01758: table must be empty to add mandatory (NOT NULL) column


ps: sorry for my English
       

Other related posts: