Oracle

SQL Server和Oracle的常用函数比较

日期:2015/6/28来源: IT猫扑网

  ---------数学函数 ---------------

  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:SELECT ACOS(-1)from dual  3.1415926535897932384626433832795028842

  15.sin,cos,tan 参数都以弧度为单位

  S:SELECT sin() value

  O:SELECT sin() value from dual

  16.Asin,Acos,Atan,Atan2 参数都以弧度为单位

  S:SELECT Asin() value

  O:SELECT Asin() value from dual

  17.弧度角度互换

  S:DEGREES:弧度-〉角度    RADIANS:角度-〉弧度

  O:没有提供内建的弧度和角度的转换函数。

  ---------数值间比较---------------------

  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.子串位置

  S:select CHARINDEX('s','sdsq',2) value

  CHARINDEX(源字符串, 目标字符串, 起始位置)

  O:select INSTR('sdsq','s',2) value from dual

  INSTR(源字符串, 目标字符串, 起始位置, 匹配序号)

  23.模糊子串的位置 --返回2,参数去掉中间%则返回7

  S:select patindex('%d%q%','sdsfasdqe') value

  PATINDEX(%[a,z,0-9]%[a,z,0-9]%[a,z,0-9]%,xyzabc123)

  PATINDEX(源字符串, 目标字符串)

  O:oracle

  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:Replace

  O:select translate('fasdbfasegas','fa','FA' ) value from dual FAsdbFAsegAs

  27.长度

  S:len,datalength

  O:length

  28.大小写转换 lower,upper

  29.单词首字母大写

  S:无

  O:select INITCAP('abcd dsaf df') value from dual  Abcd Dsaf Df

  30.左补空格(LPAD的第一个参数为空格则同space函数)

  S:select space(10)+'abcd' value

  O:select LPAD('abcd',14) value from dual

  LPAD(字符串,补齐空格后字符串的总长度)

  31.右补空格(RPAD的第一个参数为空格则同space函数)

  S:select 'abcd'+space(10) value

  O:select RPAD('abcd',14) value from dual

  RPAD(字符串,补齐空格后字符串的总长度)

  32.删除空格

  S:ltrim,rtrim,replace(字符串,' ','')

  O:ltrim,rtrim,trim

  33.字符串重复N次

  S:select REPLICATE('abcd',2) value

  O:没发现

  34.发音相似性比较(这两个单词返回值一样,发音相同)

  S:SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe')

  O:SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe') from dual

  SQLServer中用SELECT DIFFERENCE('Sm

相关文章

相关下载

网友评论

我要评论...
    没有更早的评论了
    取消