Hi , Have a table in which 2lakh rows are present.I need to update a column and for every 10K i need a commit. Plese help me to write a script for this
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
You really didn’t give much info in your question. Here is a short generic discussion.
If you write one update statement all rows will be updated before the commit.
Using Oracle PL/SQL or SQL/PLUS or another language you could use a cursor to identify the rows you want to update, and then issue an update for each row in the cursor, count them, at 10,000 issue a commit, and return to the update process.
Using one update statement will cause lots of locks, but should run faster.
Using the cursor will be much slower, but should provide better concurrency.
I find the following works best for me most of the time:
declare
v_count := 0;
cursor (….)
begin
for r in cursor
loop
v_count:= v_count + 1;
update rec;
if ( v_count= 1000 )
then
commit;
v_count:= 0;
end if;
end loop;
end;
You really didn’t give much info in your question. Here is a short generic discussion.
If you write one update statement all rows will be updated before the commit.
Using Oracle PL/SQL or SQL/PLUS or another language you could use a cursor to identify the rows you want to update, and then issue an update for each row in the cursor, count them, at 10,000 issue a commit, and return to the update process.
Using one update statement will cause lots of locks, but should run faster.
Using the cursor will be much slower, but should provide better concurrency.
More info is definitely necessary. even if you decide to commit every 10K, there are a few ways to do it depending on your situation.
A great article about this can be found on AskTom:
http://www.oracle.com/oramag/oracle/01-jul/o41asktom.html#
I find the following works best for me most of the time:
declare
v_count := 0;
cursor (….)
begin
for r in cursor
loop
v_count:= v_count + 1;
update rec;
if ( v_count= 1000 )
then
commit;
v_count:= 0;
end if;
end loop;
end;