Informatica中decode与嵌套iif表达式结果异常问题求助
问题根因
- DECODE语法使用错误:你编写的DECODE表达式在每个条件返回值后额外添加了
'close',导致第一个条件不匹配时直接返回close,后续testdoor2、testdoor3的判断逻辑完全不会执行。 - NULL值比较逻辑错误:当
testdoor1、testdoor2为NULL时,使用=做等值判断永远返回假,需要搭配ISNULL函数处理空值场景。
修正后的DECODE实现
正确写法如下,仅当所有匹配条件都不满足时才返回默认值close:
DECODE( TRUE, NOT ISNULL(testdoor1) AND testopen = testdoor1, 'open', NOT ISNULL(testdoor2) AND testopen = testdoor2, 'open', NOT ISNULL(testdoor3) AND testopen = testdoor3, 'open', 'close' )
三条件嵌套IIF实现
嵌套IIF按优先级依次判断,全部不匹配时返回noequal:
IIF( NOT ISNULL(testdoor1) AND testopen = testdoor1, 'equal', IIF( NOT ISNULL(testdoor2) AND testopen = testdoor2, 'equal', IIF( NOT ISNULL(testdoor3) AND testopen = testdoor3, 'equal', 'noequal' ) ) )
内容的提问来源于stack exchange,提问作者Frederica
相关产品推荐
相关产品推荐

