1. 程式人生 > >Oracle中case when函式和decode函式

Oracle中case when函式和decode函式

1、case when函式:

select ename,case deptno 
  when 10 then 'ACCOUNTING' 
  when 20 then 'RESEARCH' 
  else 'SALES' end from emp;
    
select ename,case  
when deptno=10 then 'ACCOUNTING' 
  when deptno=20 then 'RESEARCH' 
    else 'SALES' end from emp;

以上兩種寫法均可。

2、decode函式:

select ename,decode(deptno,10,'ACCOUNTING',20,'RESEARCH',30,'SALES','OTHERS') from emp;