2012-07-30 99 views
0

我正試圖將幾個MS Access查詢轉換爲Oracle。以下是來自MS Access的查詢之一。帶更新的Oracle更新

 

    UPDATE [RESULT] INNER JOIN [MASTER] 
     ON ([RESULT].[LAST_NAME] = [MASTER].[LAST_NAME]) 
     AND ([RESULT].[FIRST_NAME] = [MASTER].[FIRST_NAME]) 
     AND ([RESULT].[DOCUMENT_NUMBER] = [MASTER].[DOCUMENT_NUMBER]) 
     AND ([RESULT].[BATCH_ID] = [MASTER].[LEAD_ID]) 
    SET [MASTER].[CLOSURE_REASON] = "Closed For Name and Document Number Match", 
     [MASTER].[RESULT_ID] = [RESULT].[ID], 
     [MASTER].[RESULT_PID] = [RESULT].[PID] 
    WHERE (([MASTER].[CLOSURE_REASON] Is Null) 
     AND ([MASTER].[REC_CODE] = "A1") 
     AND ([RESULT].[EVENT_DATE] = [MASTER].[EVENT_DATE]) 
     AND ([RESULT].[EVENT_TYPE] = "Open") 
     AND ([MASTER].[DOCUMENT_NUMBER] Is Not Null) 
     AND ([MASTER].[DOCUMENT_NUMBER)] "null")); 

首先我收到ORA-01779:無法修改映射到非鍵保存表的錯誤列。我從您的網站跟蹤了不同的示例(包括MERGE)並修改了我的原始查詢。現在,我收到ORA-30926:無法在源表中獲得一組穩定的錯誤。

大多數示例只顯示錶格之間的一個連接,但我必須根據我的要求進行更多連接。

任何幫助將此查詢翻譯成Oracle將是偉大的。謝謝!

回答

1

我相信這應該是等效的。

UPDATE master m 
    SET closure_reason = 'Closed For Name and Document Number Match', 
     (result_id, result_pid) = (SELECT r.id, r.pid 
            FROM result r 
            WHERE m.last_name  = r.last_name 
            AND m.first_name  = r.first_name 
            AND m.lead_id   = r.batch_id 
            AND m.document_number = r.document_number 
            AND m.event_date  = r.event_date 
            AND r.event_type  = 'Open') 
WHERE m.closure_reason IS NULL 
    AND m.rec_code = 'A1' 
    AND m.document_number IS NOT NULL 
    AND m.document_number != 'null' 
    AND EXISTS(SELECT 1 
       FROM result r 
       WHERE m.last_name  = r.last_name 
        AND m.first_name  = r.first_name 
        AND m.lead_id   = r.batch_id 
        AND m.document_number = r.document_number 
        AND m.event_date  = r.event_date 
        AND r.event_type  = 'Open') 

然而,很明顯,這沒有經過測試。如果您可以發佈DDL來創建表格,DML插入幾行並顯示預期結果,那麼我們可以測試我們的代碼,並且可能會給您更準確的答案。