Oracle,char(3) 变量缺失值似乎不为 null 也不等于 ''
我有一个表,从中我得到了这个计数,它突出显示了缺失值的存在:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论