一、测试目的
近期研究了原生openGauss和Oracle数据库兼容性,特整理测试了Oracle常用函数和openGauss数据库的对比测试。
二、创建DUAL虚拟表
openGauss 数据库不提供DUAL虚拟表,需要通过如下方式创建视图模拟dual虚拟表:
create or replace view dual as
select NULL::"unknown"
where 1=1;
alter table dual owner to 连接用户名;
grant all on table dual to 连接用户名;
grant select on table dual to public;
三、测试结果
测试语句及结果如下:
序号 | 函数名称 | 查询语句 | openGauss查询结果 | Oracle查询结果 | 是否兼容 |
---|---|---|---|---|---|
1 | ASCII |
SELECT ASCII('A') FROM DUAL; |
openGauss=# SELECT ASCII('A') FROM DUAL; |
SQL> SELECT ASCII('A') FROM DUAL; |
支持 |
2 |
|
SELECT CHR(65) FROM DUAL; |
openGauss=# SELECT CHR(65) FROM DUAL; |
SQL> SELECT CHR(65) FROM DUAL; |
支持 |
3 |
|
openGauss=# SELECT CONCAT(CONCAT('Hello', ' '), 'World') FROM DUAL; |
SQL> SELECT CONCAT(CONCAT('Hello', ' '), 'World') FROM DUAL; |
支持 |
|
4 |
|
SELECT INITCAP('hello world') FROM DUAL; |
openGauss=# SELECT INITCAP('hello world') FROM DUAL; |
SQL> SELECT INITCAP('hello world') FROM DUAL; |
支持 |
5 |
|
SELECT INSTR('Hello World', 'o') FROM DUAL; |
openGauss=# SELECT INSTR('Hello World', 'o') FROM DUAL; |
SQL> SELECT INSTR('Hello World', 'o') FROM DUAL; |
支持 |
6 |
|
SELECT LENGTH('Hello') FROM DUAL; |
openGauss=# SELECT LENGTH('Hello') FROM DUAL; |
SQL> SELECT LENGTH('Hello') FROM DUAL; |
支持 |
7 |
|
SELECT LOWER('Hello') FROM DUAL; |
openGauss=# SELECT LOWER('Hello') FROM DUAL; |
SQL> SELECT LOWER('Hello') FROM DUAL; |
支持 |
8 |
|
SELECT UPPER('Hello') FROM DUAL; |
openGauss=# SELECT UPPER('Hello') FROM DUAL; |
SQL> SELECT UPPER('Hello') FROM DUAL; |
支持 |
9 |
|
SELECT RPAD('Hello', 10, ' ') FROM DUAL; SELECT LPAD('Hello', 10, ' ') FROM DUAL; |
openGauss=# SELECT RPAD('Hello', 10, ' ') FROM DUAL; openGauss=# SELECT LPAD('Hello', 10, ' ') FROM DUAL; |
SQL> SELECT RPAD('Hello', 10, ' ') FROM DUAL; |
支持 |
10 |
|
SELECT LTRIM(' Hello ') FROM DUAL; SELECT RTRIM(' Hello ') FROM DUAL; |
openGauss=# SELECT LTRIM(' Hello ') FROM DUAL; |
SQL> SELECT LTRIM(' Hello ') FROM DUAL; |
支持 |
11 |
|
SELECT SUBSTR('Hello World', 7, 5) FROM DUAL; |
openGauss=# SELECT SUBSTR('Hello World', 7, 5) FROM DUAL; |
SQL> SELECT SUBSTR('Hello World', 7, 5) FROM DUAL; |
支持 |
12 |
|
openGauss=# SELECT REPLACE('Hello World', 'o', 'a') FROM DUAL; |
SQL> SELECT REPLACE('Hello World', 'o', 'a') FROM DUAL; |
支持 |
|
13 |
|
SELECT SOUNDEX('Hello') FROM DUAL; |
openGauss=# SELECT SOUNDEX('Hello') FROM DUAL; |
SQL> SELECT SOUNDEX('Hello') FROM DUAL; |
不支持 |
14 |
|
SELECT TRIM(' Hello ') FROM DUAL; |
openGauss=# SELECT TRIM(' Hello ') FROM DUAL; |
SQL> SELECT TRIM(' Hello ') FROM DUAL; |
支持 |
15 |
|
SELECT ACOS(0) FROM DUAL; |
openGauss=# SELECT ACOS(0) FROM DUAL; |
SQL> SELECT ACOS(0) FROM DUAL; |
支持 |
16 |
|
SELECT ASIN(0) FROM DUAL; |
openGauss=# SELECT ASIN(0) FROM DUAL; |
SQL> SELECT ASIN(0) FROM DUAL; |
支持 |
17 |
|
SELECT ATAN(1) FROM DUAL; |
openGauss=# SELECT ATAN(1) FROM DUAL; |
SQL> SELECT ATAN(1) FROM DUAL; |
支持 |
18 |
|
SELECT CEIL(3.14) FROM DUAL; |
openGauss=# SELECT CEIL(3.14) FROM DUAL; |
SQL> SELECT CEIL(3.14) FROM DUAL; |
支持 |
19 |
|
SELECT COS(0) FROM DUAL; |
openGauss=# SELECT COS(0) FROM DUAL; |
SQL> SELECT COS(0) FROM DUAL; |
支持 |
20 |
|
SELECT COSH(0) FROM DUAL; |
openGauss=# SELECT COSH(0) FROM DUAL; |
SQL> SELECT COSH(0) FROM DUAL; |
不支持 |
21 |
|
SELECT EXP(1) FROM DUAL; |
openGauss=# SELECT EXP(1) FROM DUAL; |
SQL> SELECT EXP(1) FROM DUAL; |
支持 |
22 |
|
SELECT FLOOR(3.14) FROM DUAL; |
openGauss=# SELECT FLOOR(3.14) FROM DUAL; |
SQL> SELECT FLOOR(3.14) FROM DUAL; |
支持 |
23 |
|
SELECT LN(2) FROM DUAL; |
openGauss=# SELECT LN(2) FROM DUAL; |
SQL> SELECT LN(2) FROM DUAL; |
支持 |
24 |
|
SELECT LOG(10, 100) FROM DUAL; |
openGauss=# SELECT LOG(10, 100) FROM DUAL; |
SQL> SELECT LOG(10, 100) FROM DUAL; |
支持 |
25 |
|
SELECT MOD(10, 3) FROM DUAL; |
openGauss=# SELECT MOD(10, 3) FROM DUAL; |
SQL> SELECT MOD(10, 3) FROM DUAL; |
支持 |
26 |
|
SELECT POWER(2, 3) FROM DUAL; |
openGauss=# SELECT POWER(2, 3) FROM DUAL; |
SQL> SELECT POWER(2, 3) FROM DUAL; |
支持 |
27 |
|
SELECT ROUND(3.14) FROM DUAL; SELECT TRUNC(3.14) FROM DUAL; |
openGauss=# SELECT ROUND(3.14) FROM DUAL; |
SQL> SELECT ROUND(3.14) FROM DUAL; |
支持 |
28 |
|
SELECT SIGN(-10) FROM DUAL; |
openGauss=# SELECT SIGN(-10) FROM DUAL; |
SQL> SELECT SIGN(-10) FROM DUAL; |
支持 |
29 |
|
SELECT SIN(0) FROM DUAL; |
openGauss=# SELECT SIN(0) FROM DUAL; |
SQL> SELECT SIN(0) FROM DUAL; |
支持 |
30 |
|
SELECT SINH(0) FROM DUAL; |
openGauss=# SELECT SINH(0) FROM DUAL;
|
SQL> SELECT SINH(0) FROM DUAL; |
不支持 |
31 |
|
SELECT SQRT(16) FROM DUAL; |
openGauss=# SELECT SQRT(16) FROM DUAL; |
SQL> SELECT SQRT(16) FROM DUAL; |
支持 |
32 |
|
SELECT TAN(0) FROM DUAL; |
openGauss=# SELECT TAN(0) FROM DUAL; |
SQL> SELECT TAN(0) FROM DUAL; |
支持 |
33 |
|
SELECT TANH(0) FROM DUAL; |
openGauss=# SELECT TANH(0) FROM DUAL; |
SQL> SELECT TANH(0) FROM DUAL; |
不支持 |
34 |
|
SELECT TRUNC(3.14) FROM DUAL; |
openGauss=# SELECT TRUNC(3.14) FROM DUAL; |
SQL> SELECT TRUNC(3.14) FROM DUAL; |
支持 |
35 |
|
SELECT ADD_MONTHS(SYSDATE, 1) FROM DUAL; |
openGauss=# SELECT ADD_MONTHS(SYSDATE, 1) FROM DUAL; |
SQL> SELECT ADD_MONTHS(SYSDATE, 1) FROM DUAL; |
支持 |
36 |
|
SELECT LAST_DAY(SYSDATE) FROM DUAL; |
openGauss=# SELECT LAST_DAY(SYSDATE) FROM DUAL; |
SQL> SELECT LAST_DAY(SYSDATE) FROM DUAL; |
支持 |
37 |
|
SELECT MONTHS_BETWEEN(TO_DATE('2022-07-01', 'YYYY-MM-DD'), TO_DATE('2022-01-01', 'YYYY-MM-DD')) FROM DUAL; |
openGauss=# SELECT MONTHS_BETWEEN(TO_DATE('2022-07-01', 'YYYY-MM-DD'), TO_DATE('2022-01-01', 'YYYY-MM-DD')) FROM DUAL; |
SQL> SELECT MONTHS_BETWEEN(TO_DATE('2022-07-01', 'YYYY-MM-DD'), TO_DATE('2022-01-01', 'YYYY-MM-DD')) FROM DUAL; |
不支持 |
38 |
|
SELECT NEW_TIME(SYSDATE, 'EST', 'PST') FROM DUAL; |
openGauss=# SELECT NEW_TIME(SYSDATE, 'EST', 'PST') FROM DUAL; |
SQL> SELECT NEW_TIME(SYSDATE, 'EST', 'PST') FROM DUAL; |
不支持 |
39 |
|
SELECT NEXT_DAY(SYSDATE, 'SUNDAY') FROM DUAL; |
openGauss=# SELECT NEXT_DAY(SYSDATE, 'SUNDAY') FROM DUAL; |
SQL> SELECT NEXT_DAY(SYSDATE, 'SUNDAY') FROM DUAL; |
支持 |
40 |
|
SELECT SYSDATE FROM DUAL; |
openGauss=# SELECT SYSDATE FROM DUAL; |
SQL> SELECT SYSDATE FROM DUAL; |
支持 |
41 |
|
SELECT CHARTOROWID('AAAVmKAABAAAXFRAAA') from dual; |
openGauss=# SELECT CHARTOROWID('AAAVmKAABAAAXFRAAA') from dual; |
SQL> SELECT CHARTOROWID('AAAVmKAABAAAXFRAAA') from dual; |
不支持 |
42 |
|
SELECT CONVERT('Hello', 'WE8ISO8859P1', 'US7ASCII') FROM DUAL; |
openGauss=# SELECT CONVERT('Hello', 'WE8ISO8859P1', 'US7ASCII') FROM DUAL; |
SQL> SELECT CONVERT('Hello', 'WE8ISO8859P1', 'US7ASCII') FROM DUAL; |
不支持 |
43 |
|
SELECT HEXTORAW('414243') FROM DUAL; |
openGauss=# SELECT HEXTORAW('414243') FROM DUAL; |
SQL> SELECT HEXTORAW('414243') FROM DUAL; |
支持 |
44 |
|
SELECT RAWTOHEX('ABC') FROM DUAL; |
openGauss=# SELECT RAWTOHEX('ABC') FROM DUAL; |
SQL> SELECT RAWTOHEX('ABC') FROM DUAL; |
支持 |
45 |
|
SELECT ROWIDTOCHAR('AAAVmKAABAAAXFRAAA') FROM DUAL; |
openGauss=# SELECT ROWIDTOCHAR('AAAVmKAABAAAXFRAAA') FROM DUAL; |
SQL> SELECT ROWIDTOCHAR('AAAVmKAABAAAXFRAAA') FROM DUAL; |
不支持 |
46 |
|
SELECT TO_CHAR(12345) AS converted_value FROM DUAL; |
openGauss=# SELECT TO_CHAR(12345) AS converted_value FROM DUAL; |
SQL> SELECT TO_CHAR(12345) AS converted_value FROM DUAL; |
支持 |
47 |
|
SELECT TO_DATE('2022-07-01', 'YYYY-MM-DD') FROM DUAL; |
openGauss=# SELECT TO_DATE('2022-07-01', 'YYYY-MM-DD') FROM DUAL; |
SQL> SELECT TO_DATE('2022-07-01', 'YYYY-MM-DD') FROM DUAL; |
支持 |
48 |
|
SELECT TO_MULTI_BYTE('Hello') FROM DUAL; |
openGauss=# SELECT TO_MULTI_BYTE('Hello') FROM DUAL; |
SQL> SELECT TO_MULTI_BYTE('Hello') FROM DUAL; |
不支持 |
49 |
|
SELECT TO_NUMBER('123.45', '999.99') FROM DUAL; |
openGauss=# SELECT TO_NUMBER('123.45', '999.99') FROM DUAL; |
SQL> SELECT TO_NUMBER('123.45', '999.99') FROM DUAL; |
支持 |
50 |
|
SELECT BFILENAME('DIRECTORY', 'filename.jpg') AS file_name FROM DUAL; |
openGauss=# SELECT BFILENAME('DIRECTORY', 'filename.jpg') AS file_name FROM DUAL; |
SQL> SELECT BFILENAME('DIRECTORY', 'filename.jpg') AS file_name FROM DUAL; |
不支持 |
51 |
|
SELECT DUMP('Hello') FROM DUAL; |
openGauss=# SELECT DUMP('Hello') FROM DUAL; |
SQL> SELECT DUMP('Hello') FROM DUAL; |
不支持 |
52 |
|
SELECT GREATEST(2, 5, 3) FROM DUAL; |
openGauss=# SELECT GREATEST(2, 5, 3) FROM DUAL; |
SQL> SELECT GREATEST(2, 5, 3) FROM DUAL; |
支持 |
53 |
|
SELECT LEAST(2, 5, 3) FROM DUAL; |
openGauss=# SELECT LEAST(2, 5, 3) FROM DUAL; |
SQL> SELECT LEAST(2, 5, 3) FROM DUAL; |
支持 |
54 |
|
SELECT UID FROM DUAL; |
openGauss=# SELECT UID FROM DUAL; |
SQL> SELECT UID FROM DUAL; |
不支持 |
55 |
|
SELECT USER FROM DUAL; |
openGauss=# SELECT USER FROM DUAL; |
SQL> SELECT USER FROM DUAL; |
支持 |
56 |
|
SELECT AVG(salary) FROM employees; |
openGauss=# SELECT AVG(salary) FROM employees; |
SQL> SELECT AVG(salary) FROM employees; |
支持 |
57 |
|
SELECT MAX(salary) FROM employees; |
openGauss=# SELECT MAX(salary) FROM employees; |
SQL> SELECT MAX(salary) FROM employees; |
支持 |
58 |
|
SELECT MIN(salary) FROM employees; |
openGauss=# SELECT MIN(salary) FROM employees; |
SQL> SELECT MIN(salary) FROM employees; |
支持 |
59 |
|
SELECT STDDEV(salary) FROM employees; |
openGauss=# SELECT STDDEV(salary) FROM employees; |
SQL> SELECT STDDEV(salary) FROM employees; |
支持 |
60 |
|
SELECT VARIANCE(salary) FROM employees; |
openGauss=# SELECT VARIANCE(salary) FROM employees; |
SQL> SELECT VARIANCE(salary) FROM employees; |
支持 |
61 |
|
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id; |
openGauss=# openGauss=# SELECT department_id, AVG(salary) FROM employees GROUP BY department_id; |
SQL> SELECT department_id, AVG(salary) FROM employees GROUP BY department_id; |
支持 |
62 |
|
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) > 5000; |
openGauss=# SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) > 5000; |
SQL> SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) > 5000; |
支持 |
63 |
|
SELECT * FROM employees ORDER BY salary DESC; |
openGauss=# SELECT * FROM employees ORDER BY salary DESC; |
SQL> SELECT * FROM employees ORDER BY salary DESC; |
支持 |
64 |
|
DECLARE |
openGauss=# DECLARE |
SQL> DECLARE |
不支持 |
65 |
|
SELECT NVL(FIRST_NAME,LAST_NAME) from employees; |
openGauss=# SELECT NVL(FIRST_NAME,LAST_NAME) from employees; |
SQL> SELECT NVL(FIRST_NAME,LAST_NAME) from employees; |
支持 |
67 |
|
SELECT AVG(salary) FROM employees; |
openGauss=# SELECT AVG(salary) FROM employees; |
SQL> SELECT AVG(salary) FROM employees; |
支持 |
68 |
|
SELECT COUNT(salary) FROM employees; |
openGauss=# SELECT COUNT(salary) FROM employees; |
SQL> SELECT COUNT(salary) FROM employees; |
支持 |
69 |
|
SELECT FIRST_VALUE(salary) OVER (PARTITION BY EMPLOYEE_ID ORDER BY DEPARTMENT_ID) FROM employees; |
openGauss=# SELECT FIRST_VALUE(salary) OVER (PARTITION BY EMPLOYEE_ID ORDER BY DEPARTMENT_ID) FROM employees; |
SQL> SELECT FIRST_VALUE(salary) OVER (PARTITION BY EMPLOYEE_ID ORDER BY DEPARTMENT_ID) FROM employees; |
支持 |
70 |
|
SELECT LAG(salary) OVER (ORDER BY DEPARTMENT_ID) FROM employees; |
openGauss=# SELECT LAG(salary) OVER (ORDER BY DEPARTMENT_ID) FROM employees; |
SQL> SELECT LAG(salary) OVER (ORDER BY DEPARTMENT_ID) FROM employees; |
支持 |
71 |
|
SELECT LAST_VALUE(salary) OVER (PARTITION BY EMPLOYEE_ID ORDER BY DEPARTMENT_ID) FROM employees; |
openGauss=# SELECT LAST_VALUE(salary) OVER (PARTITION BY EMPLOYEE_ID ORDER BY DEPARTMENT_ID) FROM employees; |
SQL> SELECT LAST_VALUE(salary) OVER (PARTITION BY EMPLOYEE_ID ORDER BY DEPARTMENT_ID) FROM employees; |
支持 |
72 |
|
SELECT LEAD(salary) OVER (ORDER BY EMPLOYEE_ID) FROM employees; |
openGauss=# SELECT LEAD(salary) OVER (ORDER BY EMPLOYEE_ID) FROM employees; |
SQL> SELECT LEAD(salary) OVER (ORDER BY EMPLOYEE_ID) FROM employees; |
支持 |
73 |
|
SELECT ROW_NUMBER() OVER (ORDER BY salary) FROM employees; |
openGauss=# SELECT ROW_NUMBER() OVER (ORDER BY salary) FROM employees; |
SQL> SELECT ROW_NUMBER() OVER (ORDER BY salary) FROM employees; |
支持 |
74 |
|
SELECT STDDEV(salary) FROM employees; |
openGauss=# SELECT STDDEV(salary) FROM employees; |
SQL> SELECT STDDEV(salary) FROM employees; |
支持 |
75 |
|
SELECT STDDEV_POP(salary) FROM employees; |
openGauss=# SELECT STDDEV_POP(salary) FROM employees; |
SQL> SELECT STDDEV_POP(salary) FROM employees; |
支持 |
76 |
|
SELECT STDDEV_SAMP(salary) FROM employees; |
openGauss=# SELECT STDDEV_SAMP(salary) FROM employees; |
SQL> SELECT STDDEV_SAMP(salary) FROM employees; |
支持 |
77 |
|
SELECT SUM(salary) FROM employees; |
openGauss=# SELECT SUM(salary) FROM employees; |
SQL> SELECT SUM(salary) FROM employees; |
支持 |
78 |
|
SELECT VAR_POP(salary) FROM employees; |
openGauss=# SELECT VAR_POP(salary) FROM employees; |
SQL> SELECT VAR_POP(salary) FROM employees; |
支持 |
79 |
|
SELECT VAR_SAMP(salary) FROM employees; |
openGauss=# SELECT VAR_SAMP(salary) FROM employees; |
SQL> SELECT VAR_SAMP(salary) FROM employees; |
支持 |
80 |
|
SELECT VARIANCE(salary) FROM employees; |
openGauss=# SELECT VARIANCE(salary) FROM employees; |
SQL> SELECT VARIANCE(salary) FROM employees; |
支持 |
81 |
|
SELECT RANK() OVER (ORDER BY salary) FROM employees; |
openGauss=# SELECT RANK() OVER (ORDER BY salary) FROM employees; |
SQL> SELECT RANK() OVER (ORDER BY salary) FROM employees; |
支持 |
82 |
|
SELECT RATIO_TO_REPORT(salary) OVER () FROM employees; |
openGauss=# SELECT RATIO_TO_REPORT(salary) OVER () FROM employees; |
SQL> SELECT RATIO_TO_REPORT(salary) OVER () FROM employees; |
不支持 |
83 |
|
SELECT ROW_NUMBER() OVER (ORDER BY salary) FROM employees; |
openGauss=# SELECT ROW_NUMBER() OVER (ORDER BY salary) FROM employees; |
SQL> SELECT ROW_NUMBER() OVER (ORDER BY salary) FROM employees; |
支持 |
84 |
|
SELECT STDDEV(salary) FROM employees; |
openGauss=# SELECT STDDEV(salary) FROM employees; |
SQL> SELECT STDDEV(salary) FROM employees; |
支持 |
85 |
|
SELECT STDDEV_POP(salary) FROM employees; |
openGauss=# SELECT STDDEV_POP(salary) FROM employees; |
SQL> SELECT STDDEV_POP(salary) FROM employees; |
支持 |
86 |
|
SELECT STDDEV_SAMP(salary) FROM employees; |
openGauss=# SELECT STDDEV_SAMP(salary) FROM employees; |
SQL> SELECT STDDEV_SAMP(salary) FROM employees; |
支持 |
87 |
|
SELECT sum(salary) FROM employees; |
openGauss=# SELECT sum(salary) FROM employees; |
SQL> SELECT sum(salary) FROM employees; |
支持 |
88 |
|
SELECT VAR_POP(salary) FROM employees; |
openGauss=# SELECT VAR_POP(salary) FROM employees; |
SQL> SELECT VAR_POP(salary) FROM employees; |
支持 |
89 |
|
SELECT VAR_SAMP(salary) FROM employees; |
openGauss=# SELECT VAR_SAMP(salary) FROM employees; |
SQL> SELECT VAR_SAMP(salary) FROM employees; |
支持 |
90 |
|
SELECT VARIANCE(salary) FROM employees; |
openGauss=# SELECT VARIANCE(salary) FROM employees; |
SQL> SELECT VARIANCE(salary) FROM employees; |
支持 |
本文分享自微信公众号 - openGauss(openGauss)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。