0

我是 pl/sql 的新手,我需要在我的数据库中进行大量更新。必须更改超过 400 万个条目,我想在每 5.000 次更新后执行一次提交。我很迷失这样做。

这是我的查询。

update accounts a set a.validateid = 'TH20381', flagexport = 25, exportname ='zde'
where a.accountnumber >= 35026879 and a.ownerid like 'V35%';

提前致谢。

4

1 回答 1

2

如果你真的需要这样做,你可以考虑使用DBMS_PARALLEL_EXECUTEpackage.json 。这是一个示例:

DECLARE
  v_sql VARCHAR2(4000);
BEGIN
  -- create the task
  DBMS_PARALLEL_EXECUTE.create_task (task_name => 'update_accounts_task');

  -- define how the task should be split
  DBMS_PARALLEL_EXECUTE.create_chunks_by_rowid(task_name   => 'update_accounts_task',
                                               table_owner => 'YOUR_USERNAME',
                                               table_name  => 'ACCOUNTS',
                                               by_row      => true,
                                               chunk_size  => 5000);

  -- command to be split and executed - notice the condition on rowid
  -- which is required since we defined above that the task should be split
  -- by rowid
  v_sql   := 'UPDATE accounts
                 SET validateid = ''TH20381'',
                     flagexport = 25,
                     exportname = ''zde''
               WHERE accountnumber >= 35026879
                 AND ownerid LIKE ''V35%''
                 AND rowid BETWEEN :start_id AND :end_id';

  -- run the task
  DBMS_PARALLEL_EXECUTE.run_task(task_name      => 'update_accounts_task',
                                 sql_stmt       => v_sql,
                                 language_flag  => DBMS_SQL.NATIVE,
                                 parallel_level => 10);
END;

创建任务的用户必须被授予CREATE JOB权限。

基于 Tim Hall 的文章,可在此处访问:Oracle Base 的 DBMS_PARALLEL_EXECUTE

于 2013-11-04T20:36:02.287 回答