2016-08-03 21 views
-2

我試着使用更新設置像上面,我嘗試不同的語法,但沒有成功更新設置爲從選擇錯誤語法

update 
pc_discount 
set 
ceza_ucret_turu_id=pc_discount_ceza.CEZA_ALT_UCRET_KODU 
from 
(select CEZA_ALT_UCRET_KODU from pc_discount_ceza where CEZA_ALT_UCRET_KODU is not null) pdc 
where 
pc_discount.id=pdc.discount_id 
ceza_ucret_turu_id is null 

第一次沒有成功(SQL命令未正確結束)

MERGE INTO pc_discount pd 
    USING pc_discount_ceza pdc 
    ON pd.id = pdc.discount_id 
    AND pdc.CEZA_ALT_UCRET_KODU is not null 
    and pd.ceza_ucret_turu_id is null 
WHEN MATCHED THEN 
UPDATE 
    SET ceza_ucret_turu_id = pdc.CEZA_ALT_UCRET_KODU 

再次失敗(缺少ON關鍵字)

是否有任何建議來運行那種sql?

編輯:

update 
pc_discount 
set 
ceza_ucret_turu_id=pdc.CEZA_ALT_UCRET_KODU 
from 
(select CEZA_ALT_UCRET_KODU from pc_discount_ceza where CEZA_ALT_UCRET_KODU is not null) pdc 
where 
pc_discount.id=pdc.discount_id and 
ceza_ucret_turu_id is null 

依然沒有改變。

+0

沒有子查詢返回任何結果從pc_discount_ceza'選擇CEZA_ALT_UCRET_KODU CEZA_ALT_UCRET_KODU不爲空嗎? –

+0

是許多結果。 – Furkan

回答

1

有一對夫婦的事情,我會改變

  • 有兩個條件,他們需要一個「和」 SET加盟應該
  • 使用表的別名在集合
  • 添加加盟條件設定爲子查詢

嘗試像

update 
    pc_discount 
set 
    ceza_ucret_turu_id = pcd.CEZA_ALT_UCRET_KODU 
from 
    ( 
    select 
     discount_id, 
     CEZA_ALT_UCRET_KODU 
    from 
     pc_discount_ceza 
    where 
     CEZA_ALT_UCRET_KODU is not null 
) pcd 
where 
    pc_discount.id = pcd.discount_id and 
    pc_discount.ceza_ucret_turu_id is null 
+0

...剛剛重讀了這個問題並編輯了答案 –

+0

它強調了第一個'FROM'關鍵字 – Furkan

+0

@Furkan,爲什麼不向我們展示你的表格? –

-1

試試這個 - 我不知道你使用正確的語法用於Oracle

UPDATE pc_discount pd 
SET ceza_ucret_turu_id = 
(SELECT 
    MAX(ceza_alt_ucret_kodu) 
    FROM 
    pc_discount_ceza pdc 
    WHERE pd.id = pdc.discount_id 
) 
WHERE pd.ceza_ucret_turu_id IS NULL 
; 

以上已與新的業務規則更新

+0

[錯誤]執行(62:3):ORA-01427:單行子查詢返回多個行 – Furkan

+0

感謝您標記 - 但子查詢來自您 - 我看不到您的數據所以我不知道你的主鍵。而不是標記我的答案,你怎麼提供更多的信息,所以我可以提供幫助。我的第一行仍然存在 - 您使用的語法錯誤 –