oracle decode函数 和 case when

1.oracle decode分支函数 

1 select decode(to_char(B.LQSJ, 'hh24:mi:ss'),
2               '00:00:00',
3               to_char(B.LQSJ, 'yyyy-mm-dd') || ' ' || '01:01:01',
4               to_char(B.LQSJ, 'yyyy-mm-dd hh24:mi:ss'))
5   from pcxx b

 相当于

1   select decode('表达式', '如果A', '则A', '如果B', '则B', '其他')

2. case when then end case 也能完成这个操作

1 select case to_char(B.LQSJ, 'hh24:mi:ss')
2          when '00:00:00' then
3           to_char(B.LQSJ, 'yyyy-mm-dd') || ' ' || '01:01:01'
4          else
5           to_char(B.LQSJ, 'yyyy-mm-dd hh24:mi:ss')
6        end case
7   from pcxx b

相当于

 select  case'表达式' when 'A' then 'A1' when 'B' then 'B1' else end case 
原文地址:https://www.cnblogs.com/wzalex/p/3556469.html