RT现在有一张表A,这个里面的一个字段FUNC_POS的值是不能重复的,但不是主键,现在DB中这个字段默认的数据都是8,请问如何通过sql语句将这些数据的FUNC_POS字段的值更新为不一样呢?
如:
原来   FUNC_POS                                 更新后:   FUNC_POS         5                                                    5
         5                                                    6 
         5                                                    7
       
数据有很多  不要一条一条的去执行吧····   

解决方案 »

  1.   


    SQL> with tab as(
      2  select 5 id from dual union all
      3  select 5 id from dual union all
      4  select 5 id from dual union all
      5  select 6 id from dual union all
      6  select 6 id from dual)
      7  select id,id+row_number()over(partition by id order by 1)-1 id from
      8  /        ID         ID
    ---------- ----------
             5          5
             5          6
             5          7
             6          6
             6          7SQL>with tab as(
    select 5 id from dual union all
    select 5 id from dual union all
    select 5 id from dual union all
    select 6 id from dual union all
    select 6 id from dual)
    select id,id+row_number()over(partition by id order by 1)-1 id from tab
    /
      

  2.   

    updata tableName t1 set t1.id = 
    (select t2.id+row_number()over(partition by t2.id order by 1)-1 id from tabName t2 where t1.id = t2.id and t1.rowid=t2.rowid)
    /
      

  3.   

    update tbl set FUNC_POS=rownum;
      

  4.   

    update tb set FUNC_POS=FUNC_POS+rownum
      

  5.   

    update tb set FUNC_POS=FUNC_POS+rownum-1