用一条SQL就搞定了,为什么还想用存储过程 update tab_a a set a.num=( select count(*) from tab_b b where a.id=b.bid ) where exists ( select * from tab_b b where a.id=b.bid );
1、用什么来接收 select id from table1的结果集 2、该怎么来一个一个取结果集中的数据 3、update table1的字段num,这个已解决(谢谢libin)
where exists ( select * from tab_b b where a.id=b.bid ); 是一个一个取结果集的数据吗 ?
存储过程::) create or replace procedure update_count is v_count int; v_id int; cursor c_id is select id from tab_a; begin open c_id; loop fetch c_id into v_id;
exit when c_id%NOTFOUND;
select count(*) into v_count from tab_b where bid=v_id;
update tab_a set num=v_count where id=v_id; end loop; commit;
update tab_a a set a.num=(
select count(*) from tab_b b
where a.id=b.bid
)
where exists (
select * from tab_b b
where a.id=b.bid
);
2、该怎么来一个一个取结果集中的数据
3、update table1的字段num,这个已解决(谢谢libin)
select * from tab_b b
where a.id=b.bid
);
是一个一个取结果集的数据吗
?
create or replace procedure update_count
is
v_count int;
v_id int;
cursor c_id is
select id from tab_a;
begin
open c_id;
loop
fetch c_id into v_id;
exit when c_id%NOTFOUND;
select count(*) into v_count
from tab_b
where bid=v_id;
update tab_a set num=v_count
where id=v_id;
end loop;
commit;
close c_id;
end update_count ;