What is difference between Decode and Case

 

  • Decode is function while Case is Statement.
  • Case cannot process null while decode can process null.
  • Case is an ANSI standard where as Decode is Oracle proprietary.
 
SELECT
       DECODE(grade,'A','Distinction',
                    'B','First Class',
                    'C','Second Class',
                    'D','Failed',
                    'Failed') Per_Grade
  FROM grade;
 

SELECT
       CASE grade
         WHEN 'A' then 'Distinction'
         WHEN 'B' then 'First Class'
         WHEN 'C' then 'Second Class'
         WHEN 'D' then 'Failed'
         Else 'No Grade'
       END Per_Grade
  FROM Grade;

No comments:

Post a Comment