3

I have a cursor in stored procedure. I want to select some data from a query and insert that data into cursor, then again select some data from another query and append that data into the same cursor.

How can I do this?

3
  • simple cursor or ref_cursor man? Mar 1, 2013 at 4:53
  • @Thiyagu - Yes simple cursor, and i want to return that cursor from stored procedure. Mar 1, 2013 at 5:00
  • ha ha so no man...for this case u have to use ref_cursor Mar 1, 2013 at 5:23

2 Answers 2

4

A cursor is a read-only handle for a SQL statement. A cursor has no data. You cannot append data to a cursor. The only thing you can do with a cursor is fetch the next row.

You can change the SQL statement that is used to open the cursor to UNION together the two different SQL statements, i.e.

OPEN rc FOR 
  SELECT <<column list>>
    FROM table1
  UNION ALL
  SELECT <<column list>>
    FROM table2;

RETURN rc;
2
  • Is there any other way to do, what I want Mar 1, 2013 at 6:41
  • 1
    @NamanGoyal - I'm not quite sure what you are trying to accomplish exactly. As I said, the statement of the problem doesn't make a lot of sense. If you can explain the business problem you are trying to solve and what it is about union-ing the results of two queries that fails to solve the problem, we may be able to suggest an alternative. Mar 1, 2013 at 6:51
0

i don't know how procedure return values just see this one here 'm using simple ref_cursor

create or replace function test_ref() return sys_refcursor is
     temp sys_refcursor;
   begin
     open temp for 'select * from hr.employees ;
     return v_rc;
   end;
   / 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.