游标简单用法
declare
--类型定义
cursor c_job
is
select id from AA ;
c_row c_job%rowtype;
begin
for c_row in c_job loop
dbms_output.put_line(c_row.id);
end loop;
end;
游标遍历一个表,更新另一个表
declare
cursor city_cur is
select customer_id,city_name
from tmp_cust_city
order by customer_id;
begin
for my_cur in city_cur loop
update customers
set city_name=my_cur.city_name
where customer_id=my_cur.customer_id;
/** 此处也可以单条/分批次提交,避免锁表情况 **/
-- if mod(city_cur%rowcount,10000)=0 then
-- dbms_output.put_line('----');
-- commit;
-- end if;
end loop;
end;