所以我想要的是优化在一张表中插入许多行的过程。
我有两个选择语句-
one generates 800 rows (x)
another one 150 rows (y).
我想插入表(x,y)值,以便对于每个x,x2中将有全部150行,这意味着总共应该有120000个条目。
含义:
x1-y1
x1-y2
x1-...
x1-y150
..
x800-y1
x800-y2
...
x800-y150
我无法显示它的头或尾,并且我敢肯定它真的很简单。
答案 0 :(得分:2)
说这是您要插入的表:
SQL> create table yourTable (x varchar2(10), y varchar2(10));
Table created.
,您已经有两个查询给出了一些结果:
SQL> select 'x_' || level as x
2 from dual
3 connect by level <= 3;
X
------------------------------------------------------------------------
x_1
x_2
x_3
SQL> select 'y_' || level as y
2 from dual
3 connect by level <= 2;
Y
------------------------------------------------------------------------
y_1
y_2
您可能需要在查询中使用cross join
作为插入内容进行选择:
SQL> insert into yourTable(x, y)
2 select x, y
3 from (
4 select 'x_' || level as x
5 from dual
6 connect by level <= 3
7 ) table_X
8 CROSS JOIN
9 (
10 select 'y_' || level as y
11 from dual
12 connect by level <= 2
13 ) table_Y;
6 rows created.
结果:
SQL> select * from yourTable;
X Y
---------- ----------
x_1 y_1
x_1 y_2
x_2 y_1
x_2 y_2
x_3 y_1
x_3 y_2
6 rows selected.
答案 1 :(得分:0)
您只需要执行以下操作(没有任何连接条件),即可创建2个表的笛卡尔积:
insert into <target_table>
select x.*, y.*
from x, y;