我是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%';
提前致谢。
答案 0 :(得分:2)
如果您确实需要这样做,可以考虑使用DBMS_PARALLEL_EXECUTE
包。以下是一个示例:
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
权限。
根据蒂姆·霍尔的文章,可在此处访问:DBMS_PARALLEL_EXECUTE at Oracle Base