oracle菜鸟学习之 select case when的使用
发表于:2025-11-08 作者:千家信息网编辑
千家信息网最后更新 2025年11月08日,[toc]oracle菜鸟学习之 select case when的使用格式语法case when 条件1 then action1 when 条件2 then action2 wh
千家信息网最后更新 2025年11月08日oracle菜鸟学习之 select case when的使用
[toc]
oracle菜鸟学习之 select case when的使用
格式语法
case when 条件1 then action1 when 条件2 then action2 when 条件3 then action3 when 条件N then actionN else actionend例子
判断现在是几月
SQL> select case substr('20181118',5,2) 2 when '08' then '8yue' 3 when '09' then '9yue' 4 when '10' then '10yue' 5 when '11' then '11yue' 6 when '12' then '12yue' 7 else 'other' 8 end 9 from dual;CASESUBSTR('201---------------11yueSQL> 扩展知识:substr 截取
sbustr('str',x,y)
str:字符串
x:从x位开始
y:x位的后y位结束
SQL> select substr('123456',3,2) from dual;SUBSTR------34SQL> 实验
实验表如下:
sno:学号
km:科目
score:成绩
grade:等级
create table score(sno number,km varchar2(8),score int,grade varchar2(4) default null);insert into score(sno,km,score) values(1,'yw',65);insert into score(sno,km,score) values(2,'sx',76);insert into score(sno,km,score) values(3,'yw',86);insert into score(sno,km,score) values(4,'yw',94);查看表
SQL> select * from score; SNO KM SCORE GRADE---------- ------------------------ ---------- ------------ 1 yw 65 2 sx 76 3 yw 86 4 yw 94问题:给学生成绩分等级,优秀、良好、中等、合格
思路:先查询学号对应的成绩
SQL> select sno,case 2 when score >=90 then 'A' 3 when score >=80 then 'B' 4 when score >=70 then 'C' 5 when score >=60 then 'D' 6 else 'F' 7 end 8 from score; SNO CAS---------- --- 1 D 2 C 3 B 4 A思路:怎么将等级插入表格?
update score set grade = ?思路:选出等级的值
select grade from(select sno,case when score >=90 then 'A' when score >=80 then 'B' when score >=70 then 'C' when score >=60 then 'D' else 'F' end as grade 9 from score);GRADE----------DCBA思路:grade不能等于一个集合,只能等于某个值,怎么选出某个值?
从图中可以看出,如果我把第一个表取别名为a,但a.sno和score.sno相等的时候,grade的值唯一
update score set grade = (select grade from(select sno,case when score >=90 then 'A' when score >=80 then 'B' when score >=70 then 'C' when score >=60 then 'D' else 'F' end as grade from score) a where a.sno=score.sno );4 rows updated.查看更新之后的表
SQL> select * from score; SNO KM SCORE GRADE---------- ------------------------ ---------- ---------- 1 yw 65 D 2 sx 76 C 3 yw 86 B 4 yw 94 A
思路
条件
成绩
等级
学号
选出
实验
习之
菜鸟
优秀
良好
例子
字符
字符串
学生
时候
格式
知识
科目
表格
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
郑州dell服务器
中职网络安全主题班会教案
数据库能存list
小区宽带用哪些服务器
网络安全mtd是什么意思
上海网络技术服务电话多少
100台服务器怎么部署vrm
不属于数据库的范式
静安区智能软件开发管理
怎么防止网络安全诱导支付
高职网络技术教案.doc
移动联通电信的服务器是华为的吗
指静脉技术设备中有数据库么
网络安全清查通知
如何加强结合部网络安全管理
洛奇英雄传 服务器
绿联打印共享服务器支持打印机
数据库导出excel的数值
以下关于数据库模式描述错误的是
电力行业网络安全事故预想
哪些网页可以查国家数据库
消防网络技术公司 招聘
unity软件开发面试
微信数据库修复是怎么回事
打开本地服务器
手机指纹软件开发公司
河北pdu服务器电源生产公司
网络安全产品原厂续保
网络安全微小说
白云专业网络安全运维