ORACLE常用函式總結

2021-08-27 13:29:07 字數 2183 閱讀 5236

時常忘記,但是用得十分頻繁

nvl:nvl(exp1,exp2)exp1為null,返回exp2,exp1不為null,返回exp1

主要使用者轉換null值

nullif:nullif(exp1,exp2)exp1=exp2,返回空,不等返回exp1

coalesce:coalesce(exp1,exp2,exp3,....)返回列表中第乙個非空表示式

nvl2:nvl2(exp1,exp2,exp3)exp1不為空,返回exp2,exp1為空,返回exp3

mod:求餘數,剛才寫一段plsql,不記得這個函式,準備自己實現乙個,鬱悶

to_date:轉換日期

to_number:轉換數字

trunc:

--oracle trunc()函式的用法

/**************日期********************/

1.select trunc(sysdate) from dual --2011-3-18 今天的日期為2011-3-18

2.select trunc(sysdate, 'mm') from dual --2011-3-1 返回當月第一天.

3.select trunc(sysdate,'yy') from dual --2011-1-1 返回當年第一天

4.select trunc(sysdate,'dd') from dual --2011-3-18 返回當前年月日

5.select trunc(sysdate,'yyyy') from dual --2011-1-1 返回當年第一天

6.select trunc(sysdate,'d') from dual --2011-3-13 (星期天)返回當前星期的第一天

7.select trunc(sysdate, 'hh') from dual --2011-3-18 14:00:00 當前時間為14:41

8.select trunc(sysdate, 'mi') from dual --2011-3-18 14:41:00 trunc()函式沒有秒的精確

/***************數字********************/

/*trunc(number,num_digits)

number 需要截尾取整的數字。

num_digits 用於指定取整精度的數字。num_digits 的預設值為 0。

trunc()函式擷取時不進行四捨五入

*/9.select trunc(123.458) from dual --123

10.select trunc(123.458,0) from dual --123

11.select trunc(123.458,1) from dual --123.4

12.select trunc(123.458,-1) from dual --120

13.select trunc(123.458,-4) from dual --0

14.select trunc(123.458,4) from dual --123.458

15.select trunc(123) from dual --123

16.select trunc(123,1) from dual --123

17.select trunc(123,-1) from dual --120

substr:擷取字串

add_months:

oracle add_months(time,months)函式可以得到某一時間之前或之後n個月的時間

如 select add_months(sysdate,-6) from dual;

該查詢的結果是當前時間半年前的時間

select add_months(sysdate,6) from dual;

該查詢的結果是當前時間半年後的時間

select distinct(t.mobile) from twaplogon t where to_char(t.logontime,'yyyy-mm')=to_char(add_months(sysdate,-1),'yyyy-mm')

instr(char, search_string, startpos, occurrence):返回擷取字串在源串的位置

cast:

rpad:

lengthb:

unistr:

hextoraw:

rawtohex:

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...

oracle常用函式總結

函式總結 此函式的作用就是字段型別轉化為字元型的函式,此函式可用於復合查詢,如 前台僅有乙個輸入框,後台可以根據此輸入值進行貨品的品名,id,助記碼進行查詢。在資料庫中品名,助記碼皆為string型別的數值,而id卻為數值型的,所以此時可以使用to char進行綜合查詢。日期之間的比較 a.將str...