# sqlserver和oracle的常用函数对比(转)

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

• 博文量
3481
• 访问量
2838321