《oracle重要的几个常用函数(最精简)》由会员分享,可在线阅读,更多相关《oracle重要的几个常用函数(最精简)(25页珍藏版)》请在金锄头文库上搜索。
1、Oracle 常用函数总结6.LENGTH返回字符串的长度;SQL select name,length(name),addr,length(addr),sal,length(to_char(sal) from gao.nchar_tst;NAME LENGTH(NAME) ADDR LENGTH(ADDR) SAL LENGTH(TO_CHAR(SAL)- - - - - -高乾竞 3 北京市海锭区 6 9999.99 7 7.LOWER返回字符串,并将所有的字符小写SQL select lower(AaBbCcDd)AaBbCcDd from dual;AABBCCDD-aabbccdd8
2、.UPPER返回字符串,并将所有的字符大写SQL select upper(AaBbCcDd) upper from dual;UPPER-AABBCCDD 9.RPAD和LPAD(粘贴字符)RPAD 在列的右边粘贴字符LPAD 在列的左边粘贴字符SQL select lpad(rpad(gao,10,*),17,*)from dual;LPAD(RPAD(GAO,1-*gao*不够字符则用*来填满10.LTRIM和RTRIMLTRIM 删除左边出现的字符串RTRIM 删除右边出现的字符串SQL select ltrim(rtrim( gao qian jing , ), ) from dua
3、l;LTRIM(RTRIM(-gao qian jing11.SUBSTR(string,start,count)取子字符串,从start开始,取count个SQL select substr(13088888888,3,8) from dual;SUBSTR(-0888888812.REPLACE(string,s1,s2)string 希望被替换的字符或变量 s1 被替换的字符串s2 要替换的字符串SQL select replace(he love you,he,i) from dual;REPLACE(H-i love you13.SOUNDEX返回一个与给定的字符串读音相同的字符串S
4、QL create table table1(xm varchar(8);SQL insert into table1 values(weather);SQL insert into table1 values(wether);SQL insert into table1 values(gao);SQL select xm from table1 where soundex(xm)=soundex(weather);XM-weatherwether14.TRIM(s from string)LEADING 剪掉前面的字符TRAILING 剪掉后面的字符如果不指定,默认为空格符 15.ABS返回
5、指定值的绝对值SQL select abs(100),abs(-100) from dual; ABS(100) ABS(-100)- - 100 10016.ACOS给出反余弦的值SQL select acos(-1) from dual; ACOS(-1)-3.141592717.ASIN给出反正弦的值SQL select asin(0.5) from dual;ASIN(0.5)-.5235987818.ATAN返回一个数字的反正切值SQL select atan(1) from dual; ATAN(1)-.7853981619.CEIL返回大于或等于给出数字的最小整数SQL sele
6、ct ceil(3.1415927) from dual;CEIL(3.1415927)- 420.COS返回一个给定数字的余弦SQL select cos(-3.1415927) from dual;COS(-3.1415927)- -121.COSH返回一个数字反余弦值SQL select cosh(20) from dual; COSH(20)-24258259822.EXP返回一个数字e的n次方根SQL select exp(2),exp(1) from dual; EXP(2) EXP(1)- -7.3890561 2.718281827.POWER返回n1的n2次方根SQL sel
7、ect power(2,10),power(3,3) from dual;POWER(2,10) POWER(3,3)- - 1024 2728.ROUND和TRUNC按照指定的精度进行舍入SQL select round(55.5),round(-55.4),trunc(55.5),trunc(-55.5) from dual;ROUND(55.5) ROUND(-55.4) TRUNC(55.5) TRUNC(-55.5)- - - - 56 -55 55 -5529.SIGN取数字n的符号,大于0返回1,小于0返回-1,等于0返回0SQL select sign(123),sign(-1
8、00),sign(0) from dual;SIGN(123) SIGN(-100) SIGN(0)- - - 1 -1 030.SIN返回一个数字的正弦值SQL select sin(1.57079) from dual;SIN(1.57079)- 131.SIGH返回双曲正弦的值SQL select sin(20),sinh(20) from dual; SIN(20) SINH(20)- -.91294525 24258259832.SQRT返回数字n的根SQL select sqrt(64),sqrt(10) from dual; SQRT(64) SQRT(10)- - 8 3.16
9、2277733.TAN返回数字的正切值SQL select tan(20),tan(10) from dual; TAN(20) TAN(10)- -2.2371609 .6483608334.TANH返回数字n的双曲正切值SQL select tanh(20),tan(20) from dual; TANH(20) TAN(20)- - 1 2.2371609 35.TRUNC按照指定的精度截取一个数SQL select trunc(124.1666,-2) trunc1,trunc(124.16666,2) from dual; TRUNC1 TRUNC(124.16666,2)- - 1
10、00 124.16 36.ADD_MONTHS增加或减去月份select to_char(add_months(to_date(199912,yyyymm),2),yyyymm) from dual;TO_CHA-200002SQL select to_char(add_months(to_date(199912,yyyymm),-2),yyyymm) from dual;TO_CHA-19991037.LAST_DAY返回日期的最后一天SQL select to_char(sysdate,yyyy.mm.dd),to_char(sysdate)+1,yyyy.mm.dd) from dual
11、;TO_CHAR(SY TO_CHAR(S- -2004.05.09 2004.05.10SQL select last_day(sysdate) from dual;LAST_DAY(S-31-5月 -0438.MONTHS_BETWEEN(date2,date1)给出date2-date1的月份SQL select months_between(19-12月-1999,19-3月-1999) mon_between from dual;MON_BETWEEN- 9SQLselectmonths_between(to_date(2000.05.20,yyyy.mm.dd),to_date(2
12、005.05.20,yyyy.mm.dd) mon_betw from dual; MON_BETW- -6039.NEW_TIME(date,this,that)给出在this时区=other时区的日期和时间SQL select to_char(sysdate,yyyy.mm.dd hh24:mi:ss) bj_time,to_char(new_time 2 (sysdate,PDT,GMT),yyyy.mm.dd hh24:mi:ss) los_angles from dual;BJ_TIME LOS_ANGLES- -2004.05.09 11:05:32 2004.05.09 18:05:3240