§ High Compatibility (Oracle Compatible)
GreatSQL is 100% fully compatible with MySQL and Percona usage, and supports most common Oracle usage, including Data Type Compatibility, Function Compatibility, SQL Syntax Compatibility, Stored Routine Compatibility, and many other compatible extension usages.
§ Overview of Oracle Compatibility Design
The priority principles of GreatSQL's Oracle compatibility handling are as follows:
- GreatSQL-style SQL and stored routines can work directly in the default SQL MODE.
- Oracle compatibility features that do not conflict with GreatSQL-style SQL and stored routines can also work directly in the default SQL MODE.
- Features that have syntax or semantic conflicts with GreatSQL-style SQL and stored routines require the user to explicitly switch to Oracle MODE before they can work.
GreatSQL's Oracle compatibility is mainly implemented through the following three different approaches:
- Native mode: Oracle and GreatSQL both support or partially support common SQL standards. For some simple statements, compatibility is achieved without any adjustment.
- Compatible extension: For some functions and syntax that are unique to Oracle, GreatSQL implements extensions at the GreatSQL Server layer, such as
MERGE INTOandCONNECT BY. These types of compatibility features can be used directly without setting an additional SQL MODE. - Compatible mode: Setting
SET sql_mode = ORACLE;in GreatSQL switches the current session to Oracle compatible mode. In this mode, when Oracle syntax conflicts with GreatSQL syntax in syntax or semantics, GreatSQL automatically chooses the Oracle compatible mode.
For more information about the Oracle compatible mode, please see the document: Oracle mode.
§ Data Type Compatibility
In GreatSQL, data type compatibility is implemented through mapping, which belongs to the extended compatibility (no need to set sql_mode) approach. The specific implementation method is simple aliasing, i.e., replacing keywords at the parsing stage. For example, if a table created with CLOB is used, it will be converted to LONGTEXT in the system.
The specific mappings implemented include:
| Oracle type | GreatSQL type | Compatibility level |
|---|---|---|
| CLOB | LONGTEXT | Simple alias |
| NUMBER | DECIMAL | Simple alias |
| VARCHAR2 | VARCHAR | Simple alias |
| PLS_INTEGER | INT | Simple alias |
Example:
greatsql> CREATE TABLE t1(
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
c1 CLOB NOT NULL DEFAULT '',
c2 VARCHAR2(30) NOT NULL DEFAULT '');
ERROR 1101 (42000): BLOB, TEXT, GEOMETRY or JSON column 'c1' can't have a default value
greatsql> CREATE TABLE t1(
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
c1 CLOB NOT NULL,
c2 VARCHAR2(30) NOT NULL DEFAULT '');
Query OK, 0 rows affected (0.25 sec)
greatsql> SHOW CREATE TABLE t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`c1` longtext NOT NULL,
`c2` varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.01 sec)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
For more details, please refer to Data Type Compatibility.
§ SQL Syntax Compatibility
§ SQL Syntax Supported by Extended Compatibility
The following SQL syntax is supported in GreatSQL without setting sql_mode = ORACLE:
- ANY, ALL
- CREATE FORCE VIEW
- Hierarchical Query
- DATETIME INTERVAL
- EXECUTE IMMEDIATE
- EXPLAIN PLAN FOR
- EXTERNAL TABLE
- FULL JOIN
- INSERT ALL INTO
- KEEP FIRST/LAST
- MERGE INTO
- MINUS
- ORACLE HINT
- ROWNUM
- SELECT...FOR UPDATE OF COLUMNS
- SELECT...OFFSET...FETCH
- SEQUENCE
- (+) Outer Join
- Subquery Without Alias
- Empty String '' Equivalent to NULL Switch
- Setting CURRENT_TIMESTAMP as the Default Value for String Columns
- Removing a Specified sql_mode
- More ...
§ SQL Syntax Supported in Compatible Mode
The following SQL syntax is supported in GreatSQL only after setting sql_mode = ORACLE:
- CREATE TYPE
- CREATE TABLE OF TYPE
- DATETIME Arithmetic Operations
- DELETE Statement Without FROM
- EXEC
- ORDER BY Compatibility
- PIVOT
- RATIO_TO_REPORT
- SELECT...FOR UPDATE WAIT N
- SQLCODE_SQLERRM_FUNCTION
- SYSDATE_IS_NOW Mode
- TABLE FUNCTION
- TABLE UDT
- UPDATE SET Multi-Field Update
- WITH FUNCTION
- Global Temporary Table
- Creating Stored Procedures with Double Quotes
- Oracle Comment Style
- NULL Treated as the Same Value in Indexes
- More ...
§ Function Compatibility
§ Functions Supported by Extended Compatibility
The following functions are supported in GreatSQL without setting sql_mode = ORACLE:
- ADD_MONTHS
- CAST
- CHR
- CURRENT_TIMESTAMP
- DECODE
- DUMP
- INITCAP
- INSTRB
- LENGTHB
- LIST_AGG
- MONTHS_BETWEEN
- NCHR
- NVL
- NVL2
- RAWTOHEX
- REGEXP_COUNT
- REGEXP_REPLACE
- REPLACE
- SUBSTRB
- SYS_GUID
- SYSTIMESTAMP
- TO_CHAR
- TO_CLOB
- TO_DATE
- TO_NUMBER
- TO_TIMESTAMP
- TRANSLATE
- TRUNC
- VSIZE
- WM_CONCAT
- More ...
§ Functions Supported in Compatible Mode
The following functions are supported in GreatSQL only after setting sql_mode = ORACLE:
Note: After setting sql_mode = ORACLE, the behavior of the above functions becomes closer to Oracle; otherwise, the native GreatSQL behavior is maintained.
§ Stored Routine Compatibility
GreatSQL supports Oracle-style stored routine usage. Some stored routines have undergone basic structural modifications in ORACLE mode. For details, see: Stored Routine Basic Structural Modifications.
§ Stored Routines Supported by Extended Compatibility
In GreatSQL, regardless of whether sql_mode is DEFAULT or ORACLE, the CREATE OR REPLACE extension is supported, but the behavior differs in different modes.
§ Stored Routines Supported in Compatible Mode
The following Oracle-compatible stored routine usages require setting sql_mode = ORACLE first (some usages are also supported in sql_mode = DEFAULT mode, but do not have Oracle compatibility features):
- BULK COLLECT
- CONTINUE
- CURSOR
- EXIT/EXIT WHEN
- FORALL LOOP
- FOR LOOP
- GOTO
- IF .. ELSIF
- REF CURSOR, SYS_REFCURSOR
- TRIGGER
- TYPE IS RECORD
- TYPE IS TABLE
- VAR_TYPE
- WHILE...LOOP... END LOOP
- Anonymous Block
- Named Notation for Passing Parameters
- Stored Routines Supporting Default Parameters (DEFAULT)
- Stored Procedures Supporting RETURN
- Exception Handling EXCEPTION HANDLER
- More ...
Example:
- Stored routine usage in the Oracle environment:
CREATE OR REPLACE EDITIONABLE FUNCTION f0(delta INT DEFAULT 0) RETURN TIMESTAMP AS
cnt INT := 10;
BEGIN
RETURN SYSDATE + delta*cnt;
END;
SELECT f0(2) FROM DUAL ;
SELECT f0() FROM DUAL ;
2
3
4
5
6
7
8
- Stored routine usage in GreatSQL native mode:
CREATE OR REPLACE FUNCTION f1(delta INT) RETURNS TIMESTAMP
BEGIN
DECLARE cnt INT DEFAULT 10;
SET delta = cnt * delta;
RETURN DATE_ADD(SYSDATE(), INTERVAL delta DAY);
END;
SELECT f0(2) FROM DUAL ;
2
3
4
5
6
7
8
- Stored routine usage in GreatSQL compatible mode:
SET sql_mode = ORACLE;
CREATE OR REPLACE FUNCTION f0(delta INT DEFAULT 0) RETURN TIMESTAMP AS
cnt INT := 10;
BEGIN
RETURN SYSDATE + delta*cnt;
END;
SELECT f0(2) FROM DUAL ;
SELECT f0() FROM DUAL ;
2
3
4
5
6
7
8
9
10
For common questions about Oracle compatibility, see: Oracle Compatibility FAQ.
Scan the QR code to follow our WeChat official account
