gpt4 book ai didi

sql - 具有空字符串的Oracle NVL

转载 作者:行者123 更新时间:2023-12-04 13:09:22 25 4
gpt4 key购买 nike

我有此表,其中NULL是NULL值,而不是字符串NULL:

MYCOL
--------
NULL
example

为什么此查询不返回 NULL行?
select * from example_so where nvl(mycol, '') = '';

最佳答案

''再次是Oracle中的NULL,因为Oracle不像其他高级语言或DBMS一样支持空字符串。

您需要使用IS NULLIS NOT NULL查找NULL/空字符串

尽管它在语法上是有效的,但是没有其他关系运算符可对NULL起作用。 SQLFiddle Demo

它一定要是,

select * from example_so where mycol IS NULL

编辑:按照 Docs

Oracle Database currently treats a character value with a length of zero as null. However, this may not continue to be true in future releases, and Oracle recommends that you do not treat empty strings the same as nulls.

关于sql - 具有空字符串的Oracle NVL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26274750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com