gpt4 book ai didi

具有子查询分解的 Oracle DELETE 语句

转载 作者:行者123 更新时间:2023-12-03 03:10:19 25 4
gpt4 key购买 nike

尝试执行此操作(适用于 SQL Server):

WITH X AS (), Y AS (), Z AS ()
DELETE FROM TBL
WHERE TBL.ID IN (SELECT ID FROM Z);

这在 Oracle 中有效:

WITH X AS (), Y AS (), Z AS ()
SELECT * FROM TBL
WHERE TBL.ID IN (SELECT ID FROM Z);

但 DELETE 没有:ORA-00928:缺少 SELECT 关键字

我的子查询相当大,是否有不同的语法可以使其工作?

最佳答案

除了 SELECT 语句之外,您不能将子查询分解/CTE 与任何其他语句一起使用。 From the documentation:

You can specify this clause in any top-level SELECT statement and in most types of subqueries.

你可以这样做:

DELETE FROM tbl WHERE tbl.id IN
(WITH X AS (), Y AS (), Z AS ()
SELECT id FROM TBL
WHERE TBL.ID IN (SELECT ID FROM Z));

关于具有子查询分解的 Oracle DELETE 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6603171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com