Oracle sql从带有子句的带有限制的多个表插入

问题描述 投票:0回答:1

我想从一个查询/输入数据集中将数据插入到多个表中,同时使用where子句获取不同的数据。我正在使用Oracle SQL Developer。

我已经在逻辑下面做了一些不起作用的逻辑:

Insert into A (X, Y, Z)
Values(Select x, y, z From inputdata where x = 1)

Insert into B (X, Y, Z)
Values(Select x, y, z From inputdata where x = 2)

Insert into C (X, Y, Z)
Values(Select x, y, z From inputdata where x = 3)

With inputdata as (Select x, y, z From source)
Select x, y, z From inputdata
sql oracle where-clause insert-into
1个回答
0
投票

像这里使用条件insert all

create table a(x, y, z) as (select 0, 0, 0 from dual);
create table b(x, y, z) as (select 0, 0, 0 from dual);
create table c(x, y, z) as (select 0, 0, 0 from dual);

create table src(x, y, z) as (
    select 1, 1, 1 from dual union all
    select 2, 2, 2 from dual union all
    select 3, 3, 3 from dual );

insert all 
  when x = 1 then into a (x, y, z) values (x, y, z)
  when x = 2 then into b (x, y, z) values (x, y, z)
  when x = 3 then into c (x, y, z) values (x, y, z)
select * from src
© www.soinside.com 2019 - 2024. All rights reserved.