title: Oracle 11g PL/SQL cursor,intersect query
body: <p>I have the following query</p>
  
  <pre><code>select distinct name from table1
  intersect
  select distinct name from table2;
  </code></pre>
  
  <p>I load the resultset into a cursor in a PL/SQL procedure, like so:</p>
  
  <pre><code>cursor c1 is (select distinct name from table1
  intersect
  select distinct name from table2);
  </code></pre>
  
  <p>For some reason the last value in the resultset is duplicated in the cursor. This does not happen when running the query by itself. Any ideas why this is happening?</p>
  
  <p>Code for the loop:</p>
  
  <pre><code>var table.col%type;
  
  BEGIN
  OPEN c1;
  LOOP    
  BEGIN
    exit when c1%NOTFOUND; 
    FETCH c1 into var;       
    INSERT INTO table values (col1, var);
    commit;   
  EXCEPTION
   WHEN DUP_VAL_ON_INDEX THEN         
   CONTINUE;  
   END;
  END LOOP;    
  END;
  </code></pre>