ORACLE IIF 声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14791684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORACLE IIF Statement
提问by user1050619
I get an error while writing the IIF stamtement, table and the statement given below,
我在编写 IIF 声明、表格和下面给出的语句时出错,
Statement:
陈述:
SELECT IIF(EMP_ID=1,'True','False') from Employee;
Error: 00907-missing right parantheses
错误:00907-缺少右括号
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)
)
Please provide your inputs.
请提供您的意见。
回答by Mt. Schneiders
回答by Rob van Wijk
Two other alternatives:
另外两种选择:
a combination of
NULLIF
andNVL2
. You can only use this ifemp_id
isNOT NULL
, which it is in your case:select nvl2(nullif(emp_id,1),'False','True') from employee;
simple
CASE
expression(Mt. Schneiders used a so-called searchedCASE
expression)select case emp_id when 1 then 'True' else 'False' end from employee;
回答by Kaushik Nayak
In PL/SQL, there is a trick to use the undocumented OWA_UTIL.ITE
function.
在 PL/SQL 中,有一个使用未记录OWA_UTIL.ITE
函数的技巧。
SET SERVEROUTPUT ON
DECLARE
x VARCHAR2(10);
BEGIN
x := owa_util.ite('a' = 'b','T','F');
dbms_output.put_line(x);
END;
/
F
PL/SQL procedure successfully completed.