How to add rows into a cursor manually in stored procedure in oracle

心已入冬 提交于 2020-01-04 01:49:20

问题


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?


回答1:


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:


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;
   / 


来源:https://stackoverflow.com/questions/15150472/how-to-add-rows-into-a-cursor-manually-in-stored-procedure-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!