没有合适的资源?快使用搜索试试~ 我知道了~
首页oracle最全函数大全
oracle最全函数大全
4星 · 超过85%的资源 需积分: 41 89 下载量 156 浏览量
更新于2023-03-16
评论 5
收藏 106KB DOCX 举报
oracle最全函数大全(分析函数-聚合函数-转换函数-日期型函数-字符型函数-数值型函数-其他函数
资源详情
资源评论
资源推荐
oracle 函数大全
(分析函数,聚合函数,转换函数,日期型函数,字符型函数,数值型函数,其他函数)
oracle 函数大全.......................................................................................................................1
oracle 分析函数--SQL*PLUS 环境............................................................................................1
oracle 10g 函数大全--聚合函数.............................................................................................20
oracle 10g 函数大全--转换函数.............................................................................................26
oracle 10g 函数大全--日期型函数.........................................................................................49
oracle 10g 函数大全--字符型函数.........................................................................................58
oracle 10g 函数大全--数值型函数.........................................................................................73
oracle 10g 函数大全--其他函数.............................................................................................78
oracle 分析函数--SQL*PLUS 环境
一、总体介绍
1.1. 分析函数如何工作
语法 FUNCTION_NAME(<参数>,…) OVER (<PARTITION BY 表达式,…> <ORDER BY
表达式 <ASC DESC> <NULLS FIRST NULLS LAST>> <WINDOWING 子句>)
PARTITION 子句 ORDER BY 子句 WINDOWING 子句 缺省时相当于 RANGE UNBOUNDED
PRECEDING
1. 值域窗(RANGE WINDOW)
RANGE N PRECEDING 仅对数值或日期类型有效,选定窗为排序后当前行之前,某列(即
排序列)值大于/小于(当前行该列值 –/+ N)的所有行,因此与 ORDER BY 子句有关系。
2. 行窗(ROW WINDOW)
ROWS N PRECEDING 选定窗为当前行及之前 N 行。
还可以加上 BETWEEN AND 形式,例如 RANGE BETWEEN m PRECEDING AND n
FOLLOWING
函数 AVG(<distinct all> eXPr)
一组或选定窗中表达式的平均值 CORR(expr, expr) 即 COVAR_POP(exp1,exp2) /
(STDDEV_POP(expr1) * STDDEV_POP(expr2)),两个表达式的互相关,-1(反相关)
~ 1(正相关),0 表示不相关
COUNT(<distinct> <*> <expr>) 计数
COVAR_POP(expr, expr) 总体协方差
COVAR_SAMP(expr, expr) 样本协方差
CUME_DIST 累积分布,即行在组中的相对位置,返回 0 ~ 1
DENSE_RANK 行的相对排序(与 ORDER BY 搭配),相同的值具有一样的序数(NULL 计为
相同),并不留空序数
FIRST_VALUE 一个组的第一个值
LAG(expr, <offset>, <default>) 访问之前的行,OFFSET 是缺省为 1 的正数,表
示相对行数,DEFAULT 是当超出选定窗范围时的返回值(如第一行不存在之前行)
LAST_VALUE 一个组的最后一个值
LEAD(expr, <offset>, <default>) 访问之后的行,OFFSET 是缺省为 1 的正数,
表示相对行数,DEFAULT 是当超出选定窗范围时的返回值(如最后行不存在之前行)
MAX(expr) 最大值
MIN(expr) 最小值
NTILE(expr) 按表达式的值和行在组中的位置编号,如表达式为 4,则组分 4 份,分别为
1 ~ 4 的值,而不能等分则多出的部分在值最小的那组
PERCENT_RANK 类似 CUME_DIST,1/(行的序数 - 1)
RANK 相对序数,答应并列,并空出随后序号
RATIO_TO_REPORT(expr) 表达式值 / SUM(表达式值)
ROW_NUMBER 排序的组中行的偏移
STDDEV(expr) 标准差
STDDEV_POP(expr) 总体标准差
STDDEV_SAMP(expr) 样本标准差
SUM(expr) 合计
VAR_POP(expr) 总体方差
VAR_SAMP(expr) 样本方差
VARIANCE(expr) 方差
REGR_ xxxx(expr, expr) 线性回归函数
REGR_SLOPE:返回斜率,等于 COVAR_POP(expr1, expr2) / VAR_POP(expr2)
REGR_INTERCEPT:返回回归线的 y 截距,等于
AVG(expr1) - REGR_SLOPE(expr1, expr2) * AVG(expr2)
REGR_COUNT:返回用于填充回归线的非空数字对的数目
REGR_R2:返回回归线的决定系数,计算式为:
If VAR_POP(expr2) = 0 then return NULL
If VAR_POP(expr1) = 0 and VAR_POP(expr2) != 0 then return 1
If VAR_POP(expr1) > 0 and VAR_POP(expr2 != 0 then
return POWER(CORR(expr1,expr),2)
REGR_AVGX:计算回归线的自变量(expr2)的平均值,去掉了空对(expr1, expr2)后,
等于 AVG(expr2)
REGR_AVGY:计算回归线的应变量(expr1)的平均值,去掉了空对(expr1, expr2)后,
等于 AVG(expr1)
REGR_SXX: 返回值等于 REGR_COUNT(expr1, expr2) * VAR_POP(expr2)
REGR_SYY: 返回值等于 REGR_COUNT(expr1, expr2) * VAR_POP(expr1)
REGR_SXY: 返回值等于 REGR_COUNT(expr1, expr2) * COVAR_POP(expr1,
expr2)
首先:创建表及接入测试数据
create table students
(id number(15,0),
area varchar2(10),
stu_type varchar2(2),
score number(20,2));
insert into students values(1, '111', 'g', 80 );
insert into students values(1, '111', 'j', 80 );
insert into students values(1, '222', 'g', 89 );
insert into students values(1, '222', 'g', 68 );
insert into students values(2, '111', 'g', 80 );
insert into students values(2, '111', 'j', 70 );
insert into students values(2, '222', 'g', 60 );
insert into students values(2, '222', 'j', 65 );
insert into students values(3, '111', 'g', 75 );
insert into students values(3, '111', 'j', 58 );
insert into students values(3, '222', 'g', 58 );
insert into students values(3, '222', 'j', 90 );
insert into students values(4, '111', 'g', 89 );
insert into students values(4, '111', 'j', 90 );
insert into students values(4, '222', 'g', 90 );
insert into students values(4, '222', 'j', 89 );
commit;
二、具体应用:
1、分组求和:
1.2. GROUP BY 子句
1.2.1. GROUPING SETS
select id,area,stu_type,sum(score) score
from students
group by grouping sets((id,area,stu_type),(id,area),id)
order by id,area,stu_type;
/*--------理解 grouping sets
select a, b, c, sum( d ) from t
group by grouping sets ( a, b, c )
等效于
select * from (
select a, null, null, sum( d ) from t group by a
union all
select null, b, null, sum( d ) from t group by b
union all
select null, null, c, sum( d ) from t group by c
)
*/
1.2.2. ROLLUP
select id,area,stu_type,sum(score) score
from students
group by rollup(id,area,stu_type)
order by id,area,stu_type;
1.2.3. rollup
select a, b, c, sum( d )
from t
group by rollup(a, b, c);
等效于
select * from (
select a, b, c, sum( d ) from t group by a, b, c
union all
select a, b, null, sum( d ) from t group by a, b
union all
select a, null, null, sum( d ) from t group by a
union all
select null, null, null, sum( d ) from t
)
*/
1.2.4. CUBE
select id,area,stu_type,sum(score) score
from students
group by cube(id,area,stu_type)
order by id,area,stu_type;
/*--------理解 cube
select a, b, c, sum( d ) from t
group by cube( a, b, c)
等效于
select a, b, c, sum( d ) from t
group by grouping sets(
( a, b, c ),
( a, b ), ( a ), ( b, c ),
( b ), ( a, c ), ( c ),
() )
*/
1.2.5. GROUPING
/*从上面的结果中我们很容易发现,每个统计数据所对应的行都会出现 null,
如何来区分到底是根据那个字段做的汇总呢,grouping 函数判断是否合计列!*/
select decode(grouping(id),1,'all id',id) id,
decode(grouping(area),1,'all area',to_char(area)) area,
decode(grouping(stu_type),1,'all_stu_type',stu_type) stu_type,
sum(score) score
剩余63页未读,继续阅读
_漫不经心
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2