2016-08-03 4 views
1

작동하지 삭제 :하위 쿼리 내가 합류 남아 다음 쿼리가 가입 한 오라클

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 

위의 쿼리의 결과는 다음 [표 1] 테이블의

id 
----- 
2433 
2431 

IDS (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) 

일어날 무엇, 어떤 녹화가없는 삭제할 ords. 위 쿼리가 레코드를 삭제하지 않는다는 사실을 나는 모른다.

+0

Mayby와 ces.id is null 대체이 문제가 발생하는 이유 .I 모르는 질의에 "널"문제는 사용하여 생각 , 변경 사항을 커밋하거나 롤백하지 않았습니까? –

+0

이 레코드가 없습니다. 초보자가 아닙니다. –

+0

잘 작동합니다. 마찬가지로 댓글을 달았습니다. 결과를 올바르게 확인하지 않거나 커밋하지 않은 것 같습니다. 도움이 더 필요하면 문제를 재현하는 데 사용할 수있는 최소한이지만 완전한 스크립트를 제공하십시오. – 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)