update 表1 set num=NVL((select count(*) from 表2 where bid=表1.id),0)

解决方案 »

  1.   

    select id from 表1的语句也写在存储过程中,我应该怎么一个一个得的id的值呢?
      

  2.   

    用一条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
       );
      

  3.   

    1、用什么来接收   select id from table1的结果集
    2、该怎么来一个一个取结果集中的数据
    3、update table1的字段num,这个已解决(谢谢libin)
      

  4.   

    where exists (
         select * from tab_b b
         where a.id=b.bid
       );
    是一个一个取结果集的数据吗
      

  5.   

    存储过程::)
    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 ;