在table A 中,数据排列如下:
1 aa xx cc
2 zz ee ee
3 vv bb ww
4 tc ev bb
5 33 55 66
..........
如果有人删除2和4行后
会出现
1 aa xx cc
3 vv bb ww
5 33 55 66
..........
如何修改为
1 aa xx cc
2 vv bb ww
3 33 55 66
..........也就是说,如何将列值修改成递增,中间不留空行

解决方案 »

  1.   

    触发器操作
    存在当删除数据的时候,出发UPDATE
      

  2.   

    提供一个思路,简单的实现了哈!可以写到触发器中
       create table tmp(id int ,col varchar2(10));
       insert into tmp
        select 1, 'col1' from dual
        union 
        select 2, 'col2' from dual
        union 
        select 3, 'col3' from dual
        union 
        select 4, 'col4' from dual
        union
        select 5, 'col5' from dual
        
        select * from tmp;
        delete from tmp where id = 2;
        delete from tmp where id = 5;
        update tmp a set id = (select seq_num from (select rownum seq_num, id, col from tmp order by id)  b where a.id = b.id)
         where id>=1;
         select * from tmp;
      

  3.   

    创建sequence   重置