您的位置:首页 > 数据库 > Oracle

oracle decode函数 和 case when

2014-02-19 19:06 316 查看
1.oracle decode分支函数

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


相当于

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


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

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


相当于

select  case'表达式' when 'A' then 'A1' when 'B' then 'B1' else end case
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: