教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

oracle常用函数总结(2)

来源:网络收集 时间:2026-08-12
导读: month10 number(10,2) --10月销售金额 month11 number(10,2) --11月销售金额 month12 number(10,2) --12月销售金额 结构转化的SQL语句为: create or replace view v_sale(year,month1,month2,month3,month4,month5,

month10 number(10,2) --10月销售金额 month11 number(10,2) --11月销售金额 month12 number(10,2) --12月销售金额

结构转化的SQL语句为: create or replace view

v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12) as select

substrb(month,1,4),

sum(decode(substrb(month,5,2),'01',sell,0)), sum(decode(substrb(month,5,2),'02',sell,0)), sum(decode(substrb(month,5,2),'03',sell,0)), sum(decode(substrb(month,5,2),'04',sell,0)),

补充1:

有学生成绩表student,现在要用decode函数实现以下几个功能:成绩>85,显示优秀;>70显示良好;>60及格;否则是不及格。 假设student的编号为id,成绩为score,那么:

select id, decode(sign(score-85),1,'优秀',0,'优秀',-1, decode(sign(score-70),1,'良好',0,'良好',-1,

decode(sign(score-60),1,'及格',0,'及格',-1,'不及格'))) from student;

补充2:

Decode函数的语法结构如下:

decode (expression, search_1, result_1)

decode (expression, search_1, result_1, search_2, result_2)

decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n) decode (expression, search_1, result_1, default)

decode (expression, search_1, result_1, search_2, result_2, default)

decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n, default)

decode函数比较表达式和搜索字,如果匹配,返回结果;如果不匹配,返回default值;如果未定义default值,则返回空值。

以下是一个简单测试,用于说明Decode函数的用法:

SQL> create table t as select username,default_tablespace,lock_date from dba_users; Table created.

SQL> select * from t;

USERNAME DEFAULT_TABLESPACE

LOCK_DATE

------------------------------ ------------------------------ --------- SYS SYSTEM SYSTEM SYSTEM OUTLN SYSTEM CSMIG SYSTEM SCOTT SYSTEM EYGLE USERS DBSNMP SYSTEM

WMSYS SYSTEM 20-OCT-04

8 rows selected.

SQL> select username,decode(lock_date,null,'unlocked','locked') status from t; USERNAME STATUS ------------------------------ --------

SYS unlocked SYSTEM unlocked OUTLN unlocked CSMIG unlocked SCOTT unlocked EYGLE unlocked DBSNMP unlocked WMSYS locked 8 rows selected.

SQL> select username,decode(lock_date,null,'unlocked') status from t; USERNAME STATUS ------------------------------ --------

oracle常用函数总结(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/592305.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)