a b c 
1 A  
2 A   
3 A
4 A
5 A
6 A
7 B
8 B一个批量更新的sqla b c 三个字段 想把 所有 b='A' 的集合前两条置成 x,3-4条置成y,5,6条置成z
update table set c='x' where  (?)
update table set c='y' where  (?)update table set c='z' where (?)将这三条做成事务一起提交,问题关键就是 怎样把取出的集合分段,rownum好像不可以

解决方案 »

  1.   


    select t.a,from (
    select row_number() over(patition by b order by a) row_number,a
    ) t
    where t <3
      

  2.   

    写了一个,不知道符不符合你的要求update test
       set c = (case trunc(a / 2.5) when 0 then 'x' when 1 then 'y' when 2 then 'z' end)
     where b = 'a';更新后结果如下:
    1 a x
    2 a x
    3 a y
    4 a y
    5 a z
    6 a z
    7 b
    8 b
    9 b
      

  3.   

    ls 的不是这个意思前面的a 字段只是一个序号,无用的字段,起作用的只是b='A'的,目的是按2条一块把b='A'的C值分别付成X,Y,Z 值
    就是 b='A'的集合 前N条  X 值    ,2N条 Y值,3N条 Z值
      

  4.   

    select b,  trunc(row_number() over(partition by b  order by a)/2.4)  from test where b='a';
    结合merge操作实现就可以了!ps:还是投机取巧了
      

  5.   

    我觉得这是可以的,虽然2楼的说得有点道理,但是lz明显说明了前两条置成 x,3-4条置成y,5,6条置成z 
     按道理应该有办法把 前两条置成一类,3-4条置成一类5,6条置成一类!
      

  6.   

    update a 
    set c=(select b.c from 
          (select a,case when rn between 1 and 2 then 'x'
                         when rn between 3 and 4 then 'y' 
                         when rn between 5 and 6 then 'z' end c  
           from (select a,rownum rn from a order by a)) b
           where a.a=b.a )                                   
    where b='a' 
      

  7.   

    update table set c='x'
    where b='A' and c is null and rownum<=2;
    update table set c='y'
    where b='A' and c is null and rownum<=2;
    update table set c='z'
    where b='A' and c is null and rownum<=2;我想这样是最简单的