我想写这样的一个存储过程
首先建立一个临时表
再再向这个临时表中插入数据
然后修改插入的这个记录中的某一个属性的值
最后用游标打开这个临时表
请问怎么弄?能不能给我写一下。

解决方案 »

  1.   

    create or replace procedure proc 
    is
       type t_pat_cur is ref cursor;
          cur t_pat_cur;
       type t_rowid_rec is table of number index by binary_integer;
          rec t_rowid_rec;
       i number := 0;
       v_sql varchar2(2000) := 'select * from test';
    begin
       execute immediate 'create table test(id number)';
       commit;
       while i < 10 loop
          execute immediate 'insert into test values('||i||')';
          i := i + 1;
       end loop;
       open cur for v_sql;
       close cur;
    end;
    /
      

  2.   

    create or replace procedure proc 
    is 
      type t_pat_cur is ref cursor; 
          cur t_pat_cur; 
      type t_rowid_rec is table of number index by binary_integer; 
          rec t_rowid_rec; 
      i number := 0; 
      n_fetch_cnt  number := 0;
      v_sql varchar2(2000) := 'select id from test'; 
    begin 
      execute immediate 'create table test(id number,name varchar2(20))'; 
      commit; 
      while i < 10 loop 
          execute immediate 'insert into test values('||i||',''AA'')'; 
          i := i + 1; 
      end loop; 
      open cur for v_sql; 
      loop
          fetch cur bulk collect into rec limit 10000;
          if cur%rowcount > n_fetch_cnt
          then
             forall i in rec.first..rec.last
                execute immediate 'update test set name = ''Tom'' where id = :1'
                using              rec(i);         n_fetch_cnt := n_fetch_cnt + sql%rowcount;
          end if;
          exit when cur%notfound;
       end loop;
      close cur; 
    end; 
    /execute proc;
      

  3.   

    create or replace procedure proc 
    is 
      type t_pat_cur is ref cursor; 
          cur t_pat_cur; 
      type t_rowid_rec is table of number index by binary_integer; 
          rec t_rowid_rec; 
      i number := 0; 
      v_sql varchar2(2000) := 'select * from test'; 
    begin 
      execute immediate 'create table test(id number)'; 
      commit; 
      while i < 10 loop 
          execute immediate 'insert into test values('||i||')'; 
          i := i + 1; 
      end loop; 
      open cur for v_sql; 
      close cur; 
    end; 
    /