En caso de error, reanude el siguiente tipo de manejo de errores en Oracle PL/SQL
Frecuentes
Visto 5,578 equipos
1
Al igual que On Error Resume Next
in VB coding ,is there a way to do same in PL/SQL
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';
así que en lugar de
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
2 Respuestas
3
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;
contestado el 28 de mayo de 14 a las 15:05
1
Assuming your statement problem is trivialized in your example. Tony's answer is what I would use, but alternatively, you can use aggregate functions:
select decode(count(*), 1, max(Name)) into l_name1 from TEMP_TBL where T=1 and R='2';
select decode(count(*), 1, max(Name)) into l_name1 from TEMP_TBL where T=33 and R='3';
select decode(count(*), 1, max(Name)) into l_name1 from TEMP_TBL where T=11 and R='4';
select decode(count(*), 1, max(Name)) into l_name1 from TEMP_TBL where T=2 and R='5';
select decode(count(*), 1, max(Name)) into l_name1 from TEMP_TBL where T=4 and R='6';
This approach will return null for any instances of (T,R) where there is not 1 and only 1 row.
contestado el 28 de mayo de 14 a las 17:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas oracle plsql or haz tu propia pregunta.
As far as I'm aware there's no way to make PL/SQL act like VB in this regard. Best of luck. - Bob Jarvis - Слава Україні
I've researched too, and it seems the short answer is 'No.' For those of us with classic VB experience, the Oracle solution is the VB equivalent of wrapping a statement you expect might fail inside of
On Error Resume Next
yOn Error Goto ErrorHandler
. That is, you would wrap the Oracle statement you expect might fail inside ofBegin
<Statement that might fail>Exception
When Others Then
NULL;
End;
- Baodad