如何插入具有不同列数的select?

时间:2016-01-13 05:09:30

标签: java oracle

我有一项任务是将数据从X表格SCHEMA_A移至SCHEMA_B

问题是表SCHEMA_A.X有4列(sidis_deletedcd),而表SCHEMA_B.X有5列列(sidis_deletedridcd)。

如何从另一个表中插入列rid的值,在这种情况下我想让查询尽可能动态? 目前我只能想到以某种方式修改此查询

INSERT INTO SCHEMA_B.X
SELECT * FROM SCHEMA_A.X Aa
WHERE A.is_deleted = 'n'

谢谢你

2 个答案:

答案 0 :(得分:1)

添加虚拟列

insert into SCHEMA_B.X
select *, 0 as  dummy_columm
from SCHEMA_A.X Aa
WHERE A.is_deleted = 'n'

您可以使用NULL或其他特殊值来表明其来源

答案 1 :(得分:0)

尝试这样做

insert into SCHEMA_B.X (sid,is_deleted,rid,c,d)
select sid,is_deleted,0 as rid,c,d 
from SCHEMA_A.X A
WHERE A.is_deleted = 'n'