sql函式:
單行函式: 日期函式 數字函式 字元函式 轉換函式
分組函式
分析函式
[size=medium][b]日期函式[/b][/size]
--當前日期增加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;
[size=medium][b]字元函式[/b][/size]
--第乙個字母變成大寫
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;
[size=medium][b]數字函式[/b][/size]
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
[size=medium][b]轉換函式[/b][/size]
select to_char(sysdate, 'yyyy"-"fmmm"-"fmdd hh24:mi:ss') from dual;
select to_char(sal, 'c99999') from emp;
[b]oracle trunc用法[/b]
select trunc(sysdate,'day') result from dual
=本週第一天
select trunc(sysdate,'yy') result from dual
=本年第一天
select trunc(sysdate,'yy')-1 result from dual
=上年最後一天
select trunc(sysdate,'mm') result from dual
=本月第一天
select trunc(sysdate,'dd') result from dual
當天oracle to_char(sysdate,'d')
ddd是該天在一年內的第多少天,d是在一周內第幾天,dd是乙個月內的
dy :day of week abbreviated mon, tue, fri
day :day of week spelled out monday, tuesday, friday
d :day of week (1–7) 1,2,3,4,5,6,7--注意:每星期的第1天是」星期日「
dd :day of month (1–31) 1,2,3,4…31
ddd :day of year (1–366) 1,2,3,4…366
Oracle常用函式
一 row number over 資料甲 1 select column name column name,data type,2 row number over partition by column name order by column name row num 3 from test c...
Oracle常用函式
數學函式 1.絕對值 o select abs 1 value from dual 2.取整 大 o select ceil 1.001 value from dual 3.取整 小 o select floor 1.001 value from dual 4.取整 擷取 o select trun...
oracle常用函式
1.concat c1,c2均為字串,函式將c2連線到c1的後面,如果c1為null,將返回c2.如果c2為null,則返回c1,如果c1 c2都為null,則返回null。他和操作符 返回的結果相同 select concat slobo svoboda username from dualuse...