我会简短地描述。一列DestinationId
一列HierarchyNodeId
目前一个DestinationId有多个HierarchyNodeId。我有一个查询,它为我提供了我想要保留的每个 DestinationId 和 HierarchyNodeId。因此,我想将与每个 DestinationId 关联的所有其他 HierarchyNodeId 替换为我从上面的查询中获得的那个。
- 我通过查询创建了一个循环。所以每个循环周期我都有一个 DestinationId (cursor."DestinationId" 和某个 cursor."HierarchyNodeId")
- 我有 3 个包含“HierarchyNodeId”列的表,我想更新所有 3 个。
- 在每个循环周期中,我都有一个查询,可以找到与 cursor."DestinationId"(当前循环 DestinationId)关联的所有 HierarchyNodeIds
我的问题是第 3 步中的查询从我要更新的 3 个表中的 2 个获取数据。所以如果我在更新中使用它(例如
UPDATE table1
SET table1."HierarchyNodeId"=cursor."HierarchyNodeId"
WHERE table1."HierarchyNodeId" IN (queryfromstep3)
) 然后我会遇到问题,因为当我进行第一次 UPDATE 时,queryfromstep3 的结果会发生变化。
所以我想在每个循环开始时将 queryfromstep3 的结果存储到一个 TEMP 表中。
这在 PL/SQL 中可能吗?非常感谢!
编辑:
这是我要存储到 TEMP 中的查询
SELECT "HierarchyNodeId" FROM
(
Select t1."Counter", t2.* From
(SELECT "HierarchyNodeId", (SELECT "Description"
FROM "Destination"
WHERE "DestinationId" = hn."DestinationId") "Description", "DestinationId",
(SELECT "DestinationTypeId"
FROM "Destination"
WHERE "DestinationId" = hn."DestinationId") "DestinationTypeId"
FROM "HierarchyNode" hn
WHERE "DestinationId" IN (SELECT "DestinationId" From(SELECT COUNT ("HierarchyNodeId"), "DestinationId" FROM "HierarchyNode" GROUP BY "DestinationId" HAVING COUNT ("HierarchyNodeId") > 1))) t2,
(select COUNT (*) "Counter", "HierarchyNodeId" From "HierarchyDetail"
Group By "HierarchyNodeId") t1
Where t1."HierarchyNodeId" = t2."HierarchyNodeId"
AND t2."DestinationId" = cur."DestinationId"
AND t2."HierarchyNodeId" != cur."HierarchyNodeId"
ORDER BY "DestinationId", "Counter" Desc
)
它基本上会产生 1 列带有 Guid 的列。但是在我进行第一次更新后,其中一些指南会发生变化。为了避免这种情况,我想在每个循环开始时将其存储到 TEMP 表中。