2011-06-03 89 views
0

我試圖從2個獨立的模式中收集數據。由於單個查詢的複雜性會獲得所有的數據會導致數據庫服務器崩潰,所以我製作了單獨的表格並填充了我需要的所有數據。現在我只需要合併數據並匹配列,以便以後可以刪除任何重複的行。以下是我創建的兩個查詢,用於返回我正在查找的結果。我的問題是,當我運行第二個查詢,我得到以下錯誤:在Oracle中合併和匹配數據

Error at Command Line:7 Column:4 
    Error report: 
    SQL Error: ORA-00904: "BOF_FOR_CHUCKSIMPSON"."BATCH_ID": invalid identifier 
    00904. 00000 - "%s: invalid identifier" 
    *Cause:  
    *Action 

有人可以幫助我瞭解是怎麼回事?

查詢1

CREATE TABLE BOF_FOR_CHUCKSIMPSON AS 
    SELECT 
    bbp.SUBCAR "Treadwell", HMM.LADLE "BOTTLE CAR", 
    bbp.BATCH_ID "Batch ID", 
    TO_CHAR(bbp.START_POUR, 'yyyy/mm/dd hh24:MI:ss') "Start Pour Time", 
    TO_CHAR(bbp.END_POUR, 'yyyy/mm/dd hh24:MI:ss') "End Pour Time", 
    TO_CHAR(hmm.sched_cast_date, 'yyyy/mm/dd hh24:MI:ss') "Sched Cast Date" 
    FROM bof_batch_pour bbp, [email protected] hmm 
    WHERE bbp.subcar=hmm.ladle 
    AND TO_CHAR(hmm.sched_cast_DATE, 'yyyymmddhh24MIss') = TO_CHAR(bbp.SCHED_CAST_DATE, 'yyyymmddhh24MIss') 
    AND bbp.START_POUR>='25-MAY-11'; 
    CREATE TABLE BOF_FOR_CHUCKSIMPSON2 AS 
    SELECT bofcs.BATCH_ID "Batch ID", bofcs.sample_time "Sample Time", 
    bcs.SILICON "Si", bcs.SULPHUR S, bcs.MANGANESE "Mn", bcs.PHOSPHORUS P, 
    bofcs.TEMPERATURE "Temperature" 
    FROM bof_chem_sample bcs, bof_celox_sample bofcs 
    WHERE bofcs.SAMPLE_CODE         = bcs.SAMPLE_CODE 
    AND bofcs.BATCH_ID          = bcs.BATCH_ID 
    AND bofcs.TEMPERATURE         > 0 
    AND bcs.SAMPLE_CODE          = 'D1' 
    AND bofcs.SAMPLE_CODE         = bcs.SAMPLE_CODE 
    AND bofcs.sample_time>'25-may-11' 
    AND bofcs.sample_time<sysdate 

查詢2

merge into bof_FOR_cHUCKSIMPSON2 
    using bof_FOR_cHUCKSIMPSON 
    on (bof_FOR_cHUCKSIMPSON.batch_id=bof_FOR_cHUCKSIMPSON2.batch_id) 
    when matched 
    then 
    update 
    SET bof_FOR_cHUCKSIMPSON.BATCH_ID = bof_FOR_cHUCKSIMPSON2.bATCH_ID 
    WHEN NOT MATCHED 
     THEN 
      INSERT (bof_FOR_cHUCKSIMPSON2.bATCH_ID 
       VALUES (99999); 
+0

嘗試刪除查詢1中Batch_Id的別名.. – StevieG 2011-06-03 14:19:50

回答

3

您已經在創建表的語句中使用混合大小寫的名稱在雙引號是這樣的:

bbp.BATCH_ID "Batch ID" 

你不因此在該表中有一個名爲BATCH_ID的列,但是有一個名爲「Batch ID」的批處理表,因此它只能被引用 - 即混合大小寫和雙引號。

+0

好吧,我已經通過編輯表中的列名解決了這個問題,但我仍然得到相同的錯誤。 – 2011-06-03 15:09:34

+0

你是如何編輯列名的? – 2011-06-03 15:12:32

+3

如果仍然得到_ORA-00904:「BOF_FOR_CHUCKSIMPSON」。「BATCH_ID」:無效的identifier_,那麼在該表中仍然沒有名爲BATCH_ID的列。 – 2011-06-03 15:30:44