将oracle脚本分解为更小的脚本

时间:2017-08-28 23:01:54

标签: sql oracle

我正在尝试运行一个更改200,000条记录的脚本。但我想分别更改每个10000记录,所以第一个10000然后第二个10000,依此类推。

 FOR d IN ids -- ids is a cursor which is filled by 200,000 record
      LOOP
        UPDATE doctor
        SET name =
          (SELECT name
          FROM source
          WHERE id = d.id
          AND type =
            (SELECT MAX(type)
            FROM Da
            WHERE i = id
            )
          )
        WHERE pat = d.pat;
        COMMIT;
      END LOOP;

1 个答案:

答案 0 :(得分:1)

你有什么意思说分别改变10000条记录。你的意思是你想以10000s为块进行提交吗?

你可以使用计数器

来做到这一点
   record_count := 0
    FOR d IN ids -- ids is a cursor which is filled by 200,000 record
          LOOP
            UPDATE doctor
            SET name =
          (SELECT name
          FROM source
          WHERE id = d.id
          AND type =
            (SELECT MAX(type)
            FROM Da
            WHERE i = id
            )
          )
        WHERE pat = d.pat;
        record_count := record_count +1;
        IF  mod(record_count,10000) = 0
        THEN
         COMMIT;
        END IF;
      END LOOP;
      COMMIT; -- COMMIT for the last time if you have residual records