Vertica的这些事(八)—— SQL Server、Oracle、MySQL和Vertica数据库常用函数对比
【摘要】
SQL Server、Oracle、MySQL和Vertica数据库常用函数对比 Vertica数据库是HP公司新收购的用于BI方面的数据库。
绝对值
S:select abs(-1) value
...
SQL Server、Oracle、MySQL和Vertica数据库常用函数对比
Vertica数据库是HP公司新收购的用于BI方面的数据库。
- 绝对值
S:select abs(-1) value
O:select abs(-1) value from dual
M:select abs(-1) value from dual
V:select abs(-1)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 向上取整
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
M:select ceil(-1.001) value from dual
V:select ceil(-1.001)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 向下取整
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
M:select floor(-1.001) value from dual
V:select floor(-1.001)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取整(截取)
S:select cast(-1.002 as int) value
O:select trunc(-1.002) value from dual
V:select trunc(-1.002)
- 1
- 2
- 3
- 4
- 5
- 四舍五入
S:select round(1.23456,4) value 1.23460
O:select round(1.23456,4) value from dual 1.2346
M:select round(1.23456,4) value from dual 1.2346
V:select round(1.23456,4.0)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- e为底的幂
S:select Exp(1) value 2.71828182845905
O:select Exp(1) value from dual 2.71828182
M:select Exp(1) value from dual 2.718281828459045
V:select Exp(1.0) 2.71828182845905
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取e为底的对数
S:select log(2.7182818284590451) value 1
O:select ln(2.7182818284590451) value from dual; 1
M:select ln(2.7182818284590451) value from dual; 1
V: select ln(2.7182818284590451) 1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取10为底对数
S:select log10(10) value 1
O:select log(10,10) value from dual; 1
M:select log(10,10) value from dual; 1
M: select log(10,10) 1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取平方
S:select SQUARE(4) value 16
O:select power(4,2) value from dual 16
M:select power(4,2) value from dual 16
V:select power(4,2) 16
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取平方根
S:select SQRT(4) value 2
O:select SQRT(4) value from dual 2
M:select SQRT(4) value from dual 2
V:select SQRT(4) 2
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 求任意数为底的幂
S:select power(3,4) value 81
O:select power(3,4) value from dual 81
M:select power(3,4) value from dual 81
V:select power(3,4) 81
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取随机数
S:select rand() value
O:select sys.dbms_random.value(0,1) value from dual;
M:select rand() value from dual;
V:select random()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取符号
S:select sign(-8) value -1
O:select sign(-8) value from dual -1
M:select sign(-8) value from dual -1
V:select sign(-8) -1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 圆周率
S:SELECT PI() value 3.14159265358979
O: SELECT ACOS(-1) FROM DUAL;
M: SELECT ACOS(-1) FROM DUAL; 3.141592653589793
V: SELECT PI() 3.14159265358979
- 1
- 2
- 3
- 4
- 5
- 6
- 7
数值间比较
15. 求集合最大值
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
M:select greatest(1,-2,4,3) value from dual
V:select greatest(1,-2,4,3)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 求集合最小值
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
M:select least(1,-2,4,3) value from dual
V:select least(1,-2,4,3)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 如何处理null值(F2中的null以10代替)
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 Tbl
O:select F1,nvl(F2,10) value from Tbl
M:select F1,ifnull(F2,10) value from Tbl
V:select F1,IsNull(F2,10) value from Tbl
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 求字符ascii码
S:select ascii('a') value
O:select ascii('a') value from dual
M:select ascii('a') value from dual
V:select ascii('a')
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 从ascii码求字符
S:select char(97) value
O:select chr(97) value from dual
M:select char(97) value from dual
V:select chr(97)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 连接字符串
S:select '11'+'22'+'33' value
O:select CONCAT('11','22') 33 value from dual
M:select concat('11','22','33') value
V:select '11'||'22'||'33'
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 子串位置 --返回3
S:select CHARINDEX('s','sdsq',2) value
O:select INSTR('sdsq','s',2) value from dual
M:select LOCATE('s','sdsq',2) value from dual
V:select INSTR('sdsq','s',2)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 求子串
S:select substring('abcd',2,2) value
O:select substr('abcd',2,2) value from dual
M:select substr('abcd',2,2) value from dual
V:select substr('abcd',2,2)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 子串代替 返回aijklmnef
S:SELECT STUFF('abcdef', 2, 3, 'ijklmn') value
O:SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dual
M:SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dual
V:SELECT Replace('abcdef', 'bcd', 'ijklmn')
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 字符串长度
S:len,datalength
O: select length('aaa') value from dual
M: select length('aaa') value from dual
V: select length('aaa '::CHAR(10))
Select length('aaa '::varchar(10))
select length('aaa')
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 大小写转换 lower,upper
- 左补空格(LPAD的第一个参数为空格则同space函数)
S:select space(10)+'abcd' value
O:select LPAD('abcd',14) value from dual
M:select LPAD('abcd',14, ' ') value from dual
V:select LPAD('abcd',14, ' ') value from dual
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 右补空格(RPAD的第一个参数为空格则同space函数)
S:select 'abcd'+space(10) value
O:select RPAD('abcd',14) value from dual
M:select RPAD('abcd',14, ' ') value from dual
V:select RPAD('abcd',14, ' ') value from dual
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 删除空格
S:ltrim,rtrim
O:ltrim,rtrim,trim
M:ltrim,rtrim,trim
V:ltrim,rtrim,trim
- 1
- 2
- 3
- 4
- 5
- 6
- 7
日期函数
29. 系统时间
S:select getdate() value
O:select sysdate value from dual
M:select now() value from dual
V:select sysdate()
select getdate()
select now() 会显示时区
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 前后几日
S:直接与整数相加减
O:直接与整数相加减
M: select now()+interval 1 day value from dual
V:直接与整数相加减
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 求日期
S:select convert(char(10),getdate(),20) value
O:select trunc(sysdate) value from dual
select to_char(sysdate,'yyyy-mm-dd') value from dual
M:select DATE_FORMAT(NOW(),'%Y-%m-%d') value from dual;
V:select to_char(sysdate(),'YYYY-MM-DD')
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 求时间
S:select convert(char(8),getdate(),108) value
O:select to_char(sysdate,'hh24:mm:ss') value from dual
M:select DATE_FORMAT(NOW(),'%T') value from dual
V:select to_char(sysdate,'hh24:mi:ss')
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 取日期时间的其他部分
S:DATEPART 和 DATENAME 函数 (第一个参数决定)
O:to_char函数 第二个参数决定
参数---------------------------------下表需要补充
year yy, yyyy
quarter 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无效)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
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)
%p
AM 或 PM
%r
时间,12-小时(hh:mm:ss AM 或 PM)
%S
秒(00-59)
%s
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
原地址:http://www.verydemo.com/demo_c152_i10134.html
文章来源: dataclub.blog.csdn.net,作者:数据社,版权归原作者所有,如需转载,请联系作者。
原文链接:dataclub.blog.csdn.net/article/details/52154195
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)