title: multi row update using cursors PL SQL anonymous block
body: <p>How to we write a PL SQL block for updating multiple rows at a time. The scenarios is, there are two tables <code>TABLE1,TABLE2</code> both have a common column  <code>COLUMN1</code>. In the anonymous block the cursor is defined on the <code>TABLE1</code>.</p>
  
  <p>On running the block for the first time i.e with <code>v_run:=1</code> and <code>v_offset:=2</code> ,the first two rows will be in cursor. On running the block for the second time   <code>v_run:=2</code> and next two rows from <code>TABLE1</code> will be in the cursor and so on.</p>
  
  <p>What should be <code>v_SPECIAL_VARIABLE</code> in the sample code be so that 
  on the first run i.e <code>v_run:=1</code>, first two rows(row no 1,2) are fetched in the cursor and their corresponding <code>COLUMN2</code> values in <code>TABLE2</code> are updated to <code>'N'</code> and the rest of the rows in <code>TABLE2</code> are updated to <code>'n'</code>.</p>
  
  <p>On the second run i.e <code>v_run:=2</code>  next two rows (row no 3,4) are fetched from the <code>TABLE1</code> in the cursor and their corresponding <code>COLUMN2</code> values in <code>TABLE2</code> are updated to <code>'N'</code> and the rest of the rows in <code>TABLE2</code> are updated to <code>'n'</code>.</p>
  
  <p>On the third run i.e <code>v_run:=3</code>  next two rows (row no 5,6) are fetched from the <code>TABLE1</code> in the cursor and their corresponding <code>COLUMN2</code> values in <code>TABLE2</code> are updated to <code>'N'</code> and the rest of the rows in <code>TABLE2</code> are updated to <code>'n'</code>.</p>
  
  <p>Table1 contains </p>
  
  <pre><code>id | COLUMN1     | total
  -------------------------
   1 | 1256480     | 5
   2 | 1256481     | 3
   3 | 1256482     | 2
   4 | 1256483     | 1
   5 | 1256484     | 3
   6 | 1256485     | 2
   7 | 1256486     | 1
   8 | 1256487     | 3
  </code></pre>
  
  <p>Table2 contains </p>
  
  <pre><code>   | COLUMN1     | column2
  -------------------------
    | 1256480     | N
    | 1256481     | N
    | 1256482     | N
    | 1256483     | N
    | 1256484     | N
    | 1256485     | n
    | 1256486     | n
    | 1256487     | n
  </code></pre>
  
  <p>Sample code</p>
  
  <pre><code>declare
  v_offset number:=2;
  v_run    number:=1;
  cursor curv1 is
  select column1 from 
  (select rownum rowcol,column1 from table1)
  where rowcol between (v_run-1)*v_offset+1 and v_offset*v_run;
  begin
  
  open curv1 ;
  fetch curv1 into v_SPECIAL_VARIABLE
  ----- first update
  update table2 set column2='N' where
  column1=(' ALL the values in v_SPECIAL_VARIABLE');
  ----- second update
  update table2 set column2='n' where
  column1 not in (' ALL the values in v_SPECIAL_VARIABLE');
  close curv1 ;
  end;
  </code></pre>