sql server和oracle 的函数区别

  • 格式:txt
  • 大小:13.94 KB
  • 文档页数:6

SQL Server与oracle两者区别之函数区别2010-04-22 14:27Oracle和SQL Server的常用函数对比1.数学函数①绝对值S:select abs(-1) valueO:select abs(-1) value from dual②取整(大)S:select ceiling(-001) valueO:select ceil(-001) value from dual③取整(小)S:select floor(-001) valueO:select floor(-001) value from dual④取整(截取)S:select cast(-002 as int) valueO:select trunc(-002) value from dual⑤四舍五入S:select round(23456,4) value 23460O:select round(23456,4) value from dual 2346⑥e为底的幂S:select Exp(1) valueO:select Exp(1) value from dual⑦取e为底的对数S:select log(7182818284590451) valueO:select ln(7182818284590451) value from dual;⑧取10为底对数S:select log10(10) valueO:select log(10,10) value from dual;⑨取平方S:select SQUARE(4) valueO:select power(4,2) value from dual⑩取平方根S:select SQRT(4) valueO:select SQRT(4) value from dual求任意数为底的幂S:select power(3,4) valueO:select power(3,4) value from dual取随机数S:select rand() valueO:select sys.dbms_random.value(0,1) value from dual;取符号S:select sign(-8) value -1O:select sign(-8) value from dual -12.数值比较①求集合最大值S:select max(value) value from(select 1 value unionselect -2 value unionselect 4 value unionselect 3 value)aO:select greatest(1,-2,4,3) value from dual②求集合最小值S:select min(value) value from(select 1 value unionselect -2 value unionselect 4 value unionselect 3 value)aO:select least(1,-2,4,3) value from dual③如何处理null值(F2字段中的null以10代替)S:select F1,IsNull(F2,10) value from TblO:select F1,nvl(F2,10) value from Tbl3.字符串函数①求字符序号S:select ascii('a') valueO:select ascii('a') value from dual②从序号求字符S:select char(97) valueO:select chr(97) value from dual③连接S:select '11'+'22'+'33' valueO:select CONCAT('11','22')||33 value from dual④子串位置--返回3S:select CHARINDEX('s','sdsq',2) valueO:select INSTR('sdsq','s',2) value from dual⑤模糊子串的位置--返回2,参数去掉中间%则返回7S:select patindex('%d%q%','sdsfasdqe') valueO:oracle没发现,但是instr可以通过第四个参数控制出现次数 select INSTR('sdsfasdqe','sd',1,2) value from dual 返回6 ⑥求子串S:select substring('abcd',2,2) valueO:select substr('abcd',2,2) value from dual⑦子串代替--返回aijklmnefS:SELECT STUFF('abcdef', 2, 3, 'ijklmn') valueO:SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dual ⑧左补空格(LPAD的第1个参数为空格则同space函数)S:select space(10)+'abcd' valueO:select LPAD('abcd',14) value from dual⑨右补空格(RPAD的第1个参数为空格则同space函数)S:select 'abcd'+space(10) valueO:select RPAD('abcd',14) value from dual⑩发音相似性比较(这2个单词返回值一样,发音相同)S:select soundex ('Smith'), soundex ('Smythe')O:SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe') from dualSQL Server中用SELECT DIFFERENCE('Smithers', 'Smythers')比较soundex的差返回0~4,4为同音,1最高4.日期函数①系统时间S:select getdate() valueO:select sysdate value from dual②求日期S:select convert(char(10),getdate(),20) valueO:select trunc(sysdate) value from dualselect to_char(sysdate,'yyyy-mm-dd') value from dual③求时间S:select convert(char(8),getdate(),108) valueO:select to_char(sysdate,'hh24:mm:ss') value from dual④当月最后一天S:不知道O:select LAST_DAY(sysdate) value from dual⑤本星期的某一天(比如星期日)S:不知道O:SELECT Next_day(sysdate,7) vaule FROM DUAL;⑥字符串转时间S:select cast('2004-09-08'as datetime) valueO:SELECT To_date('2004-01-05 22:09:38','yyyy-mm-dd hh24-mi-ss') vaule FROM DUAL;⑦求2日期某一部分的差(比如秒)S:select datediff(ss,getdate(),getdate()+3) valueO:直接用两个日期相减(比如d1-d2=3)SELECT (d1-d2)*24*60*60 vaule FROM DUAL;⑧根据差值求新的日期(比如分钟)S:select dateadd(mi,8,getdate()) valueO:SELECT sysdate+8/60/24 vaule FROM DUAL;ORACLE内部函数大全以及与SQLSERVER的区别:下面是Oracle支持的字符函数和它们的Microsoft SQL Server等价函数。

函数 Oracle Microsoft SQL Server把字符转换为ASCII :ASCII ASCII字串连接: CONCAT --------------(expression + expression)把ASCII转换为字符 CHR, CHAR返回字符串中的开始字符(左起) INSTR ,---------------CHARINDEX把字符转换为小写 LOWER ---------------------LOWER把字符转换为大写 UPPER-------------------- UPPER填充字符串的左边 LPAD --------------------N/A清除开始的空白 LTRIM--------------------LTRIM清除尾部的空白 RTRIM --------------------RTRIM字符串中的起始模式(pattern) INSTR --------------------PATINDEX多次重复字符串 RPAD --------------------REPLICATE字符串的语音表示 SOUNDEX --------------------SOUNDEX重复空格的字串 RPAD --------------------SPACE从数字数据转换为字符数据 TO_CHAR --------------------STR子串 SUBSTR --------------------SUBSTRING替换字符 REPLACE --------------------STUFF将字串中的每个词首字母大写 INITCAP --------------------N/A翻译字符串 TRANSLATE --------------------N/A字符串长度 LENGTH-------------------- DATELENGTH or LEN列表中最大的字符串 GREATEST-------------------- N/A列表中最小的字符串 LEAST --------------------N/A如果为NULL则转换字串 NVL-------------------- ISNULL日期函数下面是Oracle支持的日期函数和它们的Microsoft SQL Server等价函数。

下载文档原格式

  / 6