程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> SQLServer和Oracle常用函數對比

SQLServer和Oracle常用函數對比

編輯:更多數據庫知識

SQLServer和Oracle常用函數對比


 

procedure Pro_SubPro
(
dw_in in varchar2,
cur out pkg_general.ROW_CURSOR
)
as
begin
open cur for
select yqmc from fle80 where dwbm=dw_in;
end Pro_SubPro;

procedure Pro_MainPro(
dw_in in varchar2
)
as
mc NVARCHAR2(20);
cur pkg_general.ROW_CURSOR;
begin
Pro_SubPro(dw_in,cur);
fetch cur into mc;
loop
exit when cur%notfound;
dbms_output.put_line(mc);
fetch cur into mc;
end loop;
end Pro_MainPro; 數學函數
在oracle 中distinct關鍵字可以顯示相同記錄只顯示一條
1.絕對值
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為底的對數
S:select log(2.7182818284590451) value 1
O:select ln(2.7182818284590451) value from dual; 1

  8.取10為底對數
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.求任意數為底的冪
S:select power(3,4) value 81
O:select power(3,4) value from dual 81

  12.取隨機數
S:select rand() value
O:select sys.dbms_random.value(0,1) value from dual;

  13.取符號
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 參數都以弧度為單位
例如:select sin(PI()/2) value 得到1(SQLServer)

  16.Asin,Acos,Atan,Atan2 返回弧度

  17.弧度角度互換(SQLServer,Oracle不知道)
DEGREES:弧度-〉角度
RADIANS:角度-〉弧度

數值間比較

  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.求字符序號
S:select ascii('a') value
O:select ascii('a') value from dual

  22.從序號求字符
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,參數去掉中間%則返回7
S:select patindex('%d%q%','sdsfasdqe') value
O:oracle沒發現,但是instr可以通過第四個參數控制出現次數
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:沒發現
O:select Translate('fasdbfasegas','fa','我' ) value from dual

  27.長度
S:len,datalength
O:length
28.大小寫轉換 lower,upper

  29.單詞首字母大寫
S:沒發現
O:select INITCAP('abcd dsaf df') value from dual

  30.左補空格(LPAD的第一個參數為空格則同space函數)
S:select space(10)+'abcd' value
O:select LPAD('abcd',14) value from dual

  31.右補空格(RPAD的第一個參數為空格則同space函數)
S:select 'abcd'+space(10) value
O:select RPAD('abcd',14) value from dual

  32.刪除空格
S:ltrim,rtrim
O:ltrim,rtrim,trim

  33. 重復字符串 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved