日期:2014-05-16 浏览次数:20546 次
--当前日期增加12个月 select add_months(sysdate, 12) from dual; --两个日期相差的月份 select abs(months_between('22-9月-10', '22-9月-11')) from dual; --返回给定日期最后一天 select last_day('11-2月-10') from dual; --结果: 2010-2-28 --取出年份 select extract(year from sysdate) from dual;
--第一个字母变成大写 select initcap('hee') from dual; --从左面删除'ab' select ltrim('abhee', 'ab') from dual; --从右面删除'hee' select rtrim('abhee', hee) from dual; --对应字符替换 select translate('Line', 'L', 'D') from dual; --Dine --replace select replace('LineL', 'L', 'Ds') from dual; --DsineDs --从第二个字符开始找,第二次出现‘a’的位置 select instr('abcdabab', 'a', 2, 2) from dual; --7 --从第二个字符开始取 取4个字符出来 select substr('abcdefg', 2 , 4) from dual; --bcde --连接函数 select concat('pp', 'oo') from dual; --ppoo --chr和ascii select chr(65) from dual; --A select ascii('A') from dual; --65 --lpad和rpad select lpad('abcde', 10, '*') from dual; --*****abcde --trim select trim(00 from 7600) from dual; --76 select trim('0' from '00ab00') from dual; --'ab' select trim(leading '0' from '00ab00') from dual; --'ab00' select trim(trailing '0' from '00ab00') from dual; --'00ab' --decode select ename, job, sal, decode(job, 'CLERK', sal*1.5, 'SALESMAN', sal*2.0, sal) as "new salary" from emp;
select ceil(44.1) from dual; --45 select floor(44.6) from dual; --44 select round(30.456, 2) from dual; --30.46 select trunc(30.456, 2) from dual; --30.45
select to_char(sysdate, 'YYYY"-"fmMM"-"fmDD HH24:MI:SS') from dual; select to_char(sal, 'C99999') from emp;