最近做了一个需求,需要批量更新数据库表,但是因为涉及到的数据较多(千万条),如果直接用sql更新,估计会把pl/sql弄垮
sql如下:update product set online_flag = '0' where status = 'ON'
所以,写了一个存储过程,以备忘:
declare
cursor product_id_list is
select product_id
from product
where status = 'ON';
commit_count number := 0;
total_count number := 0;
begin
for pid in product_id_list loop
total_count := total_count + 1;
commit_count := commit_count + 1;
update product
set online_flag = '0'
where status = 'ON'
and product_id = pid.product_id;
if commi