首页 > 数据库技术 > 详细

Oracle的sql语句中case关键字的用法

时间:2016-12-21 20:43:59      阅读:341      评论:0      收藏:0      [点我收藏+]

例子1:

a)查询列中有"_"开头的列名时,需要用双引号引起来。

b)使用"case"关键字,根据分数直接判断是否及格。

create table tbl_score(
    id NUMBER(4), --id
    name varchar2(30), --名称
    score NUMBER(3), --分数
    otherscore NUMBER(3) --其他分数
);
select t.id as "_id",
       t.name as name,
       case
           when t.score >= 60 then
            ‘及格
           else
            不及格
       end as ‘是否及格‘,
       t.score as ‘分数‘ 
from tbl_score t;

 

例子2:

根据情况返回不同列的值。

同用上面的tbl_score表。

select t.id as "_id",
       t.name as name,
       case
           when t.score is null then
            t.otherscore  --也可返回固定值
           else
            t.score
       end as 分数
  from tbl_score t;

 

Oracle的sql语句中case关键字的用法

原文:http://www.cnblogs.com/zj0208/p/6208692.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!