title: How to find out the temp space that will be required by a sql query on a database?
body: <p>we have customer who faced an issue with some inconsistent data and we gave them a query to fix it.</p>
  
  <p>Now before running the query, the customers asks me for a query that will give the temp space required for running that query. This is actually important as this query could be affecting a lot of entries in the table.</p>
  
  <p>Here is the query that I sent them to fix their issue:</p>
  
  <pre><code>declare
    cursor cur is select distinct SEQID from D_LEAD where SEQID IN( SELECT SEQID FROM D_LEAD WHERE CURR_FLAG = 1 GROUP BY
    SEQID HAVING COUNT(SEQID) &gt;1);
  
    seq NUMBER; 
  
  begin
  
    open cur;
    loop
      fetch cur into seq;
      update D_LEAD set CURR_FLAG = 0 where LEAD_ID IN (SELECT LEAD_ID FROM D_LEAD WHERE ((LEAD_ID != (SELECT MAX(LEAD_ID) FROM D_LEAD WHERE SEQID=seq)) AND SEQID=seq));
      exit when cur%NOTFOUND;
    end loop;
    close cur;
  commit;
  end;
  </code></pre>
  
  <p>Thanks for your help!</p>