oracle最全函数大全~(分析函数,聚合函数,转换函数,日期型函数,字符型函数,数值型函数,其他函数~).doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《oracle最全函数大全~(分析函数,聚合函数,转换函数,日期型函数,字符型函数,数值型函数,其他函数~).doc》由会员分享,可在线阅读,更多相关《oracle最全函数大全~(分析函数,聚合函数,转换函数,日期型函数,字符型函数,数值型函数,其他函数~).doc(70页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、|oracle函数大全(分析函数, 聚合函数 ,转换函数,日期型函数, 字符型函数,数值型函数,其他函数)oracle 函数大全 .1oracle 分析函数-SQL*PLUS 环境 .1oracle 10g 函数大全-聚合函数 .19oracle 10g 函数大全-转换函数 .23oracle 10g 函数大全-日期型函数 .40oracle 10g 函数大全-字符型函数 .45oracle 10g 函数大全-数值型函数 .55oracle 10g 函数大全-其他函数 .58oracle分析函数-SQL*PLUS 环境一、总体介绍1.1. 分析函数如何工作语法 FUNCTION_NAME(,)
2、 OVER ( ) 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
3、 AND n FOLLOWING 函数 AVG( eXPr) 一组或选定窗中表达式的平均值 CORR(expr, expr) 即 COVAR_POP(exp1,exp2) / (STDDEV_POP(expr1) * STDDEV_POP(expr2),两个表达式的互相关,-1(反相关) 1(正相关 ),0表示不相关 COUNT( ) 计数 COVAR_POP(expr, expr) 总体协方差 COVAR_SAMP(expr, expr) 样本协方差 |CUME_DIST 累积分布,即行在组中的相对位置 ,返回 0 1 DENSE_RANK 行的相对排序 (与 ORDER BY搭配), 相同
4、的值具有一样的序数(NULL 计为相同),并不留空序数 FIRST_VALUE 一个组的第一个值 LAG(expr, , ) 访问之前的行,OFFSET 是缺省为 1 的正数,表示相对行数,DEFAULT 是当超出选定窗范围时的返回值 (如第一行不存在之前行) LAST_VALUE 一个组的最后一个值 LEAD(expr, , ) 访问之后的行,OFFSET 是缺省为 1 的正数,表示相对行数,DEFAULT 是当超出选定窗范围时的返回值 (如最后行不存在之前行) MAX(expr) 最大值 MIN(expr) 最小值 NTILE(expr) 按表达式的值和行在组中的位置编号,如表达式为 4,
5、则组分 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_ x
6、xxx(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 NULLIf VAR_POP(expr1) = 0 and VAR_POP(expr2) != 0 the
7、n return 1If 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_
8、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 );
9、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,
10、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(
11、4, 222, j, 89 );commit;二、具体应用:1、分组求和:1.2. GROUP BY 子句 1.2.1. GROUPING SETSselect id,area,stu_type,sum(score) score from studentsgroup by grouping sets(id,area,stu_type),(id,area),id)order by id,area,stu_type;/*-理解 grouping setsselect a, b, c, sum( d ) from tgroup by grouping sets ( a, b, c )等效于|sele
12、ct * from (select a, null, null, sum( d ) from t group by aunion allselect null, b, null, sum( d ) from t group by b union allselect null, null, c, sum( d ) from t group by c )*/1.2.2. ROLLUPselect id,area,stu_type,sum(score) score from studentsgroup by rollup(id,area,stu_type)order by id,area,stu_t
13、ype;1.2.3. rollupselect a, b, c, sum( d )from tgroup by rollup(a, b, c);等效于select * from (select a, b, c, sum( d ) from t group by a, b, c union allselect a, b, null, sum( d ) from t group by a, bunion allselect a, null, null, sum( d ) from t group by aunion allselect null, null, null, sum( d ) from
14、 t)*/1.2.4. CUBE|select id,area,stu_type,sum(score) score from studentsgroup by cube(id,area,stu_type)order by id,area,stu_type;/*-理解 cubeselect a, b, c, sum( d ) from tgroup by cube( a, b, c)等效于select a, b, c, sum( d ) from tgroup by grouping sets( ( a, b, c ), ( a, b ), ( a ), ( b, c ), ( b ), ( a
15、, 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) scorefrom studentsgr
16、oup by cube(id,area,stu_type)order by id,area,stu_type; |1.3. OVER()函数的使用1.3.1. 统计名次1.3.1.1.DENSE_RANK(),允许并列名次、名次不间断,如 122344456将 score按 ID分组排名:dense_rank() over(partition by id order by score desc)将 score不分组排名: dense_rank() over(order by score desc)select id,area,score,dense_rank() over(partition
17、by id order by score desc) 分组 id排序,dense_rank() over(order by score desc) 不分组排序from students order by id,area;1.3.1.2.ROW_NUMBER(),不允许并列名次、相同值名次不重复,结果如 123456将 score按 ID分组排名:row_number() over(partition by id order by score desc)将 score不分组排名: row_number() over(order by score desc)select id,area,score
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- oracle 函数 大全 分析 聚合 转换 日期 字符 数值 其他
![提示](https://www.taowenge.com/images/bang_tan.gif)
链接地址:https://www.taowenge.com/p-581425.html
限制150内