如何使用CURSOR将超过20000的批量记录插入数据库?

时间:2012-04-14 18:41:54

标签: oracle stored-procedures

您实际上是在尝试将批量记录插入数据库。 记录超过20000。 我必须将记录插入三个表中,因为这些记录是核心的。 例如:

1. One sort of data into the Table 1.
 1.1 another sort of data into the Table 2.
   1.1.1 another sort of data into the Table 3.

我们可以将上述语句视为嵌套的lenter代码hereoop。 目前m使用Cursor进行上述方法但是v v v v很长时间。 等待你宝贵的建议....

1 个答案:

答案 0 :(得分:2)

听起来你想要INSERT ALL声明。像

这样的东西
INSERT ALL
  WHEN (<<some condition>>) THEN 
    INTO table1( <<list of columns>> )
      VALUES( <<list of columns>> )
  WHEN (<<another condition>>) THEN
    INTO table2( <<list of columns>> )
      VALUES( <<list of columns>> )
  WHEN (<<third condition>>) THEN
    INTO table3( <<list of columns>> )
      VALUES( <<list of columns>> )
  SELECT <<list of columns>> 
    FROM <<source tables>>
   WHERE <<some predicates>>

最后的SELECT语句通常是您用来填充游标的任何查询。条件将实现您在循环内实现的任何逻辑,以确定将数据插入哪个表。

如果您知道光标中的一行总是会插入到单个表中,您可以使用INSERT FIRST而不是INSERT ALL(其余语法保持不变),以便一旦第一个条件评估为TRUE,Oracle就可以停止评估条件。