PLS-00103: 在期待其中一个时遇到符号 "CREATE"

PLS-00103: Encountered the symbol "CREATE" when expecting one of the

我正在尝试在 oracle 12c 数据库中创建一个存储过程,但在我 运行 代码存储该过程时出现错误。

PLS-00103: Encountered the symbol "CREATE" when expecting one of the

关于此主题,已经提出了多个堆栈溢出问题。但他们提出了一些不同的语法。这与实际的 oracle 文档有偏差。甚至那些对我不起作用

我检查了多个网站上的文档,包括 oracle 文档。 oracle 文档建议语法如下 Oracle STORED PROCEDURE DOCUMENTATION 所以我根据语法编写了以下过程。

CREATE PROCEDURE  PDD_PROC_BASE
AS

 --DROP TABLE BASE;

CREATE TABLE  BASE as 
    SELECT idno
        ,DATE
        ,diff
        ,SUBSTR(idNO,7,2) AS PRD
        ,COMPLETED
        ,CATG
        ,OP_Number

    FROM table1
    WHERE = date >= '30-JUN-2018' 
        AND STATUS = 'G' 

 END;

我收到以下错误。

Procedure PDD_PROC_BASE compiled

Errors: check compiler log
Errors for PROCEDURE AN_5043152.PDD_PROC_BASE:

 LINE/COL ERROR
 -------- ------------------------------------------------------------------------------
 7/5      PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
     
     ( begin case declare exit for goto if loop mod null pragma
     raise return select update while with <an identifier>
     <a double-quoted delimited-identifier> <a bind variable> <<
     continue close current delete fetch lock insert open rollback
     savepoint set sql execute commit forall merge pipe purge
     json_exists json_value json_query json_object json_array
     

我也检查了其他资源,但仍然不明白哪里出了问题。

我什至尝试了 Oracle 文档中的代码示例并得到了类似的错误。

我正在使用 SQLdeveloper 工具作为客户端

您不能在 plsql 块中直接使用 sql ddl 语句,您可以使用动态 sql 和“立即执行”语句来做同样的事情,如下所示:

begin
execute immediate 'create table test_table1 (test_column1 varchar2(40))';--your create table statement here
end;

在 Oracle 的存储过程中,您只能将 DDL 语句用作动态 SQL,即立即执行 'CREATE TABLE ' ...

在这里打勾,例如:http://www.dba-oracle.com/t_using_ddl_create_index_table_plsql.htm