NVL
判断是否为空:
NVL(exp1,exp2) 如果exp1为空 则返回exp2 否则 返回 exp1
NVL2(exp1,exp2,exp3) 如果exp1为空 则返回 exp2,否则返回exp3
NULLIF(exp1,exp2) 如果exp1=exp2返回null 否则返回exp1
decode(exp1,exp2,exp3,exp4,exp5); 如果exp1=exp2返回exp3 如果等于exp4返回exp5
sign(exp1); 返回-1 0 1
case exp1
when exp2 then
exp3
when exp3 then
exp4
case
when exp1 then exp2
when exp3 then exp4
下面 举例说明吧:
NVL
SQL> select * from stu;
ID NAME
--------------------------------------- --------------------
1
2 fa
SQL> select nvl(name,'空')as 姓名 from stu;
姓名
--------------------
空
fa
ID NAME
--------------------------------------- --------------------
1
2 fa
SQL> select nvl(name,'空')as 姓名 from stu;
姓名
--------------------
空
fa
NVL2
SQL> SELECT NVL2(NAME,'不为空','空') from stu;
NVL2(NAME,'不为空','空')
------------------------
空
不为空
SQL>
NVL2(NAME,'不为空','空')
------------------------
空
不为空
SQL>
NULLIF
SQL> SELECT NULLIF(id,1) from stu;
NULLIF(ID,1)
------------
2
第二条记录是1则返回空
NULLIF(ID,1)
------------
2
第二条记录是1则返回空
decode:
SQL> select decode(id,1,'一',2,'二') as ID号 from stu;
ID号
----
一
二
ID号
----
一
二
sign:
SQL> select sign(3) from dual;
SIGN(3)
----------
1
SQL> select sign(0) from dual;
SIGN(0)
----------
0
SQL> select sign(-1) from dual;
SIGN(-1)
----------
-1
case:
SIGN(3)
----------
1
SQL> select sign(0) from dual;
SIGN(0)
----------
0
SQL> select sign(-1) from dual;
SIGN(-1)
----------
-1
case:
SQL> select (case id when 1 then '一' when 2 then '二' end) from stu;
(CASEIDWHEN1THEN'一'WHEN2THEN'
------------------------------
一
(CASEIDWHEN1THEN'一'WHEN2THEN'
------------------------------
一