环境0racle8I
我的问题是用下面方法把表里多行输出来,不想用多个索引表。DECLARE
  TYPE EmpTabTyp IS TABLE OF user_msg%ROWTYpe
  Index by binary_integer;
   emp_tab EmpTabTyp;
   i integer;
 BEGIN
 Select msg_title BULK COLLECT INTO emp_tab From user_msg ; /*此行有问题*/
  For i in 1..emp_tab.count loop
  Dbms_Output.Put_Line(emp_tab.count);
  dbms_output.put_line(emp_tab(i).msg_code || '    ' || emp_tab(i).msg_title);
  End Loop;
 END
;

解决方案 »

  1.   

    少了逗号!DECLARE
      TYPE EmpTabTyp IS TABLE OF user_msg%ROWTYpe
      Index by binary_integer;
       emp_tab EmpTabTyp;
       i integer;
     BEGIN
     Select msg_title, BULK ,COLLECT INTO emp_tab From user_msg ; /*此行有问题*/
      For i in 1..emp_tab.count loop
      Dbms_Output.Put_Line(emp_tab.count);
      dbms_output.put_line(emp_tab(i).msg_code || '    ' || emp_tab(i).msg_title);
      End Loop;
     END
    ;
      

  2.   

    我贴错了DECLARE
      TYPE EmpTabTyp IS TABLE OF user_msg%ROWTYpe
      Index by binary_integer;
       emp_tab EmpTabTyp;
       i integer;
      DECLARE
       TYPE EmpTabTyp IS TABLE OF user_msg%ROWTYpe
       Index by binary_integer;
        emp_tab EmpTabTyp;
        i integer;
      BEGIN
      Select * BULK COLLECT INTO emp_tab From user_msg ; 
       For i in 1..emp_tab.count loop
       Dbms_Output.Put_Line(emp_tab.count);
       dbms_output.put_line(emp_tab(i).msg_code || '    ' || emp_tab(i).msg_title);
       End Loop;
      END
     ;
     
    BULK COLLECT INTO 是不是不支持这种写法
    ERROR是 expression 'EMP_TAB' in the INTO list is of wrong type
      

  3.   

    我不知道BULK COLLECT是怎么回事,
    不过就你所述的功能干嘛那么麻烦,set serveroutput on size 1000000declare
    rows  integer default 1;
    begin
    for x in (select * from user_msg) loop
       dbms_output.put_line(rows);
       dbms_output.put_line(x.msg_code||'   '||x.msg_title);
       rows:=rows+1;
    end loop;
    end ;
    /
      

  4.   

    这只是个例子
    如果只实现功能我作select就可了
    其实我是想知道oracle中怎样把表里内容放入索引表中,我不想为所有栏位都定义一个索引表
    并想批处理,所以用了上面的写法,不知道什么原因没有通过,oracle能否把某个结果放入索引
    表中,怎么实现,我想知道的就是这个。多谢njhart2003
      

  5.   

    各位在oracle9i可以这样用!
      

  6.   

    oracle 817 我试了一下只能用多个索引表......--------------------------------
    create or replace procedure test
    is
    type t_province is table of city.provinceid%type index by binary_integer;
    type t_city is table of city.cityid%type index by binary_integer;
    type t_name is table of city.name%type index by binary_integer;
    pid  t_province;
    cid  t_city;
    nm   t_name;
    begin  pid.delete;
      cid.delete;
      nm.delete;
      
      select * BULK COLLECT into pid,cid,nm from city;   for x in 1..nm.count loop
        dbms_output.put_line(nm(x));
      end loop;  end test;
    ----------------------------------oracle9 release 2 可以用一个索引表装一个纪录集。