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;就不知道什么意思了,查询后记录之. ...
随机推荐
- windows守护进程脚本
通常通过进程名称或者端口号来判断进程是否正在运行.但是windows下进程名常常难以区分,比如有两个python脚本程序A和B同时在执行,进程名都是python.exe.若是通过端口来区分,却又只适用 ...
- 通俗易懂的 JSon解析处理
1.主要用到的类: 主要用到了JavaScriptSerializer类,该类在System.Web.Script.Serialization命名空间(在System.Web.Extensions.d ...
- UI基础之UITableViewController相关
1> 设置类型为Group - (instancetype)initWithStyle:(UITableViewStyle)style { return [super initWithStyle ...
- PHP那些非常有用却鲜有人知的函数
PHP里有非常丰富的内置函数,很多我们都用过,但仍有很多的函数我们大部分人都不熟悉,可它们却十分的有用.这篇文章里,我列举了一些鲜为人知但会让你眼睛一亮的PHP函数. levenshtein() 你有 ...
- 从MyEclipse转战到IntelliJ IDEA的经历
从MyEclipse转战到IntelliJ IDEA的经历 我一个朋友写了一篇"从Eclipse到Android Studio"博文,于是心潮澎湃我也想一篇,分享自己用这个IDEA ...
- SpringMVC常用注解實例詳解3:@ResponseBody
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
- ArcGIS10.1 api for Flex开发用于ArcGIS 9.3时QueryTask 'Error #2032'错误的解决方案
因客户GIS软件需求,将应用降级到低版本ArcGIS9.3,不仅数据有些样式.配色.字符有些问题,API也要相应“降级”,解决如下: 利用9.3+flex做QueryTask时候出现了[RPC Fau ...
- Windows 商店应用中使用 SharePoint REST API
前面一篇我们介绍了 Office 365 REST API 的官方工具的使用,本篇我们来看一下 SharePoint REST API 本身的描述.结构和使用方法,以及一些使用经验. 首先来看看Sha ...
- (转)如何为你的Viewcontroller瘦身
View controllers are often the biggest files in iOS projects, and they often contain way more code t ...
- [Leetcode][JAVA] Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...