相关函数
相关函数
数字函数
- select mod(100,3) from dual;--求余,如果除数为0的情况下直接返回被除数
(100,3) 输出结果为1。(100,0)输出结果为100 - select ceil(2.2) from dual;--进一取整
输出结果为3 - select floor(2.9) from dual;--直接取整
输出结果为2 - select round(350.335,2) from dual;--精确小数位,同时进行四舍五入(当逗号后面为负数时,精确整数位)
(350.335,2)输出结果为350.34
(35555,-1)输出结果为35560
(35555,-2)输出结果为35600
(35555,-3)输出结果为36000 - select trunc(350.335,-2) from dual;--直接精确小数位 方法为截取精确,不四舍五入(当逗号后面为负数时,精确整数位)
(350.335,-2)输出结果为300
(350.335,2)输出结果为350.33
字符串函数
- select upper(last_name) from s_emp;--查到的数据全部大写
- select lower(last_name) from s_emp;--查到的数据全部小写
- select concat('今天天气','不错') from dual;--拼接两个字符串concat(字符串1,字符串2)
- select replace('今天天气不错','天气','心情') from dual;--替换函数replace(当前的字符串,需要替换的字符串,替换的新字符串)
- select substr('今天天气不错',3,2) from dual;--substr截取函数(要截取的字符串,起点[从1开始包括起点],截取的个数)
- select length('今天天气不错') from dual;--字符串长度
时间函数
- alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';--更改时间的标准格式
- select sysdate from dual;--当前时间
- select sysdate+1/(24*60) from dual;--一分钟后的时间
- select last_day(sysdate) from dual;--当月最后一天
- select add_months(sysdate,-4) from dual;--当月对应的4个月前
- select sysdate-(to_date('2016/12/06','yyyy/mm/dd')) from dual;--两个日期之间的天数
- select months_between(sysdate , to_date('2017/11/06','yyyy/mm/dd')) from dual;--两个日期之间的月数
- select to_char(sysdate,'day') from dual;--求某天是星期几
- select to_char(sysdate,'yyyy-mm-dd') from dual;--对sysdate取对应的年月日时分秒,写几个取几个
- select trunc(sysdate,'yyyy') from dual;--获得指定字段及字段前的日期其余日期默认为1月1号0时0分0秒[逗号后面只能写一个日期字段]
- select to_char(sysdate,'yyyy-mm-fmdd') from dual;--对取得月份或日前加fm可以去掉前面的0
转换函数
- select to_date(20171206111255) from dual;--将字符串转化日期(在标准格式的前提下)
- select to_date('2017/01/11','yyyy/mm/dd') from dual;--按照某种格式进行日期转化
- select to_char(111111,'L000,000') from dual;--对工资格式进行转换L代表人民币符号
相关脚本链接
链接:https://pan.baidu.com/s/1dF50DJr 密码:cfrp
未完待续...
作者:btxd 链接:http://www.cnblogs.com/btxd/ 欢迎交流问题

浙公网安备 33010602011771号