找到符号 "CREATE" 而不是

Found the symbol "CREATE" instead of

CREATE OR REPLACE PROCEDURE P_DUP_DEL_CREATE_TAB IS
BEGIN                                           
  CREATE OR REPLACE TABLE T_DUPLICATE_TABLE (   
  F_NUMBER NUMBER(2),
  S_NUMBER NUMBER(1),
  CONSTRAINT ID PRIMARY KEY (F_NUMBER, S_NUMBER)
  );

END P_DUP_DEL_CREATE_TAB;

我不知道为什么会给我这个错误:

错误(3,3):PLS-00103:找到符号“CREATE”而不是以下之一:( begin case declare exit for goto if ...

我试过使用反斜杠,但没有解决问题,有什么帮助吗?

您不能在 PL/SQL 中使用 DDL 语句。您需要使用 EXECUTE IMMEDIATE 并且不能使用 CREATE OR REPLACE:

CREATE OR REPLACE PROCEDURE P_DUP_DEL_CREATE_TAB
IS
  TABLE_DOES_NOT_EXIST EXCEPTION;
  PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST, -942);
BEGIN
  EXECUTE IMMEDIATE 'TRUNCATE TABLE T_DUPLICATE_TABLE';
EXCEPTION
  WHEN TABLE_DOES_NOT_EXIST THEN
    EXECUTE IMMEDIATE 'CREATE TABLE T_DUPLICATE_TABLE (   
      F_NUMBER NUMBER(2),
      S_NUMBER NUMBER(1),
      CONSTRAINT ID PRIMARY KEY (F_NUMBER, S_NUMBER)
    )';
END P_DUP_DEL_CREATE_TAB;
/

db<>fiddle here