Oracle_常用函数
1,日期函数:
ADD_MONTHS(日期,数字):在已有的时间上增加月份(负数表示过去)。
SQL> select to_char(add_months(sysdate,-2),'yyyy-mm-dd') from dual;
LAST_DAY(日期):返回最后一天
SQL> select last_day(sysdate) from dual; 月末
SQL> select to_char(last_day(sysdate)+1,'yyyy-mm-dd') from dual; 月初
MONTHS_BETWEEN(日期1,日期2):
SQL> select months_between('19-12月-1999','19-3月-1999') mon_between from dual;
SYSDATE:系统时间
SQL> select sysdate from dual;
NEXT_DAY(d,char):给出日期date和星期x之后计算下一个星期的日期
SQL> select next_day('18-5月-2001','星期五') next_day from dual;
2,转换函数
to_number:将字符转化成数字select to_number('1988') from dual;
to_char(date,'format'):将日期或数字转成字符串
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
to_date(string,'format'):将字符串转成日期
SQL> select to_date('20140705','yyyy-mm-dd') from dual;
3,字符处理函数
upper:改为大写
SQL> select upper('AaBbCcDd') upper from dual;
lower:改为小写
SQL> select lower('AaBbCcDd') lower from dual;
instr:查询字符在字符串中的位置,无返回0
SQL> select instr('oracle traning','ra') instring from dual;
SUBSTR(string,start,count):取子字符串,从start开始,取count个
SQL> select substr('13088888888',3,8) from dual;
REPLACE('string','s1','s2') string 希望被替换的字符或变量,s1被替换的字符串,s2 要替换的字符串
SQL> select replace('he love you','he','i') from dual;
TRUNC:按照指定的精度截取一个数
SQL> select trunc(124.1666,-2) trunc1,trunc(124.16666,2) from dual;
CONCAT:连接两个字符串;
SQL> select concat('010-','88888888')||'转23' 高乾竞电话 from dual; //010-88888888转23
4,聚集函数
sum求和
avg求平均值
max最大
min最小
nvl(null,0)替代
distinct 去重
浙公网安备 33010602011771号