SQLServer和Oracle常用函数对比

文章作者 100test 发表时间 2007:03:14 14:00:29
来源 100Test.Com百考试题网


SQLServer和Oracle是大家经常用到的数据库,在此感谢作者总结出这些常用函数以供大家参考。
数学函数
  1.绝对值
  S:0select abs(-1) value
  O:0select abs(-1) value from dual
  2.取整(大)
  S:0select ceiling(-1.001) value
  O:0select ceil(-1.001) value from dual
  3.取整(小)
  S:0select floor(-1.001) value
  O:0select floor(-1.001) value from dual
  4.取整(截取)
  S:0select cast(-1.002 as int) value
  O:0select trunc(-1.002) value from dual
  5.四舍五入
  S:0select round(1.23456,4) value 1.23460
  O:0select round(1.23456,4) value from dual 1.2346
  6.e为底的幂
  S:0select Exp(1) value 2.7182818284590451
  O:0select Exp(1) value from dual 2.71828182
  7.取e为底的对数
  S:0select log(2.7182818284590451) value 1
  O:0select ln(2.7182818284590451) value from dual. 1
  8.取10为底对数
  S:0select log10(10) value 1
  O:0select log(10,10) value from dual. 1
  9.取平方
  S:0select SQUARE(4) value 16
  O:0select power(4,2) value from dual 16
  10.取平方根
  S:0select SQRT(4) value 2
  O:0select SQRT(4) value from dual 2
  11.求任意数为底的幂
  S:0select power(3,4) value 81
  O:0select power(3,4) value from dual 81
  12.取随机数
  S:0select rand() value
  O:0select sys.dbms_random.value(0,1) value from dual.
  13.取符号
  S:0select sign(-8) value -1
  O:0select sign(-8) value from dual -1
  14.圆周率
  S:SELECT PI() value 3.1415926535897931
  O:不知道
  15.sin,cos,tan 参数都以弧度为单位
  例如:0select sin(PI()/2) value 得到1(SQLServer)
  16.Asin,Acos,Atan,Atan2 返回弧度
  17.弧度角度互换(SQLServer,Oracle不知道)
  DEGREES:弧度-〉角度
  RADIANS:角度-〉弧度
数值间比较
  18. 求集合最大值
  S:0select max(value) value from
  (0select 1 value
  union
  0select -2 value
  union
  0select 4 value
  union
  0select 3 value)a
  O:0select greatest(1,-2,4,3) value from dual
  19. 求集合最小值
  S:0select min(value) value from
  (0select 1 value
  union
  0select -2 value
  union
  0select 4 value
  union
  0select 3 value)a
  O:0select least(1,-2,4,3) value from dual
  20.如何处理null值(F2中的null以10代替)
  S:0select F1,IsNull(F2,10) value from Tbl
  O:0select F1,nvl(F2,10) value from Tbl
  21.求字符序号
  S:0select ascii(’a’) value
  O:0select ascii(’a’) value from dual
  22.从序号求字符
  S:0select char(97) value
  O:0select chr(97) value from dual
  23.连接
  S:0select ’11’ ’22’ ’33’ value
  O:0select CONCAT(’11’,’22’)  33 value from dual
23.子串位置 --返回3
  S:0select CHARINDEX(’s’,’sdsq’,2) value
  O:0select INSTR(’sdsq’,’s’,2) value from dual
  23.模糊子串的位置 --返回2,参数去掉中间%则返回7
  S:0select patindex(’%d%q%’,’sdsfasdqe’) value

相关文章


不安装ORACLE客户端的系统移植方法
用SQL*Loader将Excel数据导出到Oracle
oracle问题集汇总
oracle问题集(八)
SQLServer和Oracle常用函数对比
MYSQL,Oracle,SQL数据库在JSP中的驱动
oracle问题集(七)
如何启动DataGuard的备用数据库
高手进阶:一个回滚段损坏的修复实例
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛