create table test_a(a int ,aa int);
create table test_b(b int ,bb int ,bbb int);
insert into test_a values(1,10);
insert into test_a values(2,20);
insert into test_a values(3,30);
insert into test_a values(4,40);
insert into test_b values(11,111,110);
insert into test_b values(12,122,120);
insert into test_b values(13,133,130);
insert into test_b values(14,144,140);
commit;
create table test_c(a int,b int );
a,b怎样插入c表
实现
a , b
--------
1 11
2 12
3 13
4 14
如上
即 a表取1字段, b表取一字段,插入c表中。。要实现大量插入。。
create table test_b(b int ,bb int ,bbb int);
insert into test_a values(1,10);
insert into test_a values(2,20);
insert into test_a values(3,30);
insert into test_a values(4,40);
insert into test_b values(11,111,110);
insert into test_b values(12,122,120);
insert into test_b values(13,133,130);
insert into test_b values(14,144,140);
commit;
create table test_c(a int,b int );
a,b怎样插入c表
实现
a , b
--------
1 11
2 12
3 13
4 14
如上
即 a表取1字段, b表取一字段,插入c表中。。要实现大量插入。。
--怎么没什么规律 猜的
alter table test_c nologging
insert /*+ append */ into test_c
select a,b from test_a full join test_b on test_a.a=substr(test_b.b,2,1)
alter table test_c logging
insert into test_c(a,b)
select a.a,b.b
from test_a a,test_b b
where a.aa=b.bbb-100;
--有条件
/*
1,11
2,12
3,13
4,14
*/
insert into test_c(a,b)
select a.a,b.b
from test_a a,test_b b;
--无条件
/*
A B
1 11
1 12
1 13
1 14
2 11
2 12
2 13
2 14
3 11
3 12
3 13
3 14
4 11
4 12
4 13
4 14*/
select t1.a, t2.b
from (select a,rownum rowno from test_a) a, (select b,rownum rowno from test_b) b
where ta.rowno = b.rowno ;
select to_char(sysdate,'YYYYMMDD') ||
lpad( count('x') + 1,5,'0')
from d
d4 赋值 : ‘ abc ’ 固定的 如何实现? d表为空表
select to_char(sysdate,'YYYYMMDD') ||
lpad( count('x') + 1,5,'0')
from d
d4 赋值 : ‘ abc ’ 固定的 如何实现? d表为空表
见笑了 各位 小菜学习中, 可能是我表述不清楚;比如 先在要取得b表的 bb, bbb 两字段的内容,插入到d(d1 int,d2 int ,d3 int,d4 varchar2(30))表 d2 ,d3中,同时 给d1赋值:
select to_char(sysdate,'YYYYMMDD') ||
lpad( count('x') + 1,5,'0')
from d
d4 赋值 : ‘ abc ’ 固定的 如何实现? d表为空表
insert into d (d1, d2, d3, d4)
select to_char(sysdate, 'YYYYMMDD')||lpad(d.sum_count||rownum, 5, '0'),bb, bbb, 'abc'
from b, (select count(*) sum_count from d)
select to_char(sysdate, 'YYYYMMDD')||lpad(rownum, 5, '0'),bb, bbb, 'abc'
from b
谢谢你的答案 但
用rownum 时第一次插入应该是空的吧将d1设为主键就会产生错误。。
SQL> select * from test_b
2 / B BB BBB
---------- ---------- ----------
11 111 110
12 122 120
13 133 130
14 144 140SQL> create table test_d(d1 int,d2 int,d3 int,d4 varchar2(30))
2 /表已创建。
SQL> edi
已写入 file afiedt.buf 1 insert into test_d
2* select to_char(sysdate,'yyyymmdd')||lpad(rownum,5,'0'),bb,bbb,'abc' from test_b
SQL> /已创建4行。SQL> commit
2 /提交完成。SQL> select * from test_d
2 / D1 D2 D3 D4
--------------- ---------- ---------- ------------------------------
2010110100001 111 110 abc
2010110100002 122 120 abc
2010110100003 133 130 abc
2010110100004 144 140 abc
SQL> alter table test_d add constraint pk_d1 primary key(d1)
2 /表已更改。