加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 站长百科 > 正文

oracle – 我可以在函数编译失败时使SQL * Plus退出并出现错误吗

发布时间:2021-01-21 07:50:21 所属栏目:站长百科 来源:网络整理
导读:我一直致力于通过SQL * Plus以自动方式部署的Oracle功能.有时我犯了一个错误,Oracle说: Warning: Function created with compilation errors. 然后我可以使用SHOW ERR来查看错误,但我想知道是否有一些我可以设置的配置,在这样的编译错误上: 将不会创建该功

我一直致力于通过SQL * Plus以自动方式部署的Oracle功能.有时我犯了一个错误,Oracle说:

Warning: Function created with compilation errors.

然后我可以使用SHOW ERR来查看错误,但我想知道是否有一些我可以设置的配置,在这样的编译错误上:

>将不会创建该功能
>将发出潜在的错误
> SQL * PLus将以非0退出值退出

WHENEVER SQLERROR这样的东西会很棒.

解决方法

这有点令人费解,但你可以.

初始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:tempcompile_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

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善