【问题标题】:Syntax error at expression level in InformaticaInformatica 中表达式级别的语法错误
【发布时间】:2022-01-09 14:50:45
【问题描述】:

我有一个需要实现的关键逻辑,但不知道如何在 Informatica 中的表达式级别编写 if logic

我的逻辑:

if (empid =='SBCS'):
then

    empcd = v_employee_code_number

elif empcal <> depcal and empid in ('SSC','HSC'):
then
 
    empcd = (emp_sal/avgsal) * empad

elif empcal <> depcal and empid not in ('SSC','HSC'):
then
    
    empcd = emp_del

else:
    
   empcd = emp_dev

我需要在 Informatica 甚至 SQL 查询中编写表达式级别的上述逻辑?

我尝试过以下逻辑。它在表达式中抛出语法错误

iif( empid =='SBCS',v_employee_code_number,iif(empcal <> depcal and empid in ('SSC','HSC')),(emp_sal/avgsal) * empad, empcal <> depcal and empid not in ('SSC','HSC'), emp_del,emp_dev)

上面需要用SQL写,但不知道怎么写

【问题讨论】:

  • 查看 SQL 参考指南。 "==" 不是 oracle 中的有效语法。

标签: sql oracle expression informatica


【解决方案1】:

用于您的逻辑的标准 SQL case 表达式(也适用于 Oracle)是:

empcd := case
  when empid = 'SBCS'
    then v_employee_code_number
  when empcal != depcal and empid in ('SSC','HSC')
    then (emp_sal/avgsal) * empad
  when empcal != depcal and empid not in ('SSC','HSC')
    then emp_del
  else emp_dev
end

【讨论】:

    【解决方案2】:

    如上所述,== 不是有效语法。也不支持in。我已将您的 iif 语句改写如下(请验证!)

    iif( empid ='SBCS',
        v_employee_code_number,
        iif(empcal <> depcal and (empid = 'SSC' or empid = 'HSC'),
            (emp_sal/avgsal) * empad, 
            iif(empcal <> depcal and empid <> 'SSC' and empid <> 'HSC',
            emp_del,
            emp_dev)
        )
    )
    

    但是嵌套的IIF 真的很难阅读,所以最好还是使用DECODE 函数(请参考the docs for details)。这看起来像:

    DECODE(TRUE,
        empid ='SBCS', v_employee_code_number,
        empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
        empcal <> depcal and empid <> 'SSC' and empid <> 'HSC', emp_del,
        emp_dev
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 2015-09-20
      相关资源
      最近更新 更多