批量插入 Oracle 数据库:哪个更好:FOR Cursor 循环还是简单的 Select?

2021-12-24 00:00:00 sql oracle plsql

哪个是批量插入 Oracle 数据库的更好选择?一个 FOR 光标循环,如

Which would be a better option for bulk insert into an Oracle database ? A FOR Cursor loop like

DECLARE
   CURSOR C1 IS SELECT * FROM FOO;
BEGIN
   FOR C1_REC IN C1 LOOP
   INSERT INTO BAR(A,
                B,
                C)
          VALUES(C1.A,
                 C1.B,
                 C1.C);
   END LOOP;
END

或简单的选择,例如:

INSERT INTO BAR(A,
                B,
                C)
        (SELECT A,
                B,
                C
        FROM FOO);

有什么具体原因,哪一个会更好?

Any specific reason either one would be better ?

推荐答案

我推荐选择选项,因为光标需要更长的时间.
对于必须修改查询的任何人来说,使用 Select 也更容易理解

I would recommend the Select option because cursors take longer.
Also using the Select is much easier to understand for anyone who has to modify your query

相关文章