oracle 函数集 整理
2010-08-04 15:09
295 查看
-------------------- --| 字符函数 | -------------------- --字符串连接 asssbsss Select concat('asss','bsss') from dual; select 'a'||'b' from dual; --单词首字母大写 Red Hat select initcap('red hat') from dual; --字符串截取 结果为 def Select substr('abcdef',length('abcdef')-2) from dual; Select substr('abcdef',-3,3) from dual; --取字符串长度 6 select length('123456') from dual; --字符替换 111111 select replace('aaaaaa','a','1') from dual; --查找子串的位置 8 select instr('hello world','or') from dual; --左侧填充* 总长度为8 结果为 ***muger select lpad('muger',8,'*') from dual; --右侧填充 muger*** select rpad('muger',8,'*') from dual; --过滤首尾空格 select trim(' muger ') from dual; --////////////单行函数////////////////// -------------------- --| 数值函数 | -------------------- --四舍五入 select round(456.6,-2) from dual; --500 select round(412.316,2) from dual; --412.32 --取余数 select mod(33,5) from dual; --33mod5 = 3 --取下界 直接舍掉 不四舍五入 select trunc(477.13,-2) from dual; --400 -------------------- --| 日期函数 | -------------------- --计算相差月份 结果单位为(月)sysdate为当前系统时间 select months_between(sysdate,sysdate-31) from dual; -- 1 --日期月份加 n select add_months(sysdate,1) from dual; --sysdate=2010-8-3 17:10:29 返回结果为 2010-9-3 17:10:29 --得到下一个 星期三 那天此时的日期 select next_day(sysdate,3) from dual; -- select next_day(sysdate,'星期三') from dual;--同上 --获取当月最后一天 此时的日期 select last_day(sysdate) from dual; -------------------- --| 转换函数 | -------------------- --日期到字符串的转换 select to_char(sysdate,'yyyy') from dual; --取年'yyyy' 月 'mm' 日 'dd' 时 'hh' 分 'mm' 秒 'ss' select to_char(sysdate-20,'fmyyyy-mm-dd') from dual; --单月单日不补0 例如 2010-8-18 而不是 2010-08-18 select to_char(45641313,'L999,999,999') from dual;-- ¥45,641,313 select to_char(sysdate-20,'d') from dual;--返回星期 --字符串转数字 select to_number('13')+to_number('14') from dual; --27 --字符串转日期 Select to_date('20090210','fmyyyyMMdd') from dual; --2009210 -------------------- --| 通用函数 | -------------------- --如果为NULL 用0替换 select nvl(null,0) from dual; --0 --如果表达式exp1与exp2的值相等则返回null,否则返回exp1的值 select nullif(12,12) from dual; --null --exp1是null 返回exp3 否则返回exp2 select nvl2(3,12+5,8) from dual; --17 --依次考察各参数表达式,遇到非null值即停止并返回该值。 select coalesce(null,null,null,2,null) from dual; --2 --case表达式 select a,b, case c when 10 then '十' when 20 then '二十' when 30 then '三十' else '未知' end 数字 from (select 20 as a,35 as b,30 as c from dual); --decode表达式 --结果case select a,b, decode(c, 10,'十', 20,'二十', 30,'三十', '未知') 数字 from (select 20 as a,35 as b,30 as c from dual);
相关文章推荐
- Oracle常用函数速查-我整理的笔记
- ORACLE正则表达式函数详解--转载整理
- Oracle 11G函数整理(层次函数)
- 【整理】Oracle常用函数
- oracle高级函数(待整理)
- 110个Oracle常用函数整理汇总【转】
- MSSql 与Oracle常用函数整理(二)
- oracle函数整理---sign函数
- 【Oracle 学习笔记】Day 1 常用函数整理(转换、DeCode),表的外键
- Oracle常用函数整理
- 110个Oracle常用函数整理汇总
- 对Oracle函数的整理 count substr
- oracle 函数整理(一)
- oracle 小函数整理
- SQLServer和Oracle的常用函数对比(收集,不断整理中)
- Oracle函数整理
- 110个Oracle常用函数整理汇总
- Oracle 11G函数整理(环境标识函数)
- oracle日期处理函数整理
- oracle 小函数整理