1、字符函数

-- initcap函数只针对英文
select * from tb_user where user_name = initcap('张三'); -- ltrim 左剪切
select ltrim('helloworld','h') from dual; ---- elloworld select ltrim('helloworld','ah') from dual; ---- elloworld select ltrim('helloworld','l') from dual;---- helloworld select ltrim('helloworld','hl') from dual; ---- elloworld select ltrim('helloworld','he') from dual; -- rtrim 右剪切
#translate 翻译 一个字符只能匹配一个字符
select translate('helloworld','h','A') from dual;-- Aelloworld select translate('helloworld','hl','AG') from dual;-- AeGGoworGd select translate('helloworld','lh','AG') from dual;-- GeAAoworAd select translate('helloworld','l','AG') from dual;-- heAAoworAd -- repalce 多个字符可以替换一个字符或者多个字符
select replace('hello world','e','你好') from dual;-- h你好llo world -- instr -->查询子字符串的位置
select instr('hello world','w') from dual;-- 7 从1开始 select instr('hello world','rl') from dual;-- -- substr截取字符串
select substr('hello world',2,3) from dual; -- 从2开始截取,取3个字符 select concat('hello','world') from dual;#helloworld select concat('hello',null) from dual;#hello

常用的数字函数

-- abs --->求绝对值
select abs(-10) from dual;--
select abs(-0) from dual; -- -- ceil向上取整 ceil-->天花板函数
select ceil(3.14) from dual; --
select ceil(-3.14) from dual;-- -3 -- sign 取符号
select sign(100) from dual; --
select sign(-4343) from dual; -- -1
select sign(0) from dual;--
select sign(-0) from dual;-- select floor(3.14) from dual;--
select floor(4) from dual;--
select floor(-3.14) from dual; -- -4 -- power(m,n) m的n次幂
-- 求2的3次方
select power(2,3) from dual;-- -- mod取余
-- 11/2的余数
select mod(11,2) from dual;-- -- round 四舍五入
select round(3.14) from dual;--
select round(3.5) from dual;-- -- trunc 截取数字
select trunc(100.5466,3) from dual;-- 100.546
-- sqrt 求平方根
select sqrt(9) from dual;--

常用的日期函数

--      日期函数
-- months_between--->返回两个日期之间的月的数量
select months_between('8-8月-08','4-7月-17') from dual;
select months_between('4-7月-17','8-8月-08') from dual; -- add_months 添加月份
select add_months('4-7月-17',4) from dual;
select add_months('31-7月-17',-5) from dual;-- 2017/2/28 -- next_day
select next_day('4-7月-17','星期四') from dual;
select next_day('4-7月-17','星期日') from dual;-- 2017/7/9 -- last_day --->获取每个月最后一天的日期
select last_day('4-7月-17') from dual;
select last_day('2-2月-08') from dual;#2008/2/29 -- round--->对日期进行四舍五入 四舍:当年的1月1日 五入:下一年的1月1日
-- 年中的四舍五入以7为界限的!!
select round('4-7月-17','year') from dual;
select round(sysdate,'year') from dual;
select round(to_date('30-6月-17'),'year') from dual;
-- 对月份进行四舍五入: 要么舍为当月的第一天,或者下一月的第一天 以16为界限
select round(to_date('4-7月-17'),'month') from dual;
select round(to_date('16-7月-17'),'month') from dual;
select round(to_date('15-2月-17'),'month') from dual;-- 2017/2/1 -- 对具体日期进行四舍五入-星期
-- 当周的第一天或者下周的第一天
-- 老外认为周日是一周的开始!!
-- 以周四为界限
select round(to_date('4-7月-17'),'day') from dual;#2017/7/2 --->星期天
select round(to_date('6-7月-17'),'day') from dual; -- trunc 截取日期
-- 对于年来说:截为当年的1月1日
select trunc(to_date('4-7月-17'),'year') from dual;#2017/1/1
select trunc(to_date('12-12月-17'),'year') from dual;#2017/1/1
-- 对于月份来说:截为当月的1日
select trunc(to_date('4-7月-17'),'month') from dual;#2017/7/1
-- 对于具体的日期day来说是截取为当前日期的周日
select trunc(to_date('4-7月-17'),'day') from dual;#2017/7/2

-- to_char -->把其他类型转为字符串
select to_char(sysdate) from dual; -- q的模式是第几季度
select to_char(sysdate,'q') from dual;-- 3
-- 获取当天日期在年中的天数
select to_char(sysdate,'ddd') from dual;-- 185天
select to_char(sysdate,'dd') from dual; --
select to_char(sysdate,'d') from dual;-- 3 星期三--对于老外 -- 当前日期在年中是第几周了
select to_char(sysdate,'ww') from dual;--
select to_char(sysdate,'w') from dual;-- -- to_date --->把一定格式的字符串转换为日期对象
-- yyyy-mm-dd
select to_date('2017-7-4','yyyy-mm-dd') from dual;
--hh 默认为12小时
select to_date('2017-7-4 14:05:11','yyyy-mm-dd hh24:mi:ss') from dual;

常用的其他函数

1)获取随机字符串
select dbms_random.string('l',2) from dual; -- l-->lower 2-->字符串的长度
select dbms_random.string('u',2) from dual; --> u-->upper 大写

2) oracle中的随机数字
select dbms_random.value(0,1) from dual; -- 0~1 但是取不到1
select trunc(dbms_random.value(1,10),0) from dual;

最新文章

  1. 【BZOJ-2006】超级钢琴 ST表 + 堆 (一类经典问题)
  2. Java-简陋的图书管理
  3. 在window server 2008 64位系统上 发布网站的过程中遇到的问题
  4. windows下netstat -aon命令
  5. Maven中pom.xml常用元素说明
  6. 三角形(hd1249)
  7. 基于visual Studio2013解决面试题之0208二叉搜索树后序遍历序列
  8. webpack学习笔记(四)
  9. vue-循环并获取dom元素
  10. Angular 个人深究(四)【生命周期钩子】
  11. 一个灵活的AssetBundle打包工具
  12. DB通用类:Sqlite通用类库
  13. 2.7 Sobel导数
  14. jmeter body 中文显示为乱码解决
  15. kotlin 学习感受
  16. OpenResty 最佳实践 (1)
  17. go语言入门(三)
  18. shiro+redis实现session共享
  19. 数字图像处理实验(6):PROJECT 04-02,Fourier Spectrum and Average Value 标签: 图像处理MATLABfft 2017-05-07 23:1
  20. 在项目引用里添加上对Microsoft Word 11.0 object library的引用

热门文章

  1. Gin_入门
  2. Educational Codeforces Round 80 A-E简要题解
  3. linux复制,网络报错
  4. S3C2440之存储控制器学习记录
  5. xampp 软件端口占用
  6. maven web报错:org.apache.jasper.JasperException: Unable to compile class for JSP
  7. intellij idea设置打开多个文件显示在多行tab上
  8. Java下载文件时文件名中的中文变成下划线,其他正常
  9. zk zkCli shell命令
  10. vue后台模板推荐