Oracle Decode and CASE Sample
create table testabc(
a Number,
b Date
);
insert into testabc(a,b) values(1, TO_DATE(1-MAY-2010/00:00, DD-MON-YYYY/HH24:MI));
insert into testabc(a,b) values(1, TO_DATE(2-MAY-2010/00:00, DD-MON-YYYY/HH24:MI));
insert into testabc(a,b) values(1, TO_DATE(3-MAY-2010/00:00, DD-MON-YYYY/HH24:MI));
insert into testabc(a,b) values(1, TO_DATE(4-MAY-2010/00:00, DD-MON-YYYY/HH24:MI));
insert into testabc(a,b) values(1, TO_DATE(5-MAY-2010/00:00, DD-MON-YYYY/HH24:MI));
insert into testabc(a,b) values(1, TO_DATE(6-MAY-2010/00:00, DD-MON-YYYY/HH24:MI));
select a,b,decode(sign(b - TO_DATE(3-MAY-2010/00:00, DD-MON-YYYY/HH24:MI)), -1, his, 1, cur, his) as type from testabc;
select a,b,case when b <= TO_DATE(3-MAY-2010/00:00, DD-MON-YYYY/HH24:MI) then his else cur end type from testabc;
drop table testabc;
In theory, case when will have a better performance.
相关新闻>>
- 发表评论
-
- 最新评论 更多>>