title: How to handle temporary query results in PL/SQL
body: <p>I'll describe shortly. 
  There is a column <code>DestinationId</code>
   and a column <code>HierarchyNodeId</code>
  Currently there are multiple HierarchyNodeIds for one DestinationId.
  I have a query that gives me each DestinationId and the HierarchyNodeId that I want to keep.
  So I want to replace every other HierarchyNodeId Associated with each DestinationId with the one I got from the query above.</p>
  
  <ol>
  <li>I create a Loop through the query. So each loop cycle I have a certain DestinationId (cursor."DestinationId" and a certain cursor."HierarchyNodeId")</li>
  <li>I have 3 tables that contain the column "HierarchyNodeId" and I want to update all 3 of them.</li>
  <li>In each loop cycle I have a query that finds all the HierarchyNodeIds associate with cursor."DestinationId" (current cycle DestinationId)</li>
  </ol>
  
  <p>My problem is the query in step 3 gets data from the 2 out of 3 tables that I want to Update.
  So If I use it in my updates 
  (example </p>
  
  <pre><code>UPDATE table1 
  SET table1."HierarchyNodeId"=cursor."HierarchyNodeId"
  WHERE table1."HierarchyNodeId" IN (queryfromstep3)
  </code></pre>
  
  <p>)
  Then I will have a problem since the results from queryfromstep3 will change when I do my first UPDATE.</p>
  
  <p>So I was thinking of Storing the results of queryfromstep3 into a TEMP table at the beginning of each loop.</p>
  
  <p>Is this possible in PL/SQL? Thanks a lot!</p>
  
  <p>EDIT:</p>
  
  <p>Here is the query I want to store into a TEMP</p>
  
  <pre><code>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") &gt; 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
  )
  </code></pre>
  
  <p>It basically produces 1 column with Guids.
  But some of those Guids will change after I do my first UPDATE. In order to avoid that I want to store it into a TEMP table at the beginning of each loop.</p>