Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: JDBC Driver setObject() converts empty string to NULL
Vladimir M. Zakharychev wrote:
> Hmm... Not exactly clear what the problem is, but I'll try:
> in Oracle, empty strings *are* NULLs. This is known and
> documented behavior. setString() or setObject() probably
> convert empty strings to NULLs because they are the
> same thing in Oracle. You need to code for this behavior
> as it can't be turned off.
Thanks for the hint. I can't believe that this slipped by me until now. For interested parties, here is a simple test:
SQL> set pagesize 1000 SQL> set linesize 150 SQL> create table t1 (
2 id number(10) not null,
3 text1 varchar2(100) null,
4 text2 varchar2(100) not null
5 );
Table created.
SQL> insert into t1 ( id, text1, text2 ) values ( 1, '', '' ); insert into t1 ( id, text1, text2 ) values ( 1, '', '' )
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("CR"."T1"."TEXT2")
SQL> insert into t1 ( id, text1, text2 ) values ( 2, NULL, '' ); insert into t1 ( id, text1, text2 ) values ( 2, NULL, '' )
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("CR"."T1"."TEXT2")
SQL> insert into t1 ( id, text1, text2 ) values ( 3, '', NULL ); insert into t1 ( id, text1, text2 ) values ( 3, '', NULL )
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("CR"."T1"."TEXT2")
SQL> select * from t1 where text1 is null;
no rows selected
SQL> select * from t1 where text2 is null;
no rows selected
SQL> select * from t1;
no rows selected
SQL> drop table t1;
Table dropped.
Thanks again!
Kind regards
robert Received on Wed May 31 2006 - 03:08:49 CDT