Friday, 12 April 2024

WHERE CURRENT OF Cursor Loop


WHERE CURRENT OF  clause is used in conjuction with  FOR UPDATE   to update / delete current working row in a cursor for loop.

The  WHERE CURRENT OF  clause in an UPDATE or DELETE statement states that the most recent row fetched from the table should be updated or deleted. We must declare the cursor with the  FOR UPDATE clause to use this feature

Inside a cursor loop, WHERE CURRENT OF allows the current row to be directly updated

Declare
cursor c1 is
  Select    row_number()over(order by process_id)  lineno , process_id, line_item_no
  from wbbs_to_ar where notional_invoice_no='11011875' for update;
Begin
  For cx in c1
  Loop

   update wbbs_to_ar set line_item_no = cx.lineno where current of c1;
  End Loop;
End;

No comments:

Post a Comment