oracle case语句当x为null时,else返回null

3hvapo4f  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(330)

我写了一个简单的案例陈述如下:

case when col_name is null then 'NO' else 'YES' end as col_name

但我仍然得到(null)而不是“no”?有什么想法吗?
我试过以下方法,但仍然没有成功:

case when isnull(col_name, 0) = 0 then 'NO' else 'YES' end as col_name

我也试过:

case when nvl(col_name, 0) = 0 then 'NO' else 'YES' end end as col_name

我知道null永远不等于null—null表示没有值。null也永远不等于null。
整个查询如下所示:

Select 

t1.col_a,
t1.col_b,
t1.col_c,
.
.
t2.col_a
t2.col_b

from table_1 t1
 left join table_2 t2 
  on t1.col_a = t2.col_a

 left join
 (select distinct

  case when t3.col_name is null then 'NO' else 'YES' end as col_name,
  t3.col_a,
  t3.col_b,
  t3.col_c) ABC

on abc.col_a = t2.col_a
a2mppw5e

a2mppw5e1#

这个 LEFT JOIN 他回来了 NULL ,而不是 CASE . 返回列名并执行 case 最外层查询中的逻辑:

select . . . ,
       (case when t2.column_name is null then 'NO' else 'YES' end)

相关问题