select status_a,status_b from test
如何解码status_a
,status_b
如果 status_a 或 status_b 的值之一为 null,则使用 oracle 解码函数 a 下面的值。
if status_a='Y' and status_b='Y' then 'Y'
if status_a='Y' and status_b='N' then 'N'
if status_a='N' and status_b='Y' then 'N'
if status_a='N' and status_b='N' then 'N'
Regards,
柴图哈拉
你为什么要使用DECODE
? CASE
看起来更合适
CASE WHEN status_a = 'Y' and status_b = 'Y' THEN 'Y'
WHEN status_a = 'Y' and status_b = 'N' THEN 'N'
WHEN status_a = 'N' and status_b = 'Y' THEN 'N'
WHEN status_a = 'N' and status_b = 'N' THEN 'N'
END
当然,您发布的逻辑似乎没有道理。唯一的办法就是status_a = 'Y' or status_b = 'Y'
将评估为 FALSE 而status_a = 'Y' or status_b = 'N'
评估为 TRUE 将是如果status_a = 'N'
and status_b = 'N'
。但这意味着第三和第四分支将永远无法到达。如果你的意思是and
而不是or
,逻辑就说得通了。但在这种情况下,你可以将其简化为
CASE WHEN status_a = 'Y' and status_b = 'Y' THEN 'Y'
ELSE 'N'
END
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)