2011-02-08 87 views
2

我試圖從3個表中插入數據從CSV文件中保存數據到一個有意義的倉庫表,但不知道我的語法是否正確。從多個表插入

insert into warehouseTBL 
select a.recordNum, b.fieldA, b.fieldB, c.fieldC, c.fieldD, 
    from ctrTable a, tableB b, tableC c 
where a.recordNum = b.recordNum 
    and a.recordNum = c.recordNum 
    and a.someField = b.someField 
    and a.someField = c.someField 

所以我應該使用嵌套選擇FROM子句,以便它看起來像這樣:

from ctrTable a, (
     select * 
      from tableB, tableC, 
     where tableB.recNum = tableC.recNum 
     ) as d, 
where a.recNum  = d.recNum 

是否語法甚至有意義嗎?

+0

在這個問題放在各自的Oracle錯誤。 – zerkms 2011-02-08 07:47:19

+2

語法看起來不錯,儘管1)最好明確地列出插入表「插入到warehouseTBL(recordnum,fieldA,fieldB ...)」中的列,並且2)在你的選擇中使用ANSI連接從ctrTable的內部在a.recordNum上加入tableB b = b.Recordnum等 – StuartLC 2011-02-08 07:50:25

回答

4

使用此查詢插入行,

insert into warehouseTBL 
select recordNum, fieldA, fieldB, fieldC,fieldD from 
(select a.recordNum, b.fieldA, b.fieldB, c.fieldC, c.fieldD, 
    from ctrTable a, tableB b, tableC c 
where a.recordNum = b.recordNum 
    and a.recordNum = c.recordNum 
    and a.someField = b.someField 
    and a.someField = c.someField)p