以下 SQL*Plus 脚本
WHENEVER OSERROR EXIT FAILURE
WHENEVER SQLERROR EXIT FAILURE
DECLARE
EXIST_INDEXES BOOLEAN := FALSE;
BEGIN
FOR INDEX IN (SELECT * FROM INDEXES)
LOOP
EXIST_INDEXES := TRUE;
DBMS_OUTPUT.PUT_LINE(INDEX.SCHEMA || '.' || INDEX.NAME);
END LOOP;
IF EXIST_INDEXES THEN
RAISE_APPLICATION_ERROR(-20000,'Before proceeding, it is recommended to drop the indexes listed above');
END IF;
END;
-- Here go SQL statements that should be executed if no indexes were found
当表/视图索引中有条目时产生此输出:
SCHEMA_1.INDEX_1
DECLARE
*
ERROR at line 1:
ORA-20000: Before proceeding, it is recommended to drop the indexes listed above
ORA-06512: at line 13
当表/视图索引中有条目时,如何:
- 禁止
DECLARE
和*
行出现在脚本输出中; - 跳过执行 PL/SQL 块之后的 SQL 语句;
- 脚本是否返回非零代码?