oracle較常用函式整理

2022-09-19 06:48:09 字數 2761 閱讀 4098

select abs (-100) from dual;--絕對值

select mod (8,5) from dual;--取模,取餘數

select ceil (12.1) from dual;--去上限值

select floor (12.1) from dual;--去下限值

select round (12.4567,3) from dual; -- 四捨五入

select trunc (12.456,2) from dual; -- 擷取,不四捨五入

select trunc (12.456,0) from dual; -- 擷取,不四捨五入(截整)

select length ('asddsa') from dual;--字串長度

select xingm, length (xingm) from t_hq_ryxx;

select xingm, substr (xingm,1,2) from t_hq_ryxx;--擷取,(從第一位開始擷取,截兩位)

select concat ('sa',concat ('sdsd','ddd')) from dual;

select 'sa'||'sdsd'||'ddd' from dual;

--查詢字串

select instr ('abcdef','d') from dual;

select instr ('abcdefdf','d',3) from dual;

select instr ('abcdefdf','d',5) from dual; --數字指定起始位置

select instr ('abcdefdf','dd',3) from dual; --找不到返回0

--轉換大小寫

select upper ('assa'),lower ('sdda') from dual;

select upper ('assa'),lower ('sdda'), initcap ('this is a car') from dual; --initcap 首字母轉換大寫

select replace ('abcdef','ab','123') from dual; --替換

update t_hq_ryxx set xingm = replace (xingm,'三','四') where xingm like '三%'

--填充

select rpad ('aa',8, 'c') from dual;

select rpad ('aba',8, 'de') from dual;

select lpad ('aa',8, 'rc') from dual;

--去空格

select trim (' wfat ') from dual; --去前後空格

select ltrim (' sd1 ') from dual; --去左空格

select rtrim (' sdad ') from dual; --去右空格

--去字首

select trim (leading 'a' from 'asda') from dual; --前邊開始

select trim (trailing 'a' from 'asda') from dual; --右邊開始

select trim (both 'a' from 'asda') from dual; --去前後

--日期型函式

select sysdate from dual;

select add_months(sysdate,2) from dual; --加兩個月

select add_months(sysdate,-2) from dual; --減兩個月

select last_day(sysdate) from dual;

select last_day(sysdate) +1 from dual; --(+)加天數

select last_day(sysdate) -1 from dual; --(-)減天數

--轉換函式

--select cast ('123' as number) from dual;

--select cast ('123' as number) + 123 from dual;

--select cast ('123' as varchar2(4)) from dual; --數字長度不能超過字串長度

--select cast(sysdate as varchar2(10)) from dual;

select to_char(sysdate, 'yyyy-mm-dd')from dual; --日期轉換字串(忽略大小寫)

select to_char(sysdate, 'yy-mm-dd')from dual;

select to_char(sysdate, 'yyyy-dd-mm hh24:mi:ss')from dual;

--select to_char(123.456,'9999.9')from dual;

select to_date('2015-12-11','yyyy-mm-dd') from dual; --字串轉換日期

select to_number('123.456','9999.999') from dual;

select( nianl + gongz) from t_hq_ryxx;

Oracle常用函式整理 decode函式

使用decode判斷字串是否一樣 decode value,if 條件1,then 值1,if 條件2,then 值2,else default 含義為 if 條件1 value then return 值1 elsif 條件2 value then return 值2 elsif 條件n valu...

ORACLE函式整理

語法 translate expr,from str,to str expr 被替換字串 from str 需要替換的字元 to str 被替換的字元 單字元替換,把所有的a替換成b,i替換成s select translate woainia ai bse from dual wobsnsb 當f...

Oracle函式整理

1 select abs 100 from dual 絕對值23 select mod 8,5 from dual 取模,取餘數45 select ceil 12.1 from dual 去上限值67 select floor 12.1 from dual 去下限值89 select round 1...