如何遍历此多列列表?

时间:2014-12-22 07:00:15

标签: oracle plsql

我是PL / SQL中的新手,我正在尝试将BULK COLLECTFORALL多列的记录表一起使用。我怎样才能循环遍历循环?

我尝试了不同的语法选项,但都失败了。我无法在线找到多列的参考资料 - 我只能找到单列的示例。

--Here are my declarations. Note that there is more than one column in the record. 
--The examples I could find online only use one column:
type mytable_rec is record
(
      mytable_col1 mytable.mytable_col1%type,
      mytable_col2 mytable.mytable_col2%type
);

type mytable_tab is table of mytable_rec;  

l_mytable mytable_tab ;

--I've already loaded my query into l_mytable using bulk collect. 
--Skipping it for readability

forall i in 1 .. l_mytable.count loop --The procedure won't compile 
                                      --because of this line
      update mytable set
             mytable.mytable_col1 = i.mytable_col1,
             mytable.mytable_col2 = i.mytable_col2
       where 1 = 1; --some condition goes here                            
end loop;    

尝试以下操作也无效:

forall i in l_mytable.first .. l_mytable.last loop --The procedure won't compile 
                                                   --because of this line
      update mytable set
             mytable.mytable_col1 = i.mytable_col1,
             mytable.mytable_col2 = i.mytable_col2
       where 1 = 1; --some condition goes here                            
end loop;   

谢谢!

1 个答案:

答案 0 :(得分:1)

请尝试以下内容。请在此链接FORALL Update - Updating multiple columns

中查找更多信息
 forall i in l_mytable.first .. l_mytable.last --The procedure won't compile 
                                               --because of this line
  update mytable set
         mytable.mytable_col1 = l_mytable.mytable_col1(i),
         mytable.mytable_col2 = l_mytable.mytable_col2(i)
   where 1 = 1; --some condition goes here