I’m running a java method to call a stored procedure in an Oracle 11.2 database. I’m using JDBC connection calling the stored procedure with an OUT parameter to return a database cursor as a result set back to the java method. Everything is working fine.
Now I want to return a second result set to the java method in the SAME stored procedure. If I just add a second OUT parameter to this stored procedure and open a second cursor, everything also seems to work fine.
I’m wondering if this is the proper thing to do, because both cursors are simply opened in the stored procedure, relying on the java method to close them.
Will either cursor or result set have problems resulting from the fact that the first cursor is OPENed, after which some stuff is selected, and then the second cursor is OPENed with different stuff selected? Will the second stuff selected screw up the first stuff selected, or vice versa? Or is the database smart enough to know when the second cursor is opened, any new selections are directed to it and not the first cursor open?
I’m new to all this and just wanted to check this is how it’s intended to return multiple cursors into corresponding result sets in java. Thanks for any comments.
Both cursors are completely different entities that point to completely different queries that return results as of a completely different SCN. So there is no risk of confusion from the database. Your Java code will get separate
ResultSetobjects that need to be fetched from separately so your code needs to make sure that it’s fetching from the rightResultSet— if there is any confusion, it’s much more likely to be a bug in your code where you’re fetching from the wrong cursor or failing to close both cursors in all cases.While it is technically quite possible to return multiple cursors from a stored procedure, I would tend to suspect that there is a better solution. Most of the time, if there are multiple related cursors, that implies that the calling code is manually coding some sort of join operation. If that’s the case, you’d be much better served letting Oracle do the join and returning a single
REf CURSOR.