oracle 中where后面加case when

木一浪 2019-09-06 06:39:02
select name from student where age = (case when sex is not null then '15' end) 当sex=null时,结果是什么样的
...全文
1459 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rotel-刘志东 2019-09-08
  • 打赏
  • 举报
回复
SELECT name FROM student WHERE age=(CASE WHEN sex is not null THEN '15' ELSE null END)
stelf 2019-09-06
  • 打赏
  • 举报
回复
nvl2(sex, '15', null)
卖水果的net 2019-09-06
  • 打赏
  • 举报
回复
(case when sex is not null then '15' end) 等价于 (case when sex is not null then '15' else null end)
AHUA1001 2019-09-06
  • 打赏
  • 举报
回复
当sex=null时,什么都查询不到。 原理很简单,当sex=null时,就是 select case when null is not null then '15' end from dual ; 返回结果是null select name from student where age = null 这个语句什么都查询不到。

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧