--1.ASCII返回与指定的字符对应的十进制数;
select ascii('A') A, ascii('a') a, ascii('0') zero, ascii(' ') space
from dual;
--返回: 65 97 48 32
--2.CHR给出整数,返回对应的字符;
select chr(54740) zhao, chr(65) chr65 from dual;
--返回:赵 A
--3.CONCAT连接两个字符串;
select concat('010-', '88888888') || '转23' 高乾竞电话 from dual;
--返回:010-88888888转23
--4.INITCAP返回字符串并将字符串的第一个字母变为大写;
select initcap('smith') upp from dual;
--返回:Smith
--5.INSTR(C1,C2,I,J)在一个字符串中搜索指定的字符,返回发现指定的字符的位置;
--C1 被搜索的字符串
--C2 希望搜索的字符串
--I 搜索的开始位置,默认为1
--J 出现的位置,默认为1
select instr('oracle traning', 'ra', 1, 2) instring from dual;
--返回: 9
--6.LENGTH返回字符串的长度;
select name, length(name), addr, length(addr), sal, length(to_char(sal))
from gao.nchar_tst;
--返回:高乾竞 3 北京市海锭区 6 9999.99 7
--7.LOWER返回字符串,并将所有的字符小写
select lower('AaBbCcDd') AaBbCcDd from dual;
--返回:aabbccdd
--8.UPPER返回字符串,并将所有的字符大写
select upper('AaBbCcDd') upper from dual;
--返回:AABBCCDD
--9.RPAD和LPAD(粘贴字符)RPAD 在列的右边粘贴字符LPAD 在列的左边粘贴字符
select lpad(rpad('gao', 10, '*'), 17, '*') from dual;
--返回:*******gao*******
--10.LTRIM和RTRIMLTRIM 删除左边出现的字符串RTRIM 删除右边出现的字符串
select ltrim(rtrim(' gao qian jing ', ' '), ' ') from dual;
--返回:gao qian jing
--11.SUBSTR(string,start,count)取子字符串,从start开始,取count个
select substr('13088888888', 3, 8) from dual;
--返回:08888888
--12.REPLACE('string','s1','s2')
--string 希望被替换的字符或变量
--s1 被替换的字符串
--s2 要替换的字符串
select replace('he love you','he','i') from dual;
--返回:i love you
--13.SOUNDEX返回一个与给定的字符串读音相同的字符串
create table table1(xm varchar(8));
insert into table1 values('weather');
insert into table1 values('wether');
insert into table1 values('gao');
select xm from table1 where soundex(xm)=soundex('weather');
--返回结果:weather wether
--14.剪掉某个的字符,如果不指定,默认删除空格
select TRIM('s' from 'string') from dual;
select trim(' string') from dual;
select ltrim(' string') from dual;
select rtrim(' string ') from dual;
--15.ABS返回指定值的绝对值
select abs(100),abs(-100) from dual;
--返回结果: 100 100
--16.ACOS给出反余弦的值
select acos(-1) from dual;
--返回结果:3.1415927
--17.ASIN给出反正弦的值
select asin(0.5) from dual;
--返回结果:0.523598775598299
--18.ATAN返回一个数字的反正切值
select atan(1) from dual;
--返回结果:0.785398163397448
--19.CEIL返回大于或等于给出数字的最小整数
select ceil(3.1415927) from dual;
--返回结果:4
--20.COS返回一个给定数字的余弦
select cos(-3.1415927) from dual;
--返回结果:-0.999999999999999
--21.COSH返回一个数字反余弦值
select cosh(20) from dual;
--返回结果:242582597.704895
--22.EXP返回一个数字e的n次方根
select exp(2),exp(1) from dual;
--返回结果:7.38905609893065 2.71828182845905
--23.FLOOR对给定的数字取整数
select floor(2345.67) from dual;
--返回结果:2345
--24.LN返回一个数字的对数值
select ln(1),ln(2),ln(2.7182818) from dual;
--返回结果:0 0.693147180559945 0.999999989530502
--25.LOG(n1,n2)返回一个以n1为底n2的对数
select log(2,1),log(2,4) from dual;
--返回结果:0 2
--26.MOD(n1,n2)返回一个n1除以n2的余数
select mod(10,3),mod(3,3),mod(2,3) from dual;
--返回结果 : 1 0 2
--27.POWER返回n1的n2次方根
select power(2,10),power(3,3) from dual;
--返回结果:1024 27
--28.ROUND和TRUNC按照指定的精度进行舍入
select round(55.5),round(-55.4),trunc(55.5),trunc(-55.5) from dual;
--返回结果:56 -55 55 -55
--29.SIGN取数字n的符号,大于0返回1,小于0返回-1,等于0返回0
select sign(123),sign(-100),sign(0) from dual;
--返回结果: 1 -1 0
--30.SIN返回一个数字的正弦值
select sin(1.57079) from dual;
--返回结果:0.999999999979986
--31.SIGH返回双曲正弦的值
select sin(20),sinh(20) from dual;
--返回结果:0.912945250727628 242582597.704895
--32.SQRT返回数字n的根
select sqrt(64),sqrt(10) from dual;
--返回结果:8 3.16227766016838
--33.TAN返回数字的正切值
select tan(20),tan(10) from dual;
--返回结果:2.23716094422474 0.648360827459087
--34.TANH返回数字n的双曲正切值
select tanh(20),tan(20) from dual;
--返回结果:1 2.23716094422474
--35.TRUNC按照指定的精度截取一个数
select trunc(124.1666,-2) trunc1,trunc(124.16666,2) from dual;
--返回结果:100 124.16
--36.ADD_MONTHS增加或减去月份
select to_char(add_months(to_date('199912','yyyymm'),2),'yyyymm') from dual;
--返回结果:200002
select to_char(add_months(to_date('199912','yyyymm'),-2),'yyyymm') from dual;
--返回结果:199910
--37.LAST_DAY返回日期的最后一天
select to_char(sysdate,'yyyy.mm.dd'),to_char((sysdate)+1,'yyyy.mm.dd') from dual;
--2010.09.14 2010.09.15
select last_day(sysdate) from dual;
--2010-9-30 下午 04:48:10
--38.MONTHS_BETWEEN(date2,date1)给出date2-date1的月份
select months_between('19-12月-1999','19-3月-1999') mon_between from dual;
--返回结果:9
select months_between(to_date('2000.05.20','yyyy.mm.dd'),to_date('2005.05.20','yyyy.mm.dd')) mon_betw from dual;
--返回结果:-60
--39.NEW_TIME(date,'this','that')给出在this时区=other时区的日期和时间
select to_char(sysdate,'yyyy.mm.dd hh24:mi:ss') bj_time,to_char(new_time(sysdate,'PDT','GMT'),'yyyy.mm.dd hh24:mi:ss') los_angles from dual;
--返回结果:2010.09.14 16:53:25 2010.09.14 23:53:25
--40.NEXT_DAY(date,'day')给出日期date和星期x之后计算下一个星期的日期
select next_day('18-5月-2001','星期五') next_day from dual;
--41.SYSDATE用来得到系统的当前日期
select to_char(sysdate,'dd-mm-yyyy day') from dual;
--返回结果:14-09-2010 星期二
--trunc(date,fmt)按照给出的要求将日期截断,如果fmt='mi'表示保留分,截断秒
select to_char(trunc(sysdate,'hh'),'yyyy.mm.dd hh24:mi:ss') hh,
to_char(trunc(sysdate,'mi'),'yyyy.mm.dd hh24:mi:ss') hhmm
from dual;
--返回结果:2010.09.14 16:00:00 2010.09.14 16:56:00
--42.chartorowid将字符数据类型转换为ROWID类型
select rowid,rowidtochar(rowid),ename from scott.emp;
--43.CONVERT(c,dset,sset)将源字符串 sset从一个语言字符集转换到另一个目的dset字符集
select convert('strutz','we8hp','f7dec') "conversion" from dual;
--返回结果:strutz
--44.TO_CHAR(date,'format')
select to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') from dual;
--返回结果 : 2010/09/14 17:26:24
--45.TO_DATE(string,'format')将字符串转化为ORACLE中的一个日期
select to_date('2010-05-10','yyyy-mm-dd') FROM dual;
--返回:2010-5-10
--46.TO_MULTI_BYTE将字符串中的单字节字符转化为多字节字符
select to_multi_byte('高') from dual;
--47.TO_NUMBER将给出的字符转换为数字
select to_number('1999') year from dual;
--返回:1999
--48.GREATEST返回一组表达式中的最大值,即比较字符的编码大小
select greatest('AA','AB','AC') from dual;
--返回:AC
select greatest('啊','安','天') from dual;
--返回:天
--49.LEAST返回一组表达式中的最小值
select least('啊','安','天') from dual;
--返回:啊
--50.USER返回当前用户的名字
select user from dual;
--返回:scott
oracle 50个函数总结
最新推荐文章于 2024-06-04 18:07:29 发布