Oracle,char(3) 变量缺失值似乎不为 null 也不等于 ''

发布于 2025-01-13 22:05:47 字数 621 浏览 4 评论 0原文

我有一个表,从中我得到了这个计数,它突出显示了缺失值的存在:

select tipo, count(*) from mytable group by tipo;
tipo | count(*)
-----+---------
010  | 100
020  | 200
NULL | 300

select * from mytable where tipo is null   ;
select * from mytable where tipo = ''      ;
select * from mytable where tipo like '% %';

所有值都返回空结果。 “tipo”是一个 char(3)。 这怎么可能?到底是怎么回事?

-- 编辑 --

只是为了清楚起见:以下内容返回预期结果。

select * from clabanche where cast(tipo_int as varchar2(3)) is null;

因此,现在我将该变量预转换为 varchar2 以规避该问题(正如 Thorsten 在评论中所建议的那样)。我想这是某种非常非常糟糕的错误......

I have a table from which I had this count which highlights the existence of missing values:

select tipo, count(*) from mytable group by tipo;
tipo | count(*)
-----+---------
010  | 100
020  | 200
NULL | 300

but

select * from mytable where tipo is null   ;
select * from mytable where tipo = ''      ;
select * from mytable where tipo like '% %';

all return an empty result. "tipo" is a char(3).
How is this possible? What is going on?

-- EDIT --

Just for clarity: the following instead returns the expected results.

select * from clabanche where cast(tipo_int as varchar2(3)) is null;

So for now I am pre-casting that variable as a varchar2 to circumvent the issue (as suggested by Thorsten in the comments). I guess this is some kind of bad, bad bug...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文