how to implement If statement in the select statement

We can implement the if statement in the select statement by using the Decode statement.

Example

     SELECT DECODE (EMP_CAT,'1','First','2','Second'Null);

Here the Null is the else statement where null is done . Here DECODE implement below IF – ELSE logic

                     IF EMP_CAT = ‘1’ THEN
                                  ‘FIRST’ 
                     ELSIF EMP_CAT = ‘2’ THEN
                                  ‘SECOND’
                     ELSE
                                   NULL
                     END IF;

No comments:

Post a Comment