Search code examples
sqloracle-databasesql-updatecaseoracle-data-integrator

SQL case expression in UPDATE statement


I'm trying to map this particular SQL code for data warehousing purpose.

I have two columns (TARGET) and (NET_SALARY), purpose is to map NET_SALARY with 0 when TARGET is 700, in other cases sub-string net salary 1, 30

I'm receiving missing right parenthesis error

Both columns are varchar2 datatype

CASE 
  WHEN SRC_CUSTOMER.TARGET = '700' THEN SRC_CUSTOMER.NET_SALARY = '0'
  ELSE SUBSTR(SRC_CUSTOMER.NET_SALARY,1,30)
END

Solution

  • If this is in a context of an ODI mapping/interface, you can only use SQL and not PL/SQL. You can't assign the value to SRC_CUSTOMER.NET_SALARY in the first THEN. You actually only need to set the value you want and it will be mapped to your target attribute.

    Try with

    CASE 
      WHEN SRC_CUSTOMER.TARGET = '700' THEN '0'
      ELSE SUBSTR(SRC_CUSTOMER.NET_SALARY,1,30)
    END