title: Optimizing SQL by using temporary table in Oracle
body: <p>I have a data cleanup-er procedure which deletes the same data from the card rows of two tables.
  Both of these update statement use the same subQuery for detecting which rows should be updated. </p>
  
  <pre><code> UPDATE table_1 SET card = NULL WHERE id in
                 (select id from sub_table WHERE /* complex clause here */);
  
   UPDATE table_2 SET card = NULL WHERE id in
                 (select id from sub_table WHERE /* complex clause here */);
  </code></pre>
  
  <p><strong>Is using Oracle Temporary table good solution for optimizing my code?</strong></p>
  
  <pre><code>CREATE TEMPORARY TABLE tmp_sub_table AS
  select id from sub_table WHERE /* complex clause here */;
  
  UPDATE table_1 SET card = NULL WHERE id in (select * from tmp_sub_table);    
  UPDATE table_2 SET card = NULL WHERE id in (select * from tmp_sub_table);
  </code></pre>
  
  <p>Should I use <strong>Local temporary</strong> table or <strong>Global Temporary</strong> table?</p>