oracle使用子查询插入列
oracle insert into column using subquery
我想将数据插入到 table 中的列中。
Table a
ID col1 col2
1 A null
2 B null
Table b
ID col1
1 C
2 D
预期结果:
Table A
ID col1 col2
1 A C
2 B D
我试过这个:
insert into tableA (col2)
select b.col1
from tableB b , tableA a
where b.id = a.id
我收到了
0 row inserted.
如何将 B 中的 col1 插入 A 中的 col2 以匹配 'id' 列?
谢谢。
您想做的事情不需要子查询。我不太喜欢 table a, table b
符号,试试这个:
update a
set col2 = b.col1
from tableB b
join tableA a
on a.id = b.id
基于连接插入时必须使用 Merge 语句。
同样在 table tablecol2 已经存在,但你想在连接时插入一个值,那么你必须更新该列。
合并成tablea a
使用 tableb b
在 (b.id = a.id)
匹配时
然后
更新集 a.col2 = b.col1;
我想将数据插入到 table 中的列中。
Table a
ID col1 col2
1 A null
2 B null
Table b
ID col1
1 C
2 D
预期结果:
Table A
ID col1 col2
1 A C
2 B D
我试过这个:
insert into tableA (col2)
select b.col1
from tableB b , tableA a
where b.id = a.id
我收到了
0 row inserted.
如何将 B 中的 col1 插入 A 中的 col2 以匹配 'id' 列?
谢谢。
您想做的事情不需要子查询。我不太喜欢 table a, table b
符号,试试这个:
update a
set col2 = b.col1
from tableB b
join tableA a
on a.id = b.id
基于连接插入时必须使用 Merge 语句。 同样在 table tablecol2 已经存在,但你想在连接时插入一个值,那么你必须更新该列。
合并成tablea a 使用 tableb b 在 (b.id = a.id) 匹配时 然后 更新集 a.col2 = b.col1;