哪位给一个 存储返回结果集的例子啊带临时表那种,我知道oracle没有真正意义上的临时表。哪位给个例子啊

解决方案 »

  1.   

    存储过程返回结果集一般都是用cursorcreate or replace procedure testRef(
      mycursor out sys_refcursor
      )
    as
    begin
      open mycursor for select *from emp;
    end;
    /declare
    cur sys_refcursor;
        rec emp%rowtype;
    begin
    testRef(cur);
    loop
    fetch cur into rec;
            exit when cur%notfound;
            dbms_output.put_line(rec.ename);
    end loop;
    end;
    /
    而临时表是另外的,临时表的例子create global temporary table tmp_test as
    select * from emp where 1=2;
    insert into tmp_test select * from emp;
    select * from tmp_test;
      

  2.   


    select id ID,name NOTEXISTCOL from t1
    union all select id,name from t2
    union all select id,name from t3
    union all select id,name from t4
    --然后最后选出来,一样的
    --临时表没试过,不过临时表在commit或会话结束时会自动清空的,看你的临时表设置的是事务性的,还是会话性的了
      

  3.   


    create or replace procedure testRef(
      mycursor out sys_refcursor
      )
    as
    begin
    insert into tmp_test select * from emp;
    open mycursor for select * from tmp_test;
    end;
    /declare
        cur sys_refcursor;
        rec emp%rowtype;
    begin
        testRef(cur);
        loop
            fetch cur into rec;
            exit when cur%notfound;
            dbms_output.put_line(rec.ename);
        end loop;
    end;
    /
    试了下,可以的,那你就用临时表吧,第一次用,呵呵
      

  4.   

    那创建临时表的代码也要写在begin end 之间吧
      

  5.   

    create or replace procedure testRef(mycursor out sys_refcursor) as
    begin
      v_sql VARCHAR2(1000);
      v_count number;
      v_Plow number;
      v_Phei number;
      create global TEMPORARY table tmp_test(t1 int default 0) on commit preserve rows;  insert into tmp_test
        select * from emp;
      open mycursor for
        select * from tmp_test;
    end;declare cur sys_refcursor; rec emp%rowtype;
    begin
    testRef(cur); loop fetch cur into rec; exit when cur%notfound; dbms_output.put_line(rec.ename);
    end loop;
    end;
    麻烦再看下我上面写的语法没有问题吧