从过程中获取数据并显示在 table

get data from a procedure and show in a table

这些是事实:

  • this procedure is an example

     CREATE OR replace PROCEDURE Demo_test(
                v_1 IN NUMBER DEFAULT NULL,
                v_2 IN DATE DEFAULT NULL,
                v_n IN VARCHAR2 DEFAULT NULL,
                v_c OUT SYS_REFCURSOR
            )
            AS
            BEGIN       
        open v_c for
        select dat_1, dat_2, dat_n from(
             select vw.od1, xt.od2, xt.odn   
             from xview vw
             join xtbl xt
             order by vw.od1 asc
             FETCH FIRST 100 ROWS ONLY
             ) fidata;        
        END demo_test;

> - and i have this other bad procedure, i need to fix:

CREATE OR replace PROCEDURE Demo_test2(
    v_1 IN NUMBER DEFAULT NULL,
    v_2 IN DATE DEFAULT NULL,
    v_n IN VARCHAR2 DEFAULT NULL,
    v_c OUT SYS_REFCURSOR
)
as
begin
execute immediate ('create table xtbl (val1 varchar2, val2 date, val2 number)');

END demo_test2;
  • i need to fill this table xtbl(Demo_test2) with the Demo_test data
  • and show the result

在pseudo-code

declare
  rc sys_refcursor;
  v1, v2, v3  number;  -- ie, the datatypes of dat1,dat2,...,datn
begin 
  Demo_test(in_parameters, rc);

  loop
    fetch rc into v1,v2,v3;
    exit when rc%notfound;
    
    execute immediate 'insert into xtbl values (:1,:2,:3)' using v1,v,v3;
  end loop;
end;

'execute imediate'是因为我们还不能引用'xtbl',因为它在编译时不存在。

但我想看看这里的要求 - 我们通常不希望动态创建表。