cursor  c1  is  select  *  from  test; 
   rst c1%rowtype;
   begin  
   open  c1;  
   fetch  c1  bulk  collect  into  rst;  
   close  c1;  
   end;
类型声明不是这样用的,也不是用在这地方的!

解决方案 »

  1.   

    按照你的写法,还是不对阿。我就是想要知道怎么把一个结果集bulk  collect  into  到一个变量中,怎么来实现阿?
      

  2.   

    使用油标的时候
    加上
    loop
      exit when c1%notfound;
      fetch c1  into  rst;  
    end loop;
      

  3.   

    谢谢楼上的回答,但是好像不是我问的问题啊

    不管是否使用游标,怎么把一个结果集bulk  collect  into  到一个变量中,怎么来实现阿?
    例如:
    declare type t_test is table of test%rowtype;
    rs_test t_test;
    cursor c1 is select * from test;
    begin
    open c1;
    fetch c1 bulk collect into rs_test;
    close c1;
    end;就像上面的例子,总是报错,不是知道是否能做到,还是根本就行不通?
      

  4.   

    多个数据集要返回吗?如果要返回,我也就不知道了!
    插入到某个值的话,要
    fetch rst.column into rs_test;
      

  5.   

    这个应该可以,<<PL/SQL USER GUIDE AND REFERENCE>>9.0.2上就有这么一个例子:Into a Collection of Records
    You can bulk-fetch from a cursor into a collection of records:DECLARE
      TYPE DeptRecTab IS TABLE OF dept%ROWTYPE;
      dept_recs DeptRecTab;
      CURSOR c1 IS SELECT deptno, dname, loc FROM dept WHERE deptno > 10;
    BEGIN
      OPEN c1;
      FETCH c1 BULK COLLECT INTO dept_recs;
    END;实在不行就这么写:declare
      i pls_integer;  
      type r_st is table of test%rowtype;
      rst r_st:=r_st();
      cursor c1 is select * from test;
    begin
      i:=1;
      open c1; 
      loop
        rst.extend();
        fetch c1 into rst(i);
        exit when c1%notfound;
        i:=i+1;
      end loop;  
      close c1;
      
      for i in rst.first..rst.last loop
        dbms_output.put_line(rst(i).column1||'   '||rst(i).column2);
      end loop;
    end;
      

  6.   

    to:CodeMagic(ErrorDetector)
    首先非常感谢你,对我的问题给予了详细的解答!我也是看到<<PL/SQL USER GUIDE AND REFERENCE>>9.0.2上这么一个例子的时候,
    运行总是不对,才提出的这个问题,现在看来有可能是我的oracle的版本(我的是
    SQL*Plus: Release 9.0.1.0.1 - Production)不对
    所以才运行通不过的。不知道大家试过没有。