create or replace procedure goalgoalgoal isbegin for temp_cur in (select distinct b_id from c) loop update c set a_id= (select a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id) where c.bid=temp_cur.b_id; commit;end goalgoalgoal;
create or replace procedure goalgoalgoal is begin for temp_cur in (select distinct b_id from c) --取出c里的所有b_id,即用户 loop --循环更新该b_id所对应的a_id update c set a_id= (select distinct a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id) where c.bid=temp_cur.b_id; commit; end loop;end goalgoalgoal;上面少了end loop,呵呵。
update c set a_id=(select distinct a_id from b where id = b.b_id)
这个不需要用到a表 update c set a_id=(select a_id from b where id = c.b_id and rownum<2)
update c set a_id= (select a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id) where c.bid=temp_cur.b_id;直接执行就可以了!
6楼的意思是在(select a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id) 不用distinctA表id应该不会出现重复的情况,不用去重。
isbegin
for temp_cur in (select distinct b_id from c)
loop
update c set a_id=
(select a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id)
where c.bid=temp_cur.b_id;
commit;end goalgoalgoal;
is begin
for temp_cur in (select distinct b_id from c) --取出c里的所有b_id,即用户
loop --循环更新该b_id所对应的a_id
update c set a_id=
(select distinct a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id)
where c.bid=temp_cur.b_id;
commit;
end loop;end goalgoalgoal;上面少了end loop,呵呵。
update c set a_id=(select a_id from b where id = c.b_id and rownum<2)
(select a.id from a,b where a.id=b.a_id and b.id=temp_cur.b_id)
where c.bid=temp_cur.b_id;直接执行就可以了!