Oracle-12c
分析過程中的表
我有很多分區要分析,不想將每一行都粘貼到終端,所以我試圖為它執行一個過程,但我得到了編譯錯誤:
CREATE OR REPLACE PROCEDURE analyze_table BEGIN analyze table SCHEMA.TABLE_NAME partition (PARTITION) validate structure cascade into invalid_rows; analyze table SCHEMA.TABLE_NAME partition (PARTITION) validate structure cascade into invalid_rows; analyze table SCHEMA.TABLE_NAME partition (PARTITION) validate structure cascade into invalid_rows; END; /
警告:創建的過程存在編譯錯誤。
SQL> SHOW ERRORS Errors for PROCEDURE ANALYZE_TABLE: LINE/COL ERROR -------- ----------------------------------------------------------------- 2/3 PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: ( ; is with default authid as cluster compress order using compiled wrapped external deterministic parallel_enable pipelined result_cache accessible rewrite
這是什麼原因?
不能將 DDL 命令直接放在 PL/SQL 程式碼中。您可以將它們作為動態 SQL 執行,例如:
CREATE OR REPLACE PROCEDURE analyze_table BEGIN execute immediate 'analyze table SCHEMA.TABLE_NAME partition (PARTITION) validate structure cascade into invalid_rows'; execute immediate 'analyze table SCHEMA.TABLE_NAME partition (PARTITION) validate structure cascade into invalid_rows'; execute immediate 'analyze table SCHEMA.TABLE_NAME partition (PARTITION) validate structure cascade into invalid_rows'; END; /