Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle/无循环的多个插入_Oracle_Multiple Insert - Fatal编程技术网

Oracle/无循环的多个插入

Oracle/无循环的多个插入,oracle,multiple-insert,Oracle,Multiple Insert,我有下表_1,其中包含数千行: Num_replication object_name -------------------------------- 4 obj_1 8 obj_2 12 obj_3 对于其中的每一行,我需要在其他表中插入行 例如,我必须在表_2中为表_1中的每一行插入一行: ID obj_name ------------------ 1

我有下表_1,其中包含数千行:

Num_replication   object_name
--------------------------------
       4             obj_1
       8             obj_2
      12             obj_3
对于其中的每一行,我需要在其他表中插入行

例如,我必须在表_2中为表_1中的每一行插入一行:

ID       obj_name
------------------
1         obj_1
2         obj_2
3         obj_3
在表3中,我必须根据num_复制插入行数,如下所示:

ID       port
--------------
1        P0001
1        P0002
1        P0003
1        P0004
2        P0001
2        P0002
2        P0003
2        P0004
2        P0005
2        P0006
2        P0007
2        P0008
其他行也一样

我知道我可以使用循环来完成这项工作,但我需要在没有循环的情况下使用多个插入来完成


如果有任何帮助,我们将不胜感激。

使用分层查询对行进行乘法运算,然后使用密集秩生成id:

insert all
  when column_value = 1 then
    into table_2(id, obj_name) values (rn, object_name) 
  when 1 = 1 then
    into table_3(id, port) values(rn, port)
select dense_rank() over (order by object_name) rn, t.object_name, 
       column_value, 'P'||lpad(column_value, 4, '0') port
  from table_1 t, 
  table(cast(multiset(select level 
                        from dual 
                        connect by level <= t.num_replication) 
             as sys.odcinumberlist));

使用分层查询对行进行乘法运算,然后使用密集秩生成id条件插入所有行:

insert all
  when column_value = 1 then
    into table_2(id, obj_name) values (rn, object_name) 
  when 1 = 1 then
    into table_3(id, port) values(rn, port)
select dense_rank() over (order by object_name) rn, t.object_name, 
       column_value, 'P'||lpad(column_value, 4, '0') port
  from table_1 t, 
  table(cast(multiset(select level 
                        from dual 
                        connect by level <= t.num_replication) 
             as sys.odcinumberlist));