ORA-01400:無法將NULL插入,ORACLE中DAFAULT和DAFAULT ON NULL的區別

建表:

create table aims_test(
id number(16),
birthday date default on null sysdate not null,
happlybirth date default sysdate not null,
happyday date default on null sysdate
)
insert into aims_test(id) values (2); -- 插入3個時間
insert into aims_test(id,birthday) values (3,null); --插入3個時間
insert into aims_test(id,birthday,happlybirth) values (4,null,null); --報錯,因爲是default 不是default on null

總結:

default on null 會自動將字段變成not null,不需要再設置not null, default不會

default on null 當插入null的時候變成默認值,default會報錯

當插入時不指定列名時insert into aims_test(id) values (2),default和default on null 都會將字段設置成默認值。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章