Open Cursor for with an Exception Clause [message #608978] |
Thu, 27 February 2014 13:29 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
I might be missing something but can you have an exception with an OPEN (cursor name) FOR statement?
I'm trying to create a fail over so that if one database instance is down it fails over to the next database instance. It would appear this doesn't work. If an error occurs, such as, TNS error because they took the instance down to rebuild it, it doesn't fail over to the exception. Maybe you can't do this.
begin
begin
open Report for
select emplid
from database[b]1[/b]@somedblink
where emplid = User;
exception
when others
then
begin
open Report for
select emplid
from database[b]2[/b]@somedblink
where emplid = User;
exception
when others
then
'Both Instances are down. You are hosed'
end;
exception
when others
then
null;
end;
|
|
|
|
|
|
Re: Open Cursor for with an Exception Clause [message #608984 is a reply to message #608982] |
Thu, 27 February 2014 14:21 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
Didn't work. Exception was "Invalid Number". This would be correct since I'm trying to make the first query fail so it rolls over to the Exception to try the next query in sequence. It would appear to roll all the way down to "Response := sqlerrm;" for the "Invalid Number".
Trying to help a co-worker out.
Actual code:
procedure getResult is
begin
Response := GlobalVariables.Ok;
begin
open var_Results for
select 1 from dual@db1;
exception
when others
then
open var_Results for
select 1 from dual@db2;
exception
when others
then
/* this is from IRAPDW */
begin
open var_Results for
select 1 from dual@db3;
exception
when others
then
Response := sqlerrm;
end;
end;
end;
end;
Mod Edit: Replaced actual Tables with example selects from dual.
[Updated on: Thu, 27 February 2014 19:49] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
Re: Open Cursor for with an Exception Clause [message #608991 is a reply to message #608990] |
Thu, 27 February 2014 14:47 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
Sorry, I must be slow.
Are you saying that Response will default to 2 characters? Otherwise, I don't quite follow. Response first contains "Ok". If the last exception is executed then Response contains the error message.
Or, I'm totally missing what is written.
|
|
|
|
|
Re: Open Cursor for with an Exception Clause [message #608994 is a reply to message #608993] |
Thu, 27 February 2014 15:03 |
|
Littlefoot
Messages: 21808 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Ouch! You don't have to be sorry, but I must. Gee, what a blind fool I've been (still am). No idea how I managed to see what I saw (that RESPONSE is a variable that is being declared) - completely wrong. Sorry, I was talking nonsense ...
OK then, how do you call that procedure? RESPONSE, as its OUT parameter, has to be stored somewhere. What is that variable's datatype? Something like this:
declare
l_response <what is here?>
begin
getSSOName(some_emplid, blabla, L_RESPONSE);
|
|
|
Re: Open Cursor for with an Exception Clause [message #608995 is a reply to message #608994] |
Thu, 27 February 2014 15:19 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
The procedure is part of a package and they have an ASP.net application that calls the package/procedure. I didn't include the package spec because I didn't think it was necessary.
Problem:
It's possible that a instance can be down. Rebuilding RPT from PROD. They want a way to roll over to another instance and grab the data they need without any interruption. From what they tell me, the begin/exception is not doing that and just returning the actual sqlerror. They want the CURSOR to always return data from some instance.
Test:
I'm breaking the first query to see if it will roll over to the next query. It would appear that is not happening.
|
|
|
|
Re: Open Cursor for with an Exception Clause [message #608997 is a reply to message #608996] |
Thu, 27 February 2014 15:54 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
Nothing to do with ASP.net. SQL error. From what I can tell, the query fails but it doesn't run the next exception but runs the bottom exception in the original query code.
select some...columns....
from some table
where empid = 'my employee id'
ORA-01722: invalid number
ORA-02063: preceding line from db3
Mod Edit: removed column names
[Updated on: Thu, 27 February 2014 19:52] by Moderator Report message to a moderator
|
|
|
|
|
Re: Open Cursor for with an Exception Clause [message #609000 is a reply to message #608999] |
Thu, 27 February 2014 16:42 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
Ok, if anyone is still following, it would appear you CAN NOT use an exception with an OPEN FOR statement. If the query fails, it just returns the error. It will not execute the exception.
I'm hoping someone will prove me wrong and tell me to use THIS STATEMENT or THAT STATEMENT but for now, it won't work.
|
|
|
Re: Open Cursor for with an Exception Clause [message #609001 is a reply to message #608999] |
Thu, 27 February 2014 16:49 |
ThomasG
Messages: 3211 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
The question might be *when* does it fail.
It could be that "opening and returning the cursor" works fine, only when you start to fetch rows the invalid number error happens, when the procedure itself is long finished.
The easiest way to debug that would be to try do build a simple test case that can be run directly from SQL*Plus. Have a look at the first comment "Just use SQL*Plus variable" in Kevins Blog here.
If you do it that way, you can figure out if the error happens when you *run* the procedure of when you *fetch* (print) the cursor data.
|
|
|
|