oracle使用子查询插入到列中

时间:2015-06-11 13:13:13

标签: oracle insert subquery

我想将数据插入表格中的一列。

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”列?

谢谢。

2 个答案:

答案 0 :(得分:0)

您想要做的事情不应该需要子查询。我不是update a set col2 = b.col1 from tableB b join tableA a on a.id = b.id 符号的忠实粉丝,试试这个:

0   java.lang.ClassCastException: android.support.v7.internal.view.menu.ActionMenuItemView cannot be cast to android.support.v7.internal.view.menu.m$a
1       at android.support.v7.internal.view.menu.b.createItemView(BaseMenuPresenter.java:161)
2       at android.support.v7.internal.view.menu.b.getItemView(BaseMenuPresenter.java:180)
3       at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:170)
4       at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:429)
5       at android.support.v7.internal.view.menu.f.k(MenuBuilder.java:1129)
6       at android.support.v7.internal.view.menu.b.updateMenuView(BaseMenuPresenter.java:91)
7       at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:207)
8       at android.support.v7.internal.view.menu.f.e(MenuBuilder.java:279)
9       at android.support.v7.internal.view.menu.f.c(MenuBuilder.java:1021)
10      at android.support.v7.internal.view.menu.f.i(MenuBuilder.java:1044)
11      at android.support.v7.internal.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:463)
12      at android.support.v7.internal.app.ToolbarActionBar$1.run(ToolbarActionBar.java:68)
13      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
14      at android.view.Choreographer.doCallbacks(Choreographer.java:590)
15      at android.view.Choreographer.doFrame(Choreographer.java:559)
16      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
17      at android.os.Handler.handleCallback(Handler.java:739)
18      at android.os.Handler.dispatchMessage(Handler.java:95)
19      at android.os.Looper.loop(Looper.java:145)
20      at android.app.ActivityThread.main(ActivityThread.java:5834)
21      at java.lang.reflect.Method.invoke(Native Method)
22      at java.lang.reflect.Method.invoke(Method.java:372)
23      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
24      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

答案 1 :(得分:0)

基于联接插入时必须使用Merge语句。 同样在表tableA中,col2已经存在但你想在join上插入一个值,那么你必须更新该列。

合并到tablea a      使用tableb b         on(b.id = a.id) 匹配时 然后    更新集a.col2 = b.col1;