2016-08-03 66 views
1

工作我已被接合並且左以下查詢加入:子查詢刪除未在Oracle

select aad.id 
        from [table1] aad 
        left outer join [table2] itm 
        on aad.table2_id = itm.id 
        left outer join [table3] eac 
        on aad.id = eac.table1_id 
        LEFT JOIN [table4] ces 
        ON eac.car_id = ces.id 
        LEFT join [table5] ci 
        on ces.car_information_id = ci.id 
       INNER join [table6] groupBi 
        on aad.capatibilty_degree_group_id = groupBi.id 
       where ces.id is null 
        and aad.depot_ammu_estimate = 123 

上述查詢的結果是:

id 
----- 
2433 
2431 

IDS [表1]表中的( aad.id),那麼我想刪除該表的這個記錄,然後我的查詢語法如下:

delete 
    FROM [table1] w 
where w.id in (select aad.id 
        from [table1] aad 
        left outer join [table2] itm 
        on aad.table2_id = itm.id 
        left outer join [table3] eac 
        on aad.id = eac.table1_id 
        LEFT JOIN [table4] ces 
        ON eac.car_id = ces.id 
        LEFT join [table5] ci 
        on ces.car_information_id = ci.id 
       INNER join [table6] groupBi 
        on aad.capatibilty_degree_group_id = groupBi.id 
       where ces.id is null 
        and aad.depot_ammu_estimate = 123) 

它是什麼發生,沒有REC ords刪除。我不知道上述查詢不會刪除記錄。

+0

Mayby更換ces.id is null您已經刪除,但沒有提交/回滾更改? –

+0

沒有這條記錄exists.i我不是初學者 –

+0

應該工作正常。 Like被評論,你可能沒有正確地檢查結果或沒有提交,等等。如果你想得到進一步的幫助,請提供一個最小但完整的腳本,我們可以用它來重現你的問題。 – sstan

回答

1

nvl(ces.id,0) = 0

0

我沒有測試env來處理語法,但嘗試使用EXIST子句。像這樣的東西。

DELETE FROM [table1] t WHERE 
EXISTS 
(
    select 1 
        from [table1] aad 
        left outer join [table2] itm 
        on aad.table2_id = itm.id 
        left outer join [table3] eac 
        on aad.id = eac.table1_id 
        LEFT JOIN [table4] ces 
        ON eac.car_id = ces.id 
        LEFT join [table5] ci 
        on ces.car_information_id = ci.id 
       INNER join [table6] groupBi 
        on aad.capatibilty_degree_group_id = groupBi.id 
       where ces.id is null 
        and aad.depot_ammu_estimate = 123 
and aad.id=t.id; 
) 
1

我認爲你的問題是使用「爲空」查詢。我不知道爲什麼會發生這個問題

delete 
    FROM [table1] w 
where w.id in (select aad.id 
        from [table1] aad 
        left outer join [table2] itm 
        on aad.table2_id = itm.id 
        left outer join [table3] eac 
        on aad.id = eac.table1_id 
        LEFT JOIN [table4] ces 
        ON eac.car_id = ces.id 
        LEFT join [table5] ci 
        on ces.car_information_id = ci.id 
       INNER join [table6] groupBi 
        on aad.capatibilty_degree_group_id = groupBi.id 
       where nvl(ces.id,0)=0 
        and aad.depot_ammu_estimate = 123)