日期:2014-05-16 浏览次数:20389 次
条件表达式 :IF-THEN-ELSE 逻辑
CASE expr WHEN comparison_expr1 THEN return_expr1
???????? [WHEN comparison_expr2 THEN return_expr2
????????? WHEN comparison_exprn THEN return_exprn
????????? ELSE else_expr]
END
?
DECODE(col|expression, search1, result1
????? ?????????? ???[, search2, result2,...,]
????? ?????????? ???[, default])
?
//为职位是Manager的员工发放5000元的奖金
SQL> select ename,job,case job when 'MANAGER' then nvl(sal,0)+5000? end? as "工资" from emp;
//员工的工资
SQL> select ename ,job,
? 2? case job when 'MANAGER' then nvl(sal,0)+5000+nvl(comm,0)
? 3? else nvl(sal,0)+nvl(comm,0)
? 4? end
? 5? from emp;
//改写成 decode的写法
SQL> select ename,job
? 2? ,decode(job,'MANAGER', nvl(sal,0)+5000+nvl(comm,0),