STUDENT(学生信息表)
 
 ID   NUMBER(8) N 学号
 NAME   VARCHAR2(10) N 姓名
 AGE   NUMBER(4) N 年龄
 REMARK   VARCHAR2(100) Y 备注
 
 *表中ID为主键
 ?一个sql语句或一个存储过程,将表中记录翻倍,也就是说,除了主键不能重复,其余字段可以使用表中原有记录进行复制
          

解决方案 »

  1.   

    insert into STUDENT
    select id +1 + count(*) over(),NAME,AGE,REMARK from test1下面是示例,id为字母的话需要做下其他处理SQL> select * from test1;USERID           NUM1       NUM2
    ---------- ---------- ----------
    1                  12         32
    2                  23         32
    3                  31         13
    4                  23         43insert into test1 
    select userid + count(*) over(),num1,num2 from test1SQL> 
      3  /4 rows insertedSQL> commit;Commit completeSQL> select * from test1;USERID           NUM1       NUM2
    ---------- ---------- ----------
    1                  12         32
    2                  23         32
    5                  12         32
    6                  23         32
    3                  31         13
    7                  31         13
    4                  23         43
    8                  23         438 rows selected
      

  2.   

    思路:
    select max(ID) into tmp_id from student;for start_id = 1 to tmp_id
        insert into student(select tmp_id+start_id,NAME,AGE,REMARK from student where ID=start_id);
      

  3.   

    这里只是举个例子,实际上id + count(*) over() 对于你的情况可能不适用,你可以换成其他算法,只要能保证该值不在原纪录中就可以了,试试下面的,应该可以的
     
    insert into STUDENT
    select max(id) over() + rownum,NAME,AGE,REMARK from test1