Oracle函数脚本记录
--内置函数
--聚合函数 返回单个值
select count(*) from student where sclass=''; --count()记录条数
select sum(degree) from score t; --sum(degree)求成绩总和
select avg(degree) from score t; --avg(degree)求成绩平均值
select max(degree),min(degree) from score t; --max(degree),min(degree)分别为成绩最大值,最小值
select max(degree),min(degree),avg(degree),sum(degree) from score t; --可以用一行将所有聚合函数全部计算出来 --转换函数
select sname,sno,sbirthday from student where to_char(sbirthday,'yyyy')= (select to_char(s.sbirthday,'yyyy') from student s where s.sno='');
--to_char 将日期转化成字符串,日期格式 'yyyy-mm-dd hh24:mi:ss'
select * from student where sbirthday >=to_date('1976-1-1','yyyy-mm-dd') --to_date 将字符串转化成日期 --时间函数
select cast('' as number) from dual;
select sysdate from dual; --获取数据库当前时间
select sysdate+1 from dual; --日期里的日进行加1日;
select add_months(sysdate,+1) from dual; --月份加1月 --数值函数
--绝对值
select abs(-123) from dual;
--求模
select mod(12,5) from dual;
--取整
--取上限值
select ceil(123.35) from dual;
--取下限值
select floor(123.35) from dual;
--四舍五入
select round(123.35) from dual;
select round(123.4567,2) from dual; --根据保留位数在四舍五入,保留两位小数
select round(123.4567,-1) from dual; --个位数进行四舍五入,以小数点作为远点进行加减
--舍去小数点
select trunc(123.35) from dual;
select trunc(123.35,1) from dual; --字符串函数
--计算长度
select sname, langth(sname) from student;
--去空格
select trim(' asas ') from dual;
select ltrim(' asas ') from dual; --左侧去空格
select rtrim(' asas ') from dual; --右侧去空格
--替换
select replace(' ab cd ',' ','') from dual;
select replace(sname,'王','liu') from student where sname like '王%';
--查找字符串
select instr('abcd','a') from dual; --查询索引值从1开始,找不到返回0
--截取字符串
select substr('abcde','') from dual; --0或者1都是从1位开始往后截取,到最后
select substr('abcde',-1) from dual; --从右侧进行截取,截取结果为e
select substr('abcde',2,3) from dual; --截取结果为bcd,从截取位置开始算取3位长度
select substr('abcde',-2,3) from dual; --截取结果为dc,从最右边开始截取到3个长度
select aname,substr(sname,1,1)||'同学' from student; --其他函数
select avg(nvl(degree,0)) from score; --将空值赋个默认值为0,在进行平均数计算;
select t.* decode(ssex,'','男','','女','不知道') from STUDENT t; --将1换成男,2换成女,如果没有,显示‘不知道’
Oracle函数脚本记录的更多相关文章
- Oracle编程脚本记录
--命令窗口查询 exec 存储名.包名.视图; select 函数名 from dual; create or replace procedure PR_test is begin --存储过程的代 ...
- Oracle 函数使用记录
持续更新…… 参考:https://www.cnblogs.com/bbliutao/archive/2017/11/08/7804263.html 1. ADD_MONTHS 语法: ADD_MON ...
- oracle 函数中,一定要注意出现空记录和多条记录的处理方法
今天折腾了3个小时,为一个以前不知道的oracle函数机制: 在sql查询中,如果一个查询未能获取记录,oracle不会报错 如select aa from bb where 1=2; 但在oracl ...
- oracle函数,游标,视图使用总结0.000000000000000000001
oracle函数或者叫存储过程,在实际的开发过程中对于复杂的业务需求是非常有用的,非常有效率的也是非常好玩儿的一个技术点. 平常在开发过程中对于CRUD功能较多.一般SQL即可应付,大不了就是长一点而 ...
- Oracle函数sys_connect_by_path 详解
Oracle函数sys_connect_by_path 详解 语法:Oracle函数:sys_connect_by_path 主要用于树查询(层次查询) 以及 多列转行.其语法一般为: s ...
- Oracle多行记录合并的几种方法
今天正好遇到需要做这个功能,顺手搜了一下网络,把几种方法都列出来,方便以后参考. 1 什么是合并多行字符串(连接字符串)呢,例如: SQL> desc test; Name Type Nulla ...
- 汉字转拼音的Oracle函数
前言: 最近处理一个特殊的问题,需要用到汉字自动转换拼音的功能. 解决: 在这里找了不少资料,都是有所缺陷,而且也好像很绕.其实是一个很简单的东东.后来还是自己写了一个函数获取.分享出来,给有需要的X ...
- oracle函数,游标,视图使用总结
oracle函数或者叫存储过程,在实际的开发过程中对于复杂的业务需求是非常有用的,非常有效率的也是非常好玩儿的一个技术点. 平常在开发过程中对于CRUD功能较多.一般SQL即可应付,大不了就是长一点而 ...
- Oracle数据库脚本中的set define off
2018年8月6日15:11:34 Oracle数据库脚本中的set define off 前言 最近在公司写需求,接触到脚本,第一句set define off;就不知道什么意思了,查询后记录之. ...
随机推荐
- 正确获得android设备的IP地址
网上此类获得android设备IP地址相关的文章有不少,有一篇是比较通用的,但有一个问题:有些设备默认的是IPv6的地址,那段代码获得的就是IPv6的地址.但这显然不是我们想要的,我们需要的是IPv4 ...
- JS制作计算器(键盘版)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #2b7ec3 } p.p2 { margin: 0.0px ...
- 使用Glyph Designer创建位图字体
使用Glyph Designer创建位图字体 转http://book.2cto.com/201210/6610.html <iOS 5 cocos2d游戏开发实战(第2版)>将引导 ...
- [LeetCode]436 Find Right Interval
Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...
- [转]ORACLE 审计功能
审计是对选定的用户动作的监控和记录,通常用于: u 审查可疑的活动.例如:数据被非授权用户所删除,此时安全管理员可决定对该 数据库的所有连接进行审计,以及对数据库的所有表的成功地或不 ...
- AngularJs 时间控件
<div class="form-group col-sm-4 clearfix"> <label class="col-sm-5 control-la ...
- Oracle Blob 字段的模糊查询
原文地址:http://blog.csdn.net/springk/article/details/6866248
- runtime记录
前言: 最初对于runtime的了解其实只停留在,知道这是一组C的方法,知道消息机制中会把方法调用转成objc_msgSend(theObject,@selector(objectMethod)).随 ...
- position定位
CSS盒模型和定位的类型 为了搞清楚定位首先你得了解CSS盒模型.在上一句中的链接是我写在InstantShift 中的一篇关于盒模型的文章.我在那篇文章做了详细的讲解并会在这篇文章中做一个快速的总结 ...
- 最快让你上手ReactiveCocoa之进阶篇
前言 由于时间的问题,暂且只更新这么多了,后续还会持续更新本文<最快让你上手ReactiveCocoa之进阶篇>,目前只是简短的介绍了些RAC核心的一些方法,后续还需要加上MVVM+Rea ...