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;

oracle常见的函数的更多相关文章

  1. Access、SQLServer、Oracle常见SQL语句应用区别

    Access.SQLServer.Oracle常见SQL语句应用区别 关劲松 PMP 如果要兼容Access.SQL Server.Oracle三个数据库版本:我们在编写SQL语句的过程中,尽量使用一 ...

  2. 分享:Oracle 系统变量函数用法说明

    在Oracle数据库中,Oracle系统变量函数是经常会使用到的函数,分享下Oracle系统变量函数的用法. Oracle函数多种多样,系统变量函数就是其中之一,介绍三种最常见的系统变量函数. Ora ...

  3. Oracle 中 decode 函数用法

    Oracle 中 decode 函数用法 含义解释:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译 ...

  4. Oracle Tuning 基础概述01 - Oracle 常见等待事件

    对Oracle数据库整体性能的优化,首先要关注的是在有性能问题时数据库排名前几位等待事件是哪些.Oracle等待事件众多,随着版本的升级,数量还在不断增加,可以通过v$event_name查到当前数据 ...

  5. 重写Oracle的wm_concat函数,自定义分隔符、排序

    oracle中,wm_concat函数是一个聚合函数,和mysql中的group_concat函数类似,不过group_concat函数比较强大,可以定义分隔符和排序,当然所谓强大是相对的,这里假使我 ...

  6. 【原创】ORACLE常见使用问题解决

    ORACLE常见使用问题解决 一.安装了oracle客户端后,发现plsql客户端找不到之前已经配置过的TNS连接信息 或许大家再使用ORACLE软件的过程中,经常会遇到这样的问题: 问题现象描述: ...

  7. Oracle日期时间函数大全

    ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 显示值:07 yyy three digits ...

  8. Oracle过程及函数的参数模式,In、out、in out模式

    Oracle过程及函数的参数模式 In.out.in out模式 在Oracle中过程与函数都可以有参数,参数的类型可以指定为in.out.in out三种模式. 三种参数的具体说明,如下图所示: ( ...

  9. oracle的substr函数的用法

    oracle的substr函数的用法 取得字符串中指定起始位置和长度的字符串   substr( string, start_position, [ length ] ) 如:     substr( ...

随机推荐

  1. eclipse的一些使用

    1.恢复默认视图 window->perspective->open perspective ->open java 2.打开其他的一些视图,比如server(tomcat,目前使用 ...

  2. jqGrid colModel 参数(来自中文手册)

    jqGrid colModel 参数 ColModel 是jqGrid里最重要的一个属性,设置表格列的属性. 属性 数据类型 备注 默认值 align string left, center, rig ...

  3. C++学习书籍评价

    1.C++程序设计-现代方法 本书非常适合学习了C语言基础,想跨步到C++学习的同学,前20章都是C基础的回顾,简直不要太简单,后面的课后习题花了半个小时做完了,没怎么出错,嗯,我的C语言基础还是可以 ...

  4. ORA-01789: 查询块具有不正确的结果列数

    问题描述 ORA-01789: 查询块具有不正确的结果列数 问题原因 sql语句用union时的 两个语句查询的字段不一致,好像顺序也要保持一致才行

  5. springboot13(redis缓存)

    redis做springboot2.x的缓存 1.首先是引入依赖 <dependency> <groupId>org.springframework.boot</grou ...

  6. blur()低通滤波

    blur()函数可以用标准化的盒式过滤器来平滑图像. C++ API: 相关官网资料: https://docs.opencv.org/3.4.1/d4/d86/group__imgproc__fil ...

  7. java基础(十一)之抽象类和抽象函数

    1.抽象函数的语法特征2.抽象类的语法特征3.抽象类的作用 抽象函数 只有函数的定义,没有函数体的函数被称为抽象函数: abstract void func(); 抽象类 使用abstract定义的类 ...

  8. SDP协议介绍

    一.SDP协议介绍 SDP 完全是一种会话描述格式 ― 它不属于传输协议 ― 它只使用不同的适当的传输协议,包括会话通知协议(SAP).会话初始协议(SIP).实时流协议(RTSP).MIME 扩展协 ...

  9. C++算法导论第九章O(n)期望选择序列第i小的数字

    #include<iostream> #include<vector> #include<algorithm> #include<time.h> usi ...

  10. python接口自动化测试 - requests库的post请求进行文件下载

    前言 之前讲了文件上传,当然就有文件下载啦 文件下载操作步骤 极其简单,将二进制格式的响应内容存进本地文件中,根据需要下载的文件的格式来写文件名即可 down_url = 'https://www.i ...