我一直在开发一个Oracle函数,它将通过SQL*Plus以自动化的方式部署。有时我犯了一个错误,甲骨文说:
警告:用编译错误创建的函数。
然后,我可以使用SHOW ERR查看错误,但我想知道是否可以设置一些配置,以便在这样的编译错误上:
像WHENEVER SQLERROR这样的东西会很棒。
发布于 2013-05-07 21:57:54
有点复杂,但你可以。
初始的CREATE FUNCTION或CREATE 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 optionshttps://stackoverflow.com/questions/16429069
复制相似问题