0

If I use out sys_refcursor parameter, I'm struggling with if the first cursor has any results.

create or replace procedure cursorresults
as 
(cursor1 OUT sys_refcursor
cursor2 OUT sys_Refcursor)
begin
      open cursor1 for
      select * from table1; 

      **if cursor1 has any results**

          open cursor2 for
          select * from table2; 
 end;

I can requery the table1 to see if there was a match but there must be a better way?

4

1 回答 1

1

The only way to determine whether a cursor returns results is to attempt to fetch results from the cursor. Of course, since a cursor is a forward-only structure, that means that you would need to close and re-open the cursor.

It seems very odd, though, that you would only want to open the second cursor if the first cursor returns results. Are you sure that you don't want to join the two tables, union them, or do something else to combine the two results?

于 2012-11-30T01:46:14.090 回答