Why does Oracle 9i treat an empty string as NULL?

后端 未结 10 1543
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:39

I know that it does consider \' \' as NULL, but that doesn\'t do much to tell me why this is the case. As I understand the SQL specifications

10条回答
  •  庸人自扰
    2020-11-22 00:04

    Oracle documentation alerts developers to this problem, going back at least as far as version 7.

    Oracle chose to represent NULLS by the "impossible value" technique. For example, a NULL in a numeric location will be stored as "minus zero", an impossible value. Any minus zeroes that result from computations will be converted to positive zero before being stored.

    Oracle also chose, erroneously, to consider the VARCHAR string of length zero (the empty string) to be an impossible value, and a suitable choice for representing NULL. It turns out that the empty string is far from an impossible value. It's even the identity under the operation of string concatenation!

    Oracle documentation warns database designers and developers that some future version of Oracle might break this association between the empty string and NULL, and break any code that depends on that association.

    There are techniques to flag NULLS other than impossible values, but Oracle didn't use them.

    (I'm using the word "location" above to mean the intersection of a row and a column.)

提交回复
热议问题