update table set col='test' where id in(select id from (select id,rownum num,col1 from table order by col1)where  num <=484 and mod(484,11)=1);
执行此语句之后再执行
update table set col='test2' where id in(select id from (select id,rownum num,col1 from table order by col1)where  num <=484 and mod(484,11)=1);
这样更新的数据就产生了混乱, 第二条sql语句更新的数据有些更新到第一条sql语句当中。希望能给给答复, 到底是数据更新 排序发生了变化而使之rownum也发生了改变。

解决方案 »

  1.   

    select id from (select id,rownum num,col1 from table order by col1)where num <=484 and mod(484,11)=1这个sql语句不就相当于一个临时表吗?
      

  2.   

    我的经验是rownum 和 order by一起用就是悲剧
    --把这个改了
    select id,rownum num,col1 from table order by col1--改用row_number()
    select id,row_number() over (order by col1) num,col1 from table 
      

  3.   

    呵呵,多套一层就可以了.大家回忆下分页的时候rownum是怎么用的
      

  4.   

    rownum是select出数据的时候就确定了.order by没法改变rownum的值.如果要得到按order by的rownum,需要加层查询.
      

  5.   

    问题在于你的Order by上,你这样做根本不能保证你更新的是不同的数据。
      

  6.   

    update table set col='test2' 
    where id in(select id from (select id ,rownum num from (select id,col1 from table order by col1))where num <=484 and mod(num,11)=1);应该是这样的
      

  7.   

    rownum跟orer by的层次错误了
      

  8.   


    update table set col='test' 
    where id in(
    select id from
    (select id,rownum num from 
    (select id,col1 from table order by col1)
    )  where num <=484 and mod(484,11)=1)
      

  9.   


    -- 或者分析函数
    update table set col='test' 
    where id in(
    select id from
    (select id,col1,row_number() over(order by col1) rn
    from table ) where rn<=484 and mod(rn,11)=1)
      

  10.   

    explain plan for 查看DLL执行计划,看是怎个先后顺序执行