现在同一个表里面复制一条记录,表有主键约束,要求在主键上实现加1,其他字段一样的。
因为设计表比较多 不想一一些字段对应有办法实现吗?

解决方案 »

  1.   

    INSERT INTO TB(COL1,COL2,,,,)
    SELECT 主键+1,.....
    FROM TB
    WHERE 主键 IN(SELECT MAX(主键) FROM TB)
      

  2.   

    先插入主键,让其它字段空记录:
    declare
      count    number(10);
    begin
      count := 0;
      while count < 1000 loop
        insert into tableA(id) values (count);
        count := count + 1;
      end loop;
      commit;
    end;第二步,统统更新:
    update talbeA set col1 = 'aaa', col2 = 'bbb' ...............;
    commit;
      

  3.   

    建个临时表,表结构一样
    test(id,name)
    create global temporary t_table as select * from test;
    insert into t_table select * from test where id=1;
    update t_table set id=id+1;
    insert into test select * from t_table;
    drop table t_table;