SQL语句 select from where中可否嵌入if条件语句?

如题所述

不可以,可以用case when选择语句,但是case when只能返回标量值类型,不能完全像if那样使用
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-12
可以使用 case when 这个,但不能加入if。
if是控制语句,不是SQL语句。
第2个回答  2013-10-12
select语句中只能使用case when then来判断,然后where条件中直接使用or and就可以区分了啊。
其实select的时候如果只是单纯的判断是否为空什么的,很多函数都可以解决,比如nvl,nvl2追问

or就解决了!谢谢

本回答被提问者采纳
第3个回答  2013-10-12
可以使用case when,不能用if,如:
select case when 列1 = 'a' then 'A'
when 列1 = 'b' then 'B'
when 列1 = 'c' then 'C'
end
from 表