17,377
社区成员
发帖
与我相关
我的任务
分享
declare
maxid number;
begin
select max(id) into maxid from a;
insert into a(select maxid+rownum,name from b);
commit;
end;
SQL> select * from a;
ID NAME
---------------- ------------------------------
9 fddfgh
10 gf
11 jgh
12 jjjk
13 hjkhj
14 m,hj
6 rows selected
SQL> select * from b;
NAME
------------------------------
fddfgh
gf
jgh
jjjk
hjkhj
m,hj
6 rows selected
SQL> insert into a select t.m+rownum ,b.name from b,(select max(id) m from a)t;
6 rows inserted
SQL> select * from a;
ID NAME
---------------- ------------------------------
9 fddfgh
10 gf
11 jgh
12 jjjk
13 hjkhj
14 m,hj
15 fddfgh
16 gf
17 jgh
18 jjjk
19 hjkhj
20 m,hj
12 rows selected
SQL>
1、
insert into a select t.m+rownum ,b.name from b,(select max(id) m from a)t;
create sequence SQ_test
minvalue 1
maxvalue 9999999999999999999999999999
start with 11
increment by 1
nocache;
insert into a(id,name)
select SQ_test.NEXTVAL,name from b;