0

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

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

4

1 回答 1

0

Assuming that the structure of your temporary table will be the same as a row returned by the ref-cursor (the same number of columns and the same types of corresponding columns), then the below code should work:

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;
/
于 2013-08-16T22:16:48.080 回答