raise_application_error用法

本文介绍如何使用raise_application_error在PL/SQL中自定义错误信息,包括语法、参数说明及示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

我们经常通过dbms_output.put_line来输出异常信息,但有时需要把异常信息返回给调用的客户端。此时我们用raise_application_error,允许用户在pl/sql中返回用户自定义的“ORA-”错误代码和错误信息

 

raise_application_error语法:

raise_application_error(error_number, message[, {TRUE | FALSE}]);

 

error_number:允许-20000到-20999间的负数

message:允许最长2k的字符串

TRUE:the error is placed on the stack of previous errors. 

FALSE:(the default), the error replaces all previous errors.


例子:Raising an Application Error With raise_application_error

DECLARE
   num_tables NUMBER;
BEGIN
   SELECT COUNT(*) INTO num_tables FROM USER_TABLES;
   IF num_tables < 1000 THEN
      raise_application_error(-20101, 'Expecting at least 1000 tables');
   ELSE
      NULL; -- Do the rest of the processing (for the non-error case).
   END IF;
END;
/

 

 


 

转载于:https://www.cnblogs.com/toughhou/p/3778806.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值