--内置函数
--聚合函数 返回单个值
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函数脚本记录的更多相关文章

  1. Oracle编程脚本记录

    --命令窗口查询 exec 存储名.包名.视图; select 函数名 from dual; create or replace procedure PR_test is begin --存储过程的代 ...

  2. Oracle 函数使用记录

    持续更新…… 参考:https://www.cnblogs.com/bbliutao/archive/2017/11/08/7804263.html 1. ADD_MONTHS 语法: ADD_MON ...

  3. oracle 函数中,一定要注意出现空记录和多条记录的处理方法

    今天折腾了3个小时,为一个以前不知道的oracle函数机制: 在sql查询中,如果一个查询未能获取记录,oracle不会报错 如select aa from bb where 1=2; 但在oracl ...

  4. oracle函数,游标,视图使用总结0.000000000000000000001

    oracle函数或者叫存储过程,在实际的开发过程中对于复杂的业务需求是非常有用的,非常有效率的也是非常好玩儿的一个技术点. 平常在开发过程中对于CRUD功能较多.一般SQL即可应付,大不了就是长一点而 ...

  5. Oracle函数sys_connect_by_path 详解

    Oracle函数sys_connect_by_path 详解 语法:Oracle函数:sys_connect_by_path 主要用于树查询(层次查询) 以及 多列转行.其语法一般为:       s ...

  6. Oracle多行记录合并的几种方法

    今天正好遇到需要做这个功能,顺手搜了一下网络,把几种方法都列出来,方便以后参考. 1 什么是合并多行字符串(连接字符串)呢,例如: SQL> desc test; Name Type Nulla ...

  7. 汉字转拼音的Oracle函数

    前言: 最近处理一个特殊的问题,需要用到汉字自动转换拼音的功能. 解决: 在这里找了不少资料,都是有所缺陷,而且也好像很绕.其实是一个很简单的东东.后来还是自己写了一个函数获取.分享出来,给有需要的X ...

  8. oracle函数,游标,视图使用总结

    oracle函数或者叫存储过程,在实际的开发过程中对于复杂的业务需求是非常有用的,非常有效率的也是非常好玩儿的一个技术点. 平常在开发过程中对于CRUD功能较多.一般SQL即可应付,大不了就是长一点而 ...

  9. Oracle数据库脚本中的set define off

    2018年8月6日15:11:34 Oracle数据库脚本中的set define off 前言 最近在公司写需求,接触到脚本,第一句set define off;就不知道什么意思了,查询后记录之. ...

随机推荐

  1. 使用自定义的framework

    1.创建framework工程,创建需要的类将接口暴露在public中

  2. linq group by max 多表链接实例

    SELECT s.* FROM dbo.ERG_TipOffsInfo s, (SELECT Data,MAX(Createtime) max_Time FROM dbo.ERG_TipOffsInf ...

  3. C++面试中关于sizeof问题总结

    原文:http://blog.sina.com.cn/s/blog_7c983ca60100yfdv.html#SinaEditor_Temp_FontName (1)      sizeof是操作符 ...

  4. 在 Mac OS X 上创建的 .NET 命令行程序访问数据库 (使用Entity Framework 7 )

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  5. [UCSD白板题] Pairwise Distinct Summands

    Problem Introduction This is an example of a problem where a subproblem of the corresponding greedy ...

  6. VS2010 密钥问题

    密钥:YCFHQ9DWCYDKV88T2TMHG7BHP ①在VS2010安装包中找到setup==>setup.sdb 的Product Key把密钥改为上面的就可以了 ②不想重装那就在控制面 ...

  7. Alamofire源码学习

    Core文件夹:          Alamofire.swift - - - 该文件中主要是给用户提供一些便利的调用方法,用户可以直接调用该文件中的便利方法来使用Alamofire相关功能.     ...

  8. JavaScript 基础第十天

    学习总结 1定时器 ①.setTimeout() // 间隔多长时间执行一次(会返回一个数字型的标识) ②.setInterval() // 间隔多长时间执行,是不断地执行. ③.clearTimeo ...

  9. 练习1-23:删去C语言程序中所有的注释语句(C程序设计语言 第2版)

    #include <stdio.h> main() { FILE * fp_i; FILE * fp_o; fp_i = fopen("input.txt", &quo ...

  10. ABP框架详解(四)Feature

    ABP框架中存在一个Feature的特性,功能和设计思路非常类似于框架中的Authorization功能,都是来控制用户是否能够继续操作某项功能,不同点在于Authorization默认是应用在IAp ...