Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

conditional operator - ORACLE IIF Statement

I get an error while writing the IIF statement, table and the statement given below.

Statement:

SELECT IIF(EMP_ID=1,'True','False') from Employee;

Table:

CREATE TABLE SCOTT.EMPLOYEE
(
   EMP_ID       INTEGER                          NOT NULL,
   EMP_FNAME    VARCHAR2(30 BYTE)                NOT NULL,
   EMP_LNAME    VARCHAR2(30 BYTE)                NOT NULL,
   EMP_ADDRESS  VARCHAR2(50 BYTE)                NOT NULL,
   EMP_PHONE    CHAR(10 BYTE)                    NOT NULL,
   EMP_GENDER   CHAR(1 BYTE)
)

Error:

00907-missing right parantheses

Please provide your inputs.

question from:https://stackoverflow.com/questions/14791684/oracle-iif-statement

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Oracle doesn't provide such IIF Function. Instead, try using one of the following alternatives:

DECODE Function:

SELECT DECODE(EMP_ID, 1, 'True', 'False') from Employee

CASE Function:

SELECT CASE WHEN EMP_ID = 1 THEN 'True' ELSE 'False' END from Employee

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...