某種意義上也可以說是 sqlserver 和 mysql 的常用函數(shù)對(duì)比。
數(shù)學(xué)函數(shù)
1.絕對(duì)值 S:select abs(-1) value O:select abs(-1) value from dual
2.取整(大) S:select ceiling(-1.001) value O:select ceil(-1.001) value from dual
3.取整(小) S:select floor(-1.001) value O:select floor(-1.001) value from dual
4.取整(截。 S:select cast(-1.002 as int) value O:select trunc(-1.002) value from dual
5.四舍五入 S:select round(1.23456,4) value 1.23460 O:select round(1.23456,4) value from dual 1.2346
6.e為底的冪 S:select Exp(1) value 2.7182818284590451 O:select Exp(1) value from dual 2.71828182
7.取e為底的對(duì)數(shù) S:select log(2.7182818284590451) value 1 O:select ln(2.7182818284590451) value from dual; 1
8.取10為底對(duì)數(shù) S:select log10(10) value 1 O:select log(10,10) value from dual; 1
9.取平方 S:select SQUARE(4) value 16 O:select power(4,2) value from dual 16
10.取平方根 S:select SQRT(4) value 2 O:select SQRT(4) value from dual 2
11.求任意數(shù)為底的冪 S:select power(3,4) value 81 O:select power(3,4) value from dual 81
12.取隨機(jī)數(shù) S:select rand() value O:select sys.dbms_random.value(0,1) value from dual;
13.取符號(hào) S:select sign(-8) value -1 O:select sign(-8) value from dual -1
14.圓周率 S:SELECT PI() value 3.1415926535897931 O:不知道
15.sin,cos,tan 參數(shù)都以弧度為單位 例如:select sin(PI()/2) value 得到1(SQLServer)
16.Asin,Acos,Atan,Atan2 返回弧度
17.弧度角度互換(SQLServer,Oracle不知道) DEGREES:弧度-〉角度 RADIANS:角度-〉弧度
數(shù)值間比較
18. 求集合最大值 S:select max(value) value from (select 1 value union select -2 value union select 4 value union select 3 value)a
O:select greatest(1,-2,4,3) value from dual
19. 求集合最小值 S:select min(value) value from (select 1 value union select -2 value union select 4 value union select 3 value)a
O:select least(1,-2,4,3) value from dual
20.如何處理null值(F2中的null以10代替) S:select F1,IsNull(F2,10) value from Tbl O:select F1,nvl(F2,10) value from Tbl
21.求字符序號(hào) S:select ascii('a') value O:select ascii('a') value from dual
22.從序號(hào)求字符 S:select char(97) value O:select chr(97) value from dual
23.連接 S:select '11'+'22'+'33' value O:select CONCAT('11','22') 33 value from dual
23.子串位置 --返回3 S:select CHARINDEX('s','sdsq',2) value O:select INSTR('sdsq','s',2) value from dual
23.模糊子串的位置 --返回2,參數(shù)去掉中間%則返回7 S:select patindex('%d%q%','sdsfasdqe') value O:oracle沒發(fā)現(xiàn),但是instr可以通過第四個(gè)參數(shù)控制出現(xiàn)次數(shù) select INSTR('sdsfasdqe','sd',1,2) value from dual 返回6
24.求子串 S:select substring('abcd',2,2) value O:select substr('abcd',2,2) value from dual
25.子串代替 返回aijklmnef S:SELECT STUFF('abcdef', 2, 3, 'ijklmn') value O:SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dual
26.子串全部替換 S:沒發(fā)現(xiàn) O:select Translate('fasdbfasegas','fa','我' ) value from dual
27.長度 S:len,datalength O:length www.knowsky.com 28.大小寫轉(zhuǎn)換 lower,upper
29.單詞首字母大寫 S:沒發(fā)現(xiàn) O:select INITCAP('abcd dsaf df') value from dual
30.左補(bǔ)空格(LPAD的第一個(gè)參數(shù)為空格則同space函數(shù)) S:select space(10)+'abcd' value O:select LPAD('abcd',14) value from dual
31.右補(bǔ)空格(RPAD的第一個(gè)參數(shù)為空格則同space函數(shù)) S:select 'abcd'+space(10) value O:select RPAD('abcd',14) value from dual
32.刪除空格 S:ltrim,rtrim O:ltrim,rtrim,trim
33. 重復(fù)字符串 S:select REPLICATE('abcd',2) value O:沒發(fā)現(xiàn)
34.發(fā)音相似性比較(這兩個(gè)單詞返回值一樣,發(fā)音相同) S:SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe') O:SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe') from dual SQLServer中用SELECT DIFFERENCE('Smithers', 'Smythers') 比較soundex的差 返回0-4,4為同音,1最高
日期函數(shù) 35.系統(tǒng)時(shí)間 S:select getdate() value O:select sysdate value from dual
36.前后幾日 直接與整數(shù)相加減
37.求日期 S:select convert(char(10),getdate(),20) value O:select trunc(sysdate) value from dual select to_char(sysdate,'yyyy-mm-dd') value from dual
38.求時(shí)間 S:select convert(char(8),getdate(),108) value O:select to_char(sysdate,'hh24:mm:ss') value from dual
39.取日期時(shí)間的其他部分 S:DATEPART 和 DATENAME 函數(shù) (第一個(gè)參數(shù)決定) O:to_char函數(shù) 第二個(gè)參數(shù)決定
參數(shù)---------------------------------下表需要補(bǔ)充 year yy, yyyy quarter qq, q (季度) month mm, m (m O無效) dayofyear dy, y (O表星期) day dd, d (d O無效) week wk, ww (wk O無效) weekday dw (O不清楚) Hour hh,hh12,hh24 (hh12,hh24 S無效) minute mi, n (n O無效) second ss, s (s O無效) millisecond ms (O無效) ----------------------------------------------
40.當(dāng)月最后一天 S:不知道 O:select LAST_DAY(sysdate) value from dual
41.本星期的某一天(比如星期日) S:不知道 O:SELECT Next_day(sysdate,7) vaule FROM DUAL;
42.字符串轉(zhuǎn)時(shí)間 S:可以直接轉(zhuǎn)或者select cast('2004-09-08'as datetime) value O:SELECT To_date('2004-01-05 22:09:38','yyyy-mm-dd hh24-mi-ss') vaule FROM DUAL;
43.求兩日期某一部分的差(比如秒) S:select datediff(ss,getdate(),getdate()+12.3) value O:直接用兩個(gè)日期相減(比如d1-d2=12.3) SELECT (d1-d2)*24*60*60 vaule FROM DUAL;
44.根據(jù)差值求新的日期(比如分鐘) S:select dateadd(mi,8,getdate()) value O:SELECT sysdate+8/60/24 vaule FROM DUAL;
45.求不同時(shí)區(qū)時(shí)間 S:不知道 O:SELECT New_time(sysdate,'ydt','gmt' ) vaule FROM DUAL;
-----時(shí)區(qū)參數(shù),北京在東8區(qū)應(yīng)該是Ydt------- AST ADT 大西洋標(biāo)準(zhǔn)時(shí)間 BST BDT 白令海標(biāo)準(zhǔn)時(shí)間 CST CDT 中部標(biāo)準(zhǔn)時(shí)間 EST EDT 東部標(biāo)準(zhǔn)時(shí)間 GMT 格林尼治標(biāo)準(zhǔn)時(shí)間 HST HDT 阿拉斯加?夏威夷標(biāo)準(zhǔn)時(shí)間 MST MDT 山區(qū)標(biāo)準(zhǔn)時(shí)間 NST 紐芬蘭標(biāo)準(zhǔn)時(shí)間 PST PDT 太平洋標(biāo)準(zhǔn)時(shí)間 YST YDT YUKON標(biāo)準(zhǔn)時(shí)間
出處:藍(lán)色理想
責(zé)任編輯:藍(lán)色
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
|