From 5a269331a0870adf9983cedd53525f2df9c5c530 Mon Sep 17 00:00:00 2001
From: Liao Lanyu <1435078631@qq.com>
Date: Wed, 18 Oct 2023 15:38:33 +0800
Subject: [PATCH] [Oracle SQL] Add PLSQL_BLOCK for PLSQL of Oracle (#28757)
* add plsqlblock
* add plsqlblock
* fix
---
.../src/main/antlr4/imports/oracle/PLSQL.g4 | 4 +++
.../sql/parser/autogen/OracleStatement.g4 | 1 +
.../type/OracleDDLStatementVisitor.java | 7 +++++
.../core/database/visitor/SQLVisitorRule.java | 4 ++-
.../oracle/ddl/OraclePLSQLBlockStatement.java | 28 +++++++++++++++++++
.../resources/case/ddl/create-procedure.xml | 1 +
.../sql/supported/ddl/create-procedure.xml | 1 +
7 files changed, 45 insertions(+), 1 deletion(-)
create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OraclePLSQLBlockStatement.java
diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/PLSQL.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/PLSQL.g4
index 6947efe190e0b..8d34dbbc47cc1 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/PLSQL.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/PLSQL.g4
@@ -48,6 +48,10 @@ plsqlProcedureSource
((defaultCollationClause | invokerRightsClause | accessibleByClause)*)? (IS | AS) (callSpec | declareSection? body)
;
+plsqlBlock
+ : (SIGNED_LEFT_SHIFT_ label SIGNED_RIGHT_SHIFT_)* DECLARE declareSection body
+ ;
+
createFunction
: CREATE (OR REPLACE)? (EDITIONABLE | NONEDITIONABLE)? FUNCTION plsqlFunctionSource
;
diff --git a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4 b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
index aecb65025c5df..89ee86ff1abcf 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
@@ -154,5 +154,6 @@ execute
| createType
| createCluster
| createJava
+ | plsqlBlock
) SEMI_?
;
diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
index 9c7e24df8aa44..31cdd381674ac 100644
--- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
+++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
@@ -158,6 +158,7 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OutOfLineConstraintContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.OutOfLineRefConstraintContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.PackageNameContext;
+import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.PlsqlBlockContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.PurgeContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.RelationalPropertyContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.RenameContext;
@@ -301,6 +302,7 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleFlashbackDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleFlashbackTableStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleNoAuditStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OraclePLSQLBlockStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OraclePurgeStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleRenameStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleSystemActionStatement;
@@ -1241,6 +1243,11 @@ public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) {
return new OracleCreateProcedureStatement();
}
+ @Override
+ public ASTNode visitPlsqlBlock(final PlsqlBlockContext ctx) {
+ return new OraclePLSQLBlockStatement();
+ }
+
@Override
public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) {
return new OracleAlterProcedureStatement();
diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
index 80ee96d220265..6fbab21d92425 100644
--- a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
+++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
@@ -695,7 +695,9 @@ public enum SQLVisitorRule {
EMPTY_STATEMENT("EmptyStatement", SQLStatementType.DAL),
- CREATE_JAVA("CreateJava", SQLStatementType.DDL);
+ CREATE_JAVA("CreateJava", SQLStatementType.DDL),
+
+ PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL);
private final String name;
diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OraclePLSQLBlockStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OraclePLSQLBlockStatement.java
new file mode 100644
index 0000000000000..589523db17758
--- /dev/null
+++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OraclePLSQLBlockStatement.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl;
+
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+
+public final class OraclePLSQLBlockStatement implements OracleStatement {
+
+ @Override
+ public int getParameterCount() {
+ return 0;
+ }
+}
diff --git a/test/it/parser/src/main/resources/case/ddl/create-procedure.xml b/test/it/parser/src/main/resources/case/ddl/create-procedure.xml
index 395cc57e0bb22..0776ec466d64b 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-procedure.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-procedure.xml
@@ -34,4 +34,5 @@
+
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml
index bb978c99ac92b..fc975d00875c7 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml
@@ -46,4 +46,5 @@
+