我将很快描述。
有一列DestinationId
和一列HierarchyNodeId
目前,一个DestinationId有多个HierarchyNodeIds。
我有一个查询,它给我每个DestinationId和我想要保留的HierarchyNodeId。
所以我想用每个DestinationId关联的每个其他HierarchyNodeId替换我从上面的查询得到的那个。
我的问题是第3步中的查询从我想要更新的3个表中的2个中获取数据。 所以如果我在我的更新中使用它 (例子
UPDATE table1
SET table1."HierarchyNodeId"=cursor."HierarchyNodeId"
WHERE table1."HierarchyNodeId" IN (queryfromstep3)
) 然后我会遇到问题,因为当我第一次更新时,来自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
)
它基本上生成了一个带Guids的列。 但在我第一次更新后,其中一些Guids会改变。为了避免我想在每个循环开始时将它存储到TEMP表中。
答案 0 :(得分:0)