Standard SQL alternative to Oracle DECODE

后端 未结 4 2047
一个人的身影
一个人的身影 2021-01-02 10:58

Is there an ANSI SQL equivalent to Oracle\'s DECODE function?

Oracle\'s decode function is the IF-THEN-ELSE construct in SQL.

4条回答
  •  生来不讨喜
    2021-01-02 11:13

    Please note that Oracle DECODE treats null as equal to null, while CASE(and any other comparisons) don't.

    Example: Decode(a,b,1,0) will return 1 if both a and b are nulls.

    Just run these 2 statements to see the difference.

    select case null when null then 'Y' else 'N' end dd from dual;
    select decode(null, null, 'Y', 'N') dd from dual;
    

提交回复
热议问题