我在 Oracle 过程中使用“where 0=0”这样的语句时有点困惑?有人可以澄清一下吗?即使我们这样做是为了动态选择,为什么即使我们在查询中附加了实际条件,也要添加这条语句呢?这个 where 条件会对结果集产生任何影响吗?...
我经历了如何选择列包含字符串的任何单词的所有行 https://stackoverflow.com/questions/10522345/how-can-i-select-all-rows-where-column-contain-any-words-of-a-string?
但我不太明白使用的原因where 0=0
。
有人能给我使用这种条件的正确理由吗?
We use 0 = 0
或者,通常,1 = 1
as a stub:
select *
from My_Table
where 1 = 1
因此,当您编写过滤器时,您可以通过添加/注释来完成单线:
-- 3 filters added
select *
from My_Table
where 1 = 1
and (Field1 > 123) -- 1st
and (Field2 = 456) -- 2nd
and (Field3 like '%test%') -- 3d
比如说,下一个版本将删除两个过滤器:
-- 3 filters added, 2 (1st and 3d) removed
select *
from My_Table
where 1 = 1
-- and (Field1 > 123) -- <- all you need is to comment out the corresponding lines
and (Field2 = 456)
-- and (Field3 like '%test%')
现在让我们以非常简单的方式恢复 3D 滤镜:
-- 3 filters added, 2 (1st and 3d) removed, then 3d is restored
select *
from My_Table
where 1 = 1
-- and (Field1 > 123)
and (Field2 = 456)
and (Field3 like '%test%') -- <- just uncomment
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)