错误恢复时,PL/SQL oracle中的下一类错误处理 [英] On error resume next type of error handling in PL/SQL oracle

查看:80
本文介绍了错误恢复时,PL/SQL oracle中的下一类错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像VB编码中的On Error Resume Next一样,有没有一种方法可以在PL/SQL

Just like On Error Resume Next in VB coding ,is there a way to do same in PL/SQL

我有一系列选择语句,因此当抛出no data found异常而不是begin exception块时,有一种方法可以移动到下一个语句

I have a sequence of select statments ,so when no data found exception thrown rather than having begin exception block is there a way to move to next statment

Eg

    select Name into l_name1 from TEMP_TBL where T=1 and R='2';
    select Name into l_name1 from TEMP_TBL where T=33 and R='3';
    select Name into l_name1 from TEMP_TBL where T=11 and R='4';
    select Name into l_name1 from TEMP_TBL where T=2 and R='5';
    select Name into l_name1 from TEMP_TBL where T=4 and R='6';

所以而不是

begin
select Name into l_name1 from TEMP_TBL where T=1 and R='2';
exception
when no_data_found then
null
end;

是否有一种简单的方法可以移动到下一个语句

is there a easy way to move to next statment

推荐答案

否,但是您可以使用局部函数:

No, but you could use a local function:

declare
   l_name1 temp_tbl.name%type;
   function get_name
      ( p_t number
      , p_r varchar2
      ) return varchar2
   is
      l_name temp_tbl.name%type;
   begin
      select Name into l_name from TEMP_TBL where T=p_t and R=p_r;
      return l_name;
   exception    
      when no_data_found then
         return null;
   end;
begin
   l_name1 := get_name (1, '2');
   l_name1 := get_name (33, '3');
   l_name1 := get_name (11, '4');
   l_name1 := get_name (2, '5');
   l_name1 := get_name (4, '6');
end;

这篇关于错误恢复时,PL/SQL oracle中的下一类错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆