将值插入Oracle 11g中的存储过程返回的表

时间:2013-08-16 15:30:21

标签: oracle oracle11g

我需要将存储过程返回的值插入表中。 我的存储过程由多个select语句和联合组成,如下所示:

create or replace
PROCEDURE          "my_str_proc" (
  emp_code     IN     VARCHAR2,
  hired_year   IN     VARCHAR2,
  q_bio        OUT SYS_REFCURSOR)
AS
BEGIN
  OPEN q_bio FOR
    select column list from table_1 where....and...
    UNION
    select column list from table_2 where....and...
    UNION
    select column list from table_3 where....and...
    UNION
    select column list from table_4 where....and...

 ORDER BY hired_year;

 RETURN;

 /* I plan to add the following statement to the existing proedure script:*/
 /* How can I get the return values after the procedure is done running 
    and inserted into a table ? */
    INSERT INTO Report_table (col1,col2,col3,col4,col5,col6,col7,col8,col9)
    VALUES (?????)

END;

如何编写脚本,以便最后的过程返回的值插入到我创建的表中。 我找不到脚本示例,而且我是Oracle的新手。我们的Oracle是11g

1 个答案:

答案 0 :(得分:0)

假设临时表的结构与ref-cursor返回的行(相同数量的列和相应类型的相应列)相同,那么下面的代码应该可以工作:

declare
   my_row temp_table_name%rowtype;
   q_bio SYS_REFCURSOR;
begin
  my_str_proc( 'x', 'y', q_bio );
  LOOP
    FETCH q_bio INTO my_row;
    exit when q_bio%NOTFOUND;
    INSERT INTO temp_table_name VALUES my_row ;
  END LOOP;
  CLOSE q_bio;
end;
/