Oracle
is very very very old.
Back in 80's
when it was developed (and before there were any standards) they thought is was a good idea, and given then way Oracle
stores its values, it really was.
Here's how Oracle
stores data (taken from the documentation):
No datatype is stored within the data, only the data length and the data itself.
If the NULL
occurs between two columns with values, it's stored as a single byte meaning column has length 0
(actually, 0xFF
). Trailing NULL
s are not stored at all.
So to store the value 'test'
, Oracle
needs to store 5 bytes: 04 74 65 73 74
.
However, to store both an empty string and a NULL
, Oracle
just needs to set data length to 0
.
Very smart if your data are to be stored on 20 Mb
hard drives that cost 5,000$
each.
Later, when the standards appeared, it wasn't such a good idea anymore, but by that time there already were lots and lots of code relying on NULL
and ''
being the same thing.
Making VARCHAR
to do such a distinction will break tons of code.
To fix it, they renamed VARCHAR
to VARCHAR2
(which is not a part of any standard), stated that VARCHAR2
will never distinguish between a NULL
and an empty string and urged everybody to use this datatype instead.
Now they are probably waiting for the last person who used a VARCHAR
in Oracle
database to die.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…