一,資料轉換類
1 regexp_replace函式,例子,regexp_replace(欄位名,'[^0-9]','' ),所有非數字轉換為空字元。
2 nvl函式,例子,nvl(欄位名,'a'),字段如果為空則轉換為『a』,如果欄位是多個空格,並不會轉換。
3nvl2(a,b,c)函式: 如果a的值不為空,那麼取b的值,如果a的值為空,那麼取c的值(類似三目運算子)
4 trunc函式擷取時間,時間可以為空,不報錯,例子,select * from user where trunc(欄位名) < trunc(sysdate - 7)
5 to_date函式,字串轉時間 例子, to_date('2019-12-23 23:59:59','yyyy-mm-dd hh:mm:ss')
6 to_char 時間轉換為字串,select * from tablename a where to_char(日期字段,'yyyymm')='200312'
7 nvl函式與trunc函式合用,為空時設定時間預設值,例子,select * from user where nvl(trunc(欄位名),to_date('1949/10/01','yyyy/mm/dd')) < trunc(sysdate - 7)
8 translate函式,例子,select translate('1234567','123' ,'abc') from dual 。1替換為a,2替換為b,3替換為c 結果:abc4567 。
如果 沒有對應字元則替換為null;select translate('1234567','123' ,'ab') from dual。3替換為null。結果:ab4567。
9sign(number) : 如果number大於0,sign則返回1;如果number小於0,sign則返回-1;如果number等於0,sign則返回0.
10 substr(str,a,b): 字串擷取函式 ,str :待擷取字串,a :擷取開始位置,b :擷取個數
11 listagg() ..within group() :
select listagg(order_num,'+') within group (order by order_num) names from tab_user where class = '一班'
合併資料,列轉行
12 decode(value,if1,then1,if2,then2,if3,then3,...,else)
13 case when condition then result [when … then …] … [else result] end
select name , age,
case when age>18 then '成年人'
when age<=18 and age>12 then '少年'
when age <=12 and age >6 then '兒童'
else '幼兒'
end as class
from person ;
14 instr :字段包含某個字串。 例子: select * from students where instr(address, 'beijing') > 0
二,知識點
1,字段排序,並且null值排最後,例子,select * from user order by aaa desc nulls last
未完待續。。。。。
ORACLE常用函式總結
時常忘記,但是用得十分頻繁 nvl nvl exp1,exp2 exp1為null,返回exp2,exp1不為null,返回exp1 主要使用者轉換null值 nullif nullif exp1,exp2 exp1 exp2,返回空,不等返回exp1 coalesce coalesce exp1,...
oracle常用函式總結
目錄 nvl2.1 decode 函式簡介 1 sign 函式.3 oracle 中的union union all intersect minus 3oracle trim 函式.7 oracle trunc 函式的用法 8 lpad 用法.10 oracle translate 詳解 例項.10...
Oracle常用函式總結
1 concat和 concat連線兩個字元,可連線多個字元 select concat a b from dual ab select a b c from dual abc 2 replace 將要更改的字串 被替換掉的字串 替換字串 select replace abc b 1 from du...