下面例子使用的是oracle自带的emp表
decode使用方法如下:
DECODE(col|expression, search1, result1
[, search2, result2,...,]
[, searchn, resultn,...,]
[, default])
例子:
select comm,decode(comm,0,'很低' ,300,'低', 1400,'高', '一般')"testdecode" from emp;
case when使用方法如下:
CASE expr WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THEN return_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
例子:
select comm,( case when comm=0 then '很低' when comm=300 then '低' when comm=1400 then '高' else '一般' end)"testcase" from emp;
这两种方式都能得到如下结果:
COMM testcase
---------------------- --------
一般
300 低
500 一般
一般
1400 高
一般
一般
一般
一般
0 很低
一般
一般
一般
一般