Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to store '' (empty string) as a non NULL value in the database?

I am using Oracle DB. At the database level, when you set a column value to either NULL or '' (empty string), the fetched value is NULL in both cases. Is it possible to store '' (empty string) as a non NULL value in the database?

I execute this

UPDATE contacts SET last_name = '' WHERE id = '1001';

commit;

SELECT last_name, ID FROM contacts WHERE id ='1001';

LAST_NAME                  ID
------------               ------
null                       1001

Is it possible to store the last_name as a non-NULL empty string ('')?

like image 231
RHT Avatar asked Feb 02 '10 16:02

RHT


People also ask

Can we insert empty string in NOT NULL column?

Yes you can...

Is empty string considered as NULL?

The Java programming language distinguishes between null and empty strings. An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.

Is empty string considered NULL in SQL?

What is NULL? NULL is used in SQL to indicate that a value doesn't exist in the database. It's not to be confused with an empty string or a zero value. While NULL indicates the absence of a value, the empty string and zero both represent actual values.

Is empty string NULL in MySQL?

Learn MySQL from scratch for Data Science and Analytics In the above syntax, if you compare empty string( ' ') to empty string( ' '), the result will always be NULL.


2 Answers

The only way to do this in oracle is with some kind of auxiliary flag field, that when set is supposed to represent the fact that the value should be an empty string.

like image 121
recursive Avatar answered Sep 21 '22 12:09

recursive


As far as i know Oracle does not distinguish between '' and NULL, see here.

like image 29
wallenborn Avatar answered Sep 18 '22 12:09

wallenborn