oracle常用函数

一、运算符
算术运算符:+ - * / 可以在select 语句中使用
连接运算符:|| select deptno|| dname from dept; 
比较运算符:> >= = != < <= like between is null in
逻辑运算符:not and or 
集合运算符: intersect ,union, union all, minus 
要求:对应集合的列数和数据类型相同
     查询中不能包含long 列
     列的标签是第一个集合的标签
     使用order by时,必须使用位置序号,不能使用列名

二、时间相关
select to_char(to_date('2016-12-22','yyyy-mm-dd'),'day') from dual; --指定时间是周几
select floor(sysdate - to_date('20020405','yyyymmdd')) from dual; --两个日期间的天数
select TO_CHAR(SYSDATE,'DDD'),sysdate from dual; --一年的第多少天

--当前时间的时分秒(oracle数据库时间哦)

三. 字符函数(可用于字面字符或数据库列)

select instr('abcfdgfdhd','fd') from dual;--截取 4
select 'HELLO'||'hello world' from dual;--拼接 HELLOhello world
select ltrim(' abc') s1,rtrim('zhang ') s2,trim(' zhang ') s3 from dual--;去掉空格
select trim(leading 9 from 9998767999) s1,trim(trailing 9 from 9998767999) s2,trim(9 from 9998767999) s3 from dual;--去掉前后坠
select ascii('a') from dual;--转ascii
select chr(97) from dual;--获取字母
select length('abcdef') from dual;--计算长度
select lower('ABC') s1,upper('def') s2, initcap('efg') s3 from dual; --initcap(首字母变大写) ,lower(变小写),upper(变大写)
select translate('abc','b','xc') from dual; -- x是1位 结果是axc
select lpad('func',15,'=') s1, rpad('func',15,'-') s2 from dual;--lpad [左添充] rpad [右填充](用于控制输出格式)
decode[实现if ..then 逻辑]
case[实现switch ..case 逻辑]

后面的有时间在完善 整理不易 转发请标明出处

posted @ 2016-12-22 17:46  下页小希  阅读(181)  评论(0编辑  收藏  举报