Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

empty string in oracle

When I insert an empty String in a database table column, it looks like it is internally stored as NULL. So why can I not select the respective row by looking for exactly that empty string?

Example:

insert into mytable (mycolumn,col2,col3) values ('','xyz','abc');

// now there is a row having mycolumn == NULL

select * from mytable where mycolumn='';

// empty :(

What can I do about that?

like image 910
Lokomotywa Avatar asked Mar 25 '26 11:03

Lokomotywa


1 Answers

This is a weird anachronism in Oracle (using default settings). Oracle does, indeed, treat an empty string as NULL. This includes in comparisons, so:

where mycolumn = ''

is the same as:

where mycolumn = NULL

And this never returns true (NULL <> NULL).

My advice? Get used to using NULL explicitly and writing:

where mycolumn is null
like image 90
Gordon Linoff Avatar answered Mar 27 '26 01:03

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!