子查询删除在oracle中不起作用

subquery delete not working in 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

[table1] table(aad.id) 的 ID 然后我想删除那个 table 的记录然后我查询以下语法:

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)

怎么回事,没有要删除的记录。我不知道上面的查询没有删除记录是怎么回事。

我没有测试环境来使用语法,但尝试使用 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;
)

我认为你的问题是在查询中使用 "is null"。我不知道为什么会出现这个问题

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)

ces.id is null替换为nvl(ces.id,0) = 0