You're welcome!类似的还有一个NVL(field_name,other_value)
if value of field_name is null then
return value
else
return value of field_name
end if;
if value of field_name is null then
return value
else
return value of field_name
end if;
return other_value
else
return value of field_name
end if;
E:\oracle\ora92\database>sqlplus /nologSQL*Plus: Release 9.2.0.1.0 - Production on 星期五 1月 25 11:22:16 2002Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.SQL> conn lunar/lunar
已连接。
SQL> create table testcase
2 (a char(6),
3 b number(10),
4 c char(9),
5 d number(10,2),
6 e char(20));表已创建。SQL> insert into testcase values('aa',110,'你好',100.2,'abc');已创建 1 行。SQL> insert into testcase values('bb',200,'大家好',120.25,'abcde');已创建 1 行。SQL> insert into testcase values('cc',150,'和平',50.9,'xyz');已创建 1 行。SQL> insert into testcase values('dd',170,'和平',200,'rst');已创建 1 行。SQL> insert into testcase values('ee',10,'公安部',21,'morning');已创建 1 行。SQL> commit;提交完成。SQL> select * from testcase;A B C D E
------ ---------- --------- ---------- --------------------
aa 110 你好 100.2 abc
bb 200 大家好 120.25 abcde
cc 150 和平 50.9 xyz
dd 170 和平 200 rst
ee 10 公安部 21 morningSQL> select a,b,(case when b>150 then '大于150'
2 when b=150 then '等于150'
3 when b<150 then '小于150'
4 else '输入错误'
5 end) as c, d,e
6 from testcase
7 /A B C D E
------ ---------- -------- ---------- --------------------
aa 110 小于150 100.2 abc
bb 200 大于150 120.25 abcde
cc 150 等于150 50.9 xyz
dd 170 大于150 200 rst
ee 10 小于150 21 morningSQL>