志达IT
做快乐程序员

oracle 函数(oracle是什么软件)

oracle函数

oracle中的一些常用函数及示例,一是为了和大家共享,二是可以在以后工作中忘记了随时查阅。废话不多说,下面直接上函数。
一.单行函数
只处理单个行,并且为每行回来一个成果。
1.字符函数
(1)concat(str1,str2)字符串拼接函数
selectconcat(‘Hello’,’World’)fromdual;
–等价于
select’Hello’||’World’fromdual;
(2)initcap(str)将每个单词首字母大写,其他字母小写
selectinitcap(‘helloworld!’)fromdual;–回来成果为’HelloWorld!’
selectinitcap(‘HELLOWORLD!’)fromdual;–回来成果为’HelloWorld!’
(3)instr(x,find_string[,start][,occurrence])回来指定字符串在某字符串中的方位,可以指定查找的开端方位和回来第几次查找出来的成果
———-查找时下标从1开端计算
selectinstr(‘HelloWorld!’,’o’)fromdual;–从1方位开端查找,回来第一次呈现的o的方位,成果为5
selectinstr(‘HelloWorld!’,’o’,6)fromdual;–从6方位开端查找,回来第一次呈现的o的方位,成果为8
selectinstr(‘HelloWorld!’,’o’,1,2)fromdual;–从1方位开端查找,回来第二次呈现o的方位,成果为8
(4)length(str)回来表达式中的字符数
selectlength(‘HelloWorld!’)fromdual;–回来成果为12
selectlength(‘张三’)fromdual;–回来成果为2
(5)lengthb(str)回来表达式中的字节数
selectlengthb(‘HelloWorld!’)fromdual;–回来成果为12
selectlengthb(‘张三’)fromdual;–回来成果为6
(6)lower(str)将字符串转化为小写
selectlower(‘HelloWorld!’)fromdual;
(7)upper(str)将字符串转化为大写
selectupper(‘HelloWorld!’)fromdual;
(8)lpad(str,width[,pad_string])当字符串长度不够时,左填充补齐,可以指定补齐时用什么字符补齐,若不指定,则以空格补齐
selectlpad(‘HelloWorld!’,20)fromdual;–回来成果为’HelloWorld!’
selectlpad(‘HelloWorld!’,20,’*’)fromdual;–回来成果为’********HelloWorld!’
(9)rpad(str,width[,pad_string])当字符串长度不够时,右填充补齐,原理同左填充
selectrpad(‘HelloWorld!’,20)fromdual;–回来成果为’HelloWorld!’
selectrpad(‘HelloWorld!’,20,’*+’)fromdual;–回来成果为’HelloWorld!*+*+*+*+’
(10)ltrim(x[,trim_string])从字符串左边去除指定的一切字符串,若没有指定去除的字符串,则默许去除左边空白符
selectltrim(‘HelloWorld!’)fromdual;–回来成果为’HelloWorld!’
selectltrim(‘***+*HelloWorld!***+*’,’*+’)fromdual;–回来成果为’HelloWorld!***+*’
(11)rtrim(x[,trim_string])从字符串右侧去除指定的一切字符串,原理同ltrim()
selectrtrim(‘HelloWorld!’)fromdual;–回来成果为’HelloWorld!’
selectrtrim(‘***+*HelloWorld!***+*’,’*+’)fromdual;–回来成果为’***+*HelloWorld!’
(12)trim(trim_stringfromx)从字符串两侧去除指定的一切字符串
selecttrim(‘*+’from’***+*HelloWorld!***+*’)fromdual;
注意,ltrim()和rtrim()的截取集可以使多个字符,但trim的截取集只能有一个字符
selecttrim(‘*+’from’***+*HelloWorld!***+*’)fromdual;–过错,截取集只能有一个字符
(13)nvl(x,value)将一个NULL转化为别的一个值,假如x为NULL,则回来value,不然回来x值自身
insertintostudentvalues(7,’猪猪’,default,NULL);
selectnvl(address,’北京市’)fromstudent;
(14)nvl2(x,value1,value2),假如x不为NULL,回来value1,不然,回来value2
selectnvl2(address,’有地址’,’无地址’)fromstudent;
(15)replace(x,search_string,replace_string),从字符串x中查找search_string字符串,并运用replace_string字符串替换。并不会修改数据库中原始值
selectreplace(‘HelloWorld!’,’o’,’HA’)fromdual;
(16)substr(x,start[,length])回来字符串中的指定的字符,这些字符从字符串的第start个方位开端,长度为length个字符;假如start是负数,则从x字符串的结尾开端算起;假如length省略,则将回来一直到字符串结尾的一切字符
selectsubstr(‘HelloWorld’,3)fromdual;–回来成果为’lloWorld’
selectsubstr(‘HelloWorld’,-3)fromdual;–回来成果为’rld’
selectsubstr(‘HelloWorld’,3,2)fromdual;–回来成果为’ll’
selectsubstr(‘HelloWorld’,-7,4)fromdual;–回来成果为’oWo’oracle
2.数值函数
(1)abs(value)回来value的绝对值
selectabs(-10)fromdual;–回来成果为10
(2)ceil(value)回来大于等于value的最小整数
selectceil(2.3)fromdual;–回来成果为3
(3)floor(value)回来小于等于value的最大整数
selectfloor(2.3)fromdual;–回来成果为2
(4)trunc(value,n)对value进行切断,假如n>0,保留n位小数;n<0,则保留-n位整数位;n=0,则去掉小数部分
selecttrunc(555.666)fromdual;–回来成果为555,不加n时默许去掉小数部分
selecttrunc(555.666,2)fromdual;–回来成果为555.66
selecttrunc(555.666,-2)fromdual;–回来成果为500
(5)round(value,n)对value进行四舍五入,保存小数点右侧的n位。假如n省略的话,相当于n=0的状况
selectround(555.666)fromdual;–回来成果为556,不加n时默许去掉小数部分
selectround(555.666,2)fromdual;–回来成果为555.67
selectround(555.666,-2)fromdual;–回来成果为600
注意:1.trunc和round用法相似,只不过trunc是硬生生截取,并不进行四舍五入,而round进行截取时四舍五入
2.都还可以对日期的截取,可以参考写的日期函数笔记
selectround(sysdate,’year’)fromdual;
selecttrunc(sysdate,’year’)fromdual;
3.转化函数
将值从一种类型转化成别的一种类型,或许从一种格局转化为别的一种格局
(1)to_char(x[,format]):将x转化为字符串。format为转化的格局,可认为数字格局或日期格局
selectto_char(‘12345.67’)fromdual;–回来成果为12345.67
selectto_char(‘12345.67′,’99,999.99’)fromdual;–回来成果为12,345.67
(2)to_number(x[,format]):将x转化为数字。可以指定format格局
selectto_number(‘970.13’)+25.5fromdual;
selectto_number(‘-$12,345.67′,’$99,999.99’)fromdual;
(3)cast(xastype):将x转化为指定的兼容的数据库类型
selectcast(12345.67asvarchar2(10)),cast(’05-7月-07’asdate),cast(12345.678asnumber(10,2))fromdual;
(4)to_date(x[,format]):将x字符串转化为日期
selectto_date(‘2012-3-15′,’YYYY-MM-DD’)fromdual
二.集合函数
1.常用函数
(1)avg(x):回来x的平均值
selectavg(grade)fromsc;
(2)count(x):回来计算的行数
selectcount(name)fromsc;
(3)max(x):回来x的最大值
selectmax(grade)fromsc;
(4)min(x):回来x的最小值
selectmin(grade)fromsc;
(5)sum(x):回来x的总计值
selectsum(grade)fromsc;
2.对分组行运用集合函数
对分组后的行运用集合函数,集合函数会计算每组中的值,关于每组别离计算后回来一个值。
示例
–按照职位分组,求出每个职位的最高和最低工资
selectjob,max(sal),min(sal)fromemp
groupbyjob
orderbyjob;
注意:1.分组时select子句后边的列名必须与groupby子句后的列名共同,除非是聚合函数
selectdeptno,avg(sal)fromEMP;–过错,因为deptno不是集合函数,也不是groupby后边跟的列名
2.不能运用集合函数作为WHERE子句的挑选条件
selectdeptnofromempwhereavg(sal)>1000;–过错
3.分组后,需要运用条件进行挑选,则运用having过滤分组后的行,不能运用where,where只能放在groupby前面。
selectdeptno,avg(sal)fromempwheredeptno<>10
groupbydeptno
havingavg(sal)>900;oracle

oracle是什么软件

ORACLE数据库体系是美国ORACLE公司(甲骨文)提供的以分布式数据库为中心的一组软件产品,是最流行的客户/服务器(CLIENT/SERVER)或B/S体系结构的数据库之一。比如SilverStream便是根据数据库的一种中间件。ORACLE数据库是世界上运用最为广泛的数据库办理体系,作为一个通用的数据库体系,它具有完好的数据办理功能;作为一个联系数据库,它是一个完备联系的产品;作为分布式数据库它实现了分布式处理功能。但它的一切常识,只要在一种机型上学习了ORACLE常识,便能在各种类型的机器上运用它。
Oracle数据库最新版本为OracleDatabase20c。Oracle数据库12c引入了一个新的多承租方架构,运用该架构可轻松部署和办理数据库云。此外,一些立异特性可最大极限地提高资源运用率和灵活性,如OracleMultitenant可快速整合多个数据库,而AutomaticDataOptimization和HeatMap能以更高的密度压缩数据和对数据分层。这些绝无仅有的技术进步再加上在可用性、安全性和大数据支撑方面的首要增强,使得Oracle数据库12c成为私有云和公有云部署的理想平台。

赞(0)
未经允许不得转载:志达IT网站 » oracle 函数(oracle是什么软件)
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

志达IT网站 每天分享编程和互联网的IT技术博客

登录/注册联系我们