CASE vs. DECODE

前端 未结 7 1189
小蘑菇
小蘑菇 2020-11-28 09:04

Referring to a previous question, i was wondering if its always possible to replace DECODE by CASE and which one is better for performance?

7条回答
  •  抹茶落季
    2020-11-28 09:52

    An old thread, I know but another interesting comparison between CASE and DECODE... pick your poison.

    SELECT CASE 1 WHEN '1' THEN 'A' ELSE 2 END result 
    
    FROM DUAL 
    
    /*
    ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
    00932. 00000 -  "inconsistent datatypes: expected %s got %s"
    */
    
    ;
    
    SELECT DECODE(1, '1', 'A', 2) result
    
    FROM DUAL
    
    /*
    A
    */
    
    ;
    

提交回复
热议问题