Reputation: 19
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
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