如何写一个SQL语句更新每隔7行的指定数据,
比如:在一个有1000条数据的表中,我要更新7的倍数行如:第7,14, 21……行的数据。该怎么写,谢谢了
update tablename set xxxx = '99' where 行数是7倍数的数据。

解决方案 »

  1.   

    declare num number(10):=0;
    select rownum into num
    from 
    (select id,rownum from tablename order by id);
    if(mod(num,7) == 0) then
      update tablename set xxxx = '99' where 行数是7倍数的数据;
    end if;
    commit;路过!!
      

  2.   

    begin
    for idx in (select 主键,rownum from tablename ) loop
        if mod(idx.rownum,7)=0 then
           update tablename  set xxxx = '99' where 主键= idx.主键;
        end if;
    end loop;
    end;个人认为这样定义条件来更新数据是有问题的,不推荐