Comparison of common functions in SQL Server, Oracle, MySQL and Vertica databases

Comparison of SQL Server, Oracle, MySQL and Vertica Database Common Functions
Vertica database is a newly acquired database for BI by HP.

  1. absolute value
S:select abs(-1) value

O:select abs(-1) value from dual

M:select abs(-1) value from dual

V:select abs(-1)
  1. Improvement arrangement
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. round down
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. rounding (truncating)
S:select cast(-1.002 as int) value

O:select trunc(-1.002) value from dual

V:select trunc(-1.002)
  1. rounding
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. power of base 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. Take the logarithm to base 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. Take the base 10 logarithm
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. Square
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. Tori square root
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. Find the power of any number to the base
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. take a random number
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. take the symbol
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. PI
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

Comparison between values
​​15. Find the maximum value of the set

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. find the minimum value of the set
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. How to handle null values ​​(null in F2 is replaced by 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. Find character ascii code
S:select ascii('a') value

O:select ascii('a') value from dual

M:select ascii('a') value from dual

V:select ascii('a')
  1. find character from ascii code
S:select char(97) value

O:select chr(97) value from dual

M:select char(97) value from dual

V:select chr(97)
  1. connection string
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. substring position – returns 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. substring
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. Substring instead returns 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. string length
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. Case conversion lower, upper
  2. Left-pad space (the first parameter of LPAD is a space, the same as the space function)
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. Right-fill space (the first parameter of RPAD is a space, the same as the space function)
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. remove spaces
S:ltrim,rtrim

O:ltrim,rtrim,trim

M:ltrim,rtrim,trim

V:ltrim,rtrim,trim

Date function
29. System time

S:select getdate() value

O:select sysdate value from dual

M:select now() value from dual

V:select sysdate()

select getdate()

select now() 会显示时区
  1. days before and after
S:直接与整数相加减

O:直接与整数相加减

M: select now()+interval 1 day value from dual

V:直接与整数相加减
  1. ask for date
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. ask for time
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. Get other part of datetime
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无效)
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

Original address: http://www.verydemo.com/demo_c152_i10134.html

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326669077&siteId=291194637