title: loop through cursor data and insert record if it does not exist
body: <p>I have following tables:</p>
  
  <p>Table1:  </p>
  
  <pre><code>doc_id | item_id 
  ------ | ------
  71     | 4  
  ------ | ------
  75     | 8  
  ------ | ------
  75     | 3  
  ------ | ------
  75     | 2  
  ------ | ------
  73     | 7  
  </code></pre>
  
  <p>Table2:</p>
  
  <pre><code>id     |  parent_id | parameter_id
  ------ | -----------|-------------
   1     | 4          | 4
  ------ | -----------|-------------
   2     | 8          | 3
  ------ | -----------|-------------
   3     | 3          | 4
  ------ | -----------|------------
   4     | 2          | 6 
  ------ | -----------|------------
   5     | 7          | 4
  </code></pre>
  
  <p>I want to insert row on Table 2 by following these steps:</p>
  
  <ol>
  <li><p>Select item_ids from Table1 where document_id = 75;</p></li>
  <li><p>For each item_id from 1. check if a record exist in Table2 where
  parent_id of Table2 = item_id of Table 1 and parameter_id =4;</p></li>
  <li><p>If the record does not exist then enter data.<br>
        While inserting it should insert into Table 2 values
                 (max(id)+1, parent_id of that particular record(associated Table1's item_id), 4 as parameter_id).</p></li>
  </ol>
  
  <p>How do I do this? Can someone give me some hint. I am thinking to use cursor and loop through it and check if record exist. Then insert data accordingly??</p>
  
  <pre><code>DECLARE CURSOR C1
  IS
      SELECT * FROM table 1
      WHERE DOC_ID = 75;
  BEGIN
  FOR EACH_RECORD IN C1 LOOP
      // check for Table 2 for EACH_RECORD.CONFIG_ITEM_ID;
  END LOOP;   
  END;
  /
  </code></pre>