Parthiban D
Parthiban D

Reputation: 19

How to Use If statement inside select in oracle 12c

Unable to use if statement inside Select in Oracle 12c

SELECT if(2 * 5 = 10, '1', null) AS a 
  FROM DUAL;

Upvotes: 0

Views: 12682

Answers (1)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186708

Try using case:

 SELECT CASE 
          WHEN 2 * 5 = 10 THEN '1' -- put the right condition here
          ELSE null
        END AS a 
   FROM DUAL;

Another possibility is Decode:

 SELECT Decode(2 * 5, 10, '1', null) AS a
   FROM DUAL; 

Please, note that IF ... THEN ... ELSE ... END IF syntax is PL/SQL, not SQL one.

Upvotes: 6

Related Questions