本文共 5563 字,大约阅读时间需要 18 分钟。
SQL Server、Oracle、MySQL和Vertica数据库常用函数对比
Vertica数据库是HP公司新收购的用于BI方面的数据库。S:select abs(-1) valueO:select abs(-1) value from dualM:select abs(-1) value from dualV:select abs(-1)
S:select ceiling(-1.001) valueO:select ceil(-1.001) value from dualM:select ceil(-1.001) value from dualV:select ceil(-1.001)
S:select floor(-1.001) valueO:select floor(-1.001) value from dualM:select floor(-1.001) value from dualV:select floor(-1.001)
S:select cast(-1.002 as int) valueO:select trunc(-1.002) value from dualV:select trunc(-1.002)
S:select round(1.23456,4) value 1.23460O:select round(1.23456,4) value from dual 1.2346M:select round(1.23456,4) value from dual 1.2346V:select round(1.23456,4.0)
S:select Exp(1) value 2.71828182845905O:select Exp(1) value from dual 2.71828182M:select Exp(1) value from dual 2.718281828459045V:select Exp(1.0) 2.71828182845905
S:select log(2.7182818284590451) value 1O:select ln(2.7182818284590451) value from dual; 1M:select ln(2.7182818284590451) value from dual; 1V: select ln(2.7182818284590451) 1
S:select log10(10) value 1O:select log(10,10) value from dual; 1M:select log(10,10) value from dual; 1M: select log(10,10) 1
S:select SQUARE(4) value 16O:select power(4,2) value from dual 16M:select power(4,2) value from dual 16V:select power(4,2) 16
S:select SQRT(4) value 2O:select SQRT(4) value from dual 2M:select SQRT(4) value from dual 2V:select SQRT(4) 2
S:select power(3,4) value 81O:select power(3,4) value from dual 81M:select power(3,4) value from dual 81V:select power(3,4) 81
S:select rand() valueO:select sys.dbms_random.value(0,1) value from dual;M:select rand() value from dual;V:select random()
S:select sign(-8) value -1O:select sign(-8) value from dual -1M:select sign(-8) value from dual -1V:select sign(-8) -1
S:SELECT PI() value 3.14159265358979O: SELECT ACOS(-1) FROM DUAL;M: SELECT ACOS(-1) FROM DUAL; 3.141592653589793V: SELECT PI() 3.14159265358979
数值间比较
15. 求集合最大值S:select max(value) value from(select 1 valueunionselect -2 valueunionselect 4 valueunionselect 3 value)aO:select greatest(1,-2,4,3) value from dualM:select greatest(1,-2,4,3) value from dualV:select greatest(1,-2,4,3)
S:select min(value) value from(select 1 valueUnionselect -2 valueunionselect 4 valueunionselect 3 value)aO:select least(1,-2,4,3) value from dualM:select least(1,-2,4,3) value from dualV:select least(1,-2,4,3)
Create table tbl (f1 varchar(10),f2 int);Insert into tbl(f1,f2) values(‘aa’,null);Insert into tbl(f1,f2) values(‘bb’,7);S:select F1,IsNull(F2,10) value from TblO:select F1,nvl(F2,10) value from TblM:select F1,ifnull(F2,10) value from TblV:select F1,IsNull(F2,10) value from Tbl
S:select ascii('a') valueO:select ascii('a') value from dualM:select ascii('a') value from dualV:select ascii('a')
S:select char(97) valueO:select chr(97) value from dualM:select char(97) value from dualV:select chr(97)
S:select '11'+'22'+'33' valueO:select CONCAT('11','22') 33 value from dualM:select concat('11','22','33') valueV:select '11'||'22'||'33'
S:select CHARINDEX('s','sdsq',2) valueO:select INSTR('sdsq','s',2) value from dualM:select LOCATE('s','sdsq',2) value from dualV:select INSTR('sdsq','s',2)
S:select substring('abcd',2,2) valueO:select substr('abcd',2,2) value from dualM:select substr('abcd',2,2) value from dualV:select substr('abcd',2,2)
S:SELECT STUFF('abcdef', 2, 3, 'ijklmn') valueO:SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dualM:SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dualV:SELECT Replace('abcdef', 'bcd', 'ijklmn')
S:len,datalengthO: select length('aaa') value from dualM: select length('aaa') value from dualV: select length('aaa '::CHAR(10))Select length('aaa '::varchar(10))select length('aaa')
S:select space(10)+'abcd' valueO:select LPAD('abcd',14) value from dualM:select LPAD('abcd',14, ' ') value from dualV:select LPAD('abcd',14, ' ') value from dual
S:select 'abcd'+space(10) valueO:select RPAD('abcd',14) value from dualM:select RPAD('abcd',14, ' ') value from dualV:select RPAD('abcd',14, ' ') value from dual
S:ltrim,rtrimO:ltrim,rtrim,trimM:ltrim,rtrim,trimV:ltrim,rtrim,trim
日期函数
29. 系统时间S:select getdate() valueO:select sysdate value from dualM:select now() value from dualV:select sysdate()select getdate()select now() 会显示时区
S:直接与整数相加减O:直接与整数相加减M: select now()+interval 1 day value from dualV:直接与整数相加减
S:select convert(char(10),getdate(),20) valueO:select trunc(sysdate) value from dualselect to_char(sysdate,'yyyy-mm-dd') value from dualM:select DATE_FORMAT(NOW(),'%Y-%m-%d') value from dual;V:select to_char(sysdate(),'YYYY-MM-DD')
S:select convert(char(8),getdate(),108) valueO:select to_char(sysdate,'hh24:mm:ss') value from dualM:select DATE_FORMAT(NOW(),'%T') value from dualV:select to_char(sysdate,'hh24:mi:ss')
S:DATEPART 和 DATENAME 函数 (第一个参数决定)O:to_char函数 第二个参数决定参数---------------------------------下表需要补充year yy, yyyyquarter qq, q (季度)month mm, m (m O无效)dayofyear dy, y (O表星期)day dd, d (d O无效)week wk, ww (wk O无效)weekday dw (O不清楚)Hour hh,hh12,hh24 (hh12,hh24 S无效)minute mi, n (n O无效)second ss, s (s O无效)millisecond ms (O无效)
M:date_format函数 第二个参数决定格式描述%a缩写星期名%b缩写月名%c月,数值%D带有英文前缀的月中的天%d月的天,数值(00-31)%e月的天,数值(0-31)%f微秒%H小时 (00-23)%h小时 (01-12)%I小时 (01-12)%i分钟,数值(00-59)%j年的天 (001-366)%k小时 (0-23)%l小时 (1-12)%M月名%m月,数值(00-12)%pAM 或 PM%r时间,12-小时(hh:mm:ss AM 或 PM)%S秒(00-59)%s
原地址:
转载地址:http://dawzo.baihongyu.com/