select ASCII('A'),CHR(65) from dual; --65 A select CONCAT('Hello ','World'),'Hello '||'World' from dual; --Hello World Hello World select INITCAP('I am a good boy!') from dual; --I Am A Good Boy! select INSTR('Hello World...','World',1,1),INSTR('Hello World...','World',-1,1) from dual; --7 7 select LENGTH('Hello') from dual; --5 select LOWER('Hello'),UPPER('Hello') from dual; --hello HELLO select LTRIM('###Hello##','#'),RTRIM('###Hello##','#') from dual; --Hello## ###Hello select TRIM(' tech '),TRIM(' ' from ' tech '),TRIM(leading '0' from '000123'),TRIM(trailing '1' from 'Tech1'),TRIM(both '1' from '123Tech111') from dual; --tech tech 123 Tech 23Tech select REPLACE('Hello World','World','Beijing'),REPLACE('Hello World','World') from dual; --Hello Beijing Hello select SUBSTR('Hello World',1,5),SUBSTR('Hello World',6) from dual; --Hello World
3.2 数字类函数
select CEIL(7.3) from dual; --8 select ROUND(123.4567,2),ROUND(123.4567),ROUND(123.4567,-2) from dual; --123.46 123 100 select POWER(2,3) from dual; --8 select MOD(10,3) from dual; --1 select ABS(-10) from dual; --10 select FLOOR(7.3) from dual; --7
3.3 日期和时间类函数
select SYSDATE from dual; --2013/7/27 星期六 20:59:34 select MONTHS_BETWEEN(TO_DATE('2013-7-27','yyyy-mm-dd'),TO_DATE('2013-12-7','yyyy-mm-dd')) from dual; ---4.35483870967741935483870967741935483871 select LAST_DAY(TO_DATE('2013-7-27','yyyy-mm-dd')) from dual; --2013/7/31 星期三 select NEXT_DAY(TO_DATE('2013-7-27','yyyy-mm-dd'),'星期二') from dual; --2013/7/30 星期二 select ADD_MONTHS(TO_DATE('2013-7-27','yyyy-mm-dd'),2) from dual; --2013/9/27 星期五
3.4 转换类函数
参考:http://www.java2s.com/Tutorial/Oracle/0300__Conversion-Functions/0140__TO_CHAR.htm
参考:http://www.java2s.com/Tutorial/Oracle/0300__Conversion-Functions/0160__TO_NUMBER.htm
select TO_CHAR(sysdate,'yyyy-mm-dd hh24:mi:ss'),TO_CHAR(12345.67, '$99,999.99') from dual; --2013-07-27 21:00:12 $12,345.67 select TO_DATE('2013-7-27 12:43:32','yyyy-mm-dd hh24:mi:ss') from dual; --2013/7/27 星期六 12:43:32 select TO_NUMBER('98.32'),TO_NUMBER('$98.32','$999.99'),TO_NUMBER('1E+6','9.99EEEE') from dual; --98.32 98.32 1000000
3.5 聚合类函数
select AVG(BROWSE_COUNT) from BBSDETAIL; --2378.136894183198040251693164897449445218 select MAX(BROWSE_COUNT) from BBSDETAIL; --10072 select MIN(BROWSE_COUNT) from BBSDETAIL; --0 select SUM(BROWSE_COUNT) from BBSDETAIL; --99804855
3.6 其它辅助函数
select DECODE('CM','AM','RE1','BM','RE2','CM','RE3','UNKNOWN') from dual; --RE3 select GREATEST(12,34,55,1,23,12) from dual; --55 select LEAST(12,34,55,1,23,12) from dual; --1 select NULLIF('Hello','World'),NULLIF('Hello','Hello') from dual; --Hello select NVL('Hello','World'),NVL(null,'World') from dual; --Hello World