少し複雑ですが、できます。
最初のCREATE FUNCTION
orCREATE PROCEDURE
ステートメントは、関数またはプロシージャを作成します。スクリプトでエラーがあったことを検出し、エラーがあった場合は関数やプロシージャを明示的に削除する必要があります。ただし、オブジェクトをドロップする前にエラーをキャプチャする必要があります。CREATE
これには、ステートメントの後にスクリプトでいくつかのコードが必要になります。
whenever sqlerror exit failure;
create or replace procedure compile_error
as
begin
select count(*)
into no_such_variable
from emp;
end;
/
show error;
declare
l_num_errors integer;
begin
select count(*)
into l_num_errors
from user_errors
where name = 'COMPILE_ERROR';
if( l_num_errors > 0 )
then
execute immediate 'DROP PROCEDURE compile_error';
raise_application_error( -20001, 'Errors in COMPILE_ERROR' );
end if;
end;
/
このスクリプトを実行すると、エラーを含む次の出力が生成され、プロシージャが削除されます。
SQL> @c:\temp\compile_errors.sql
Warning: Procedure created with compilation errors.
Errors for PROCEDURE COMPILE_ERROR:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/3 PL/SQL: SQL Statement ignored
5/10 PLS-00201: identifier 'NO_SUCH_VARIABLE' must be declared
6/5 PL/SQL: ORA-00904: : invalid identifier
declare
*
ERROR at line 1:
ORA-20001: Errors in COMPILE_ERROR
ORA-06512: at line 12
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options