default '' ,default null对于字符串列有什么区别?
在把MS Sql 数据库转换成Oracle 的过程中发现它们对Default字段的处理方式不一致。
在Oracle中看如下语句:
drop table testtable ;
create table testtable
(
"No" number default 0 not null ,
"Note" varchar2(1024) default '' not null
);
commit ;
insert into testtable ("No","Note") values(1,'test');
insert into testtable ("Note") values('test') ;
insert into testtable ("Note") values('') ;
insert into testtable ("No") values(2);
commit ;
返回结果如下:
表已丢弃。
表已创建。
提交完成。
已创建 1 行。
已创建 1 行。
insert into testtable ("Note") values('')
*
ERROR 位于第 1 行:
ORA-01400: 无法将 NULL 插入 (...."Note")
insert into testtable ("No") values(2)
*
ERROR 位于第 1 行:
ORA-01400: 无法将 NULL 插入 (...."Note")
提交完成。
说明:
insert into testtable ("Note") values('') ;
insert into testtable ("No") values(2);
这两句无效。即在Oracle中''(长度为0的字符串)被做为NULL处理了(而在MS Sql 中以分出NULL与'')。是不是可以这样理解?
请高手指点指点:如果确定需要默认长度为0的字符型字段时怎样处理呢?就像上面的那样?