Jul 192013
 
declare
  cursor wallet_contents is 
    select money 
    from   wallet
    for    update;
  
  baby_equipment_stores wallet%rowtype;
begin
  open wallet_contents;
  
  loop
    fetch wallet_contents
    into  baby_equipment_stores;
    
    exit when wallet_contents%notfound;
  end loop;
  
  close wallet_contents;
end;
/
Ah, the never-ending cycle of baby related paraphernalia to purchase.

create table wallet_contents (money number(10, 2));
insert into wallet_contents values (10);
declare
cursor wallet is
select money
from wallet_contents
for update;

child_stores wallet%rowtype;
begin
open wallet;

fetch wallet
into child_stores;
loop
update wallet_contents
set money = money – 1
returning money into child_stores.money;
exit when child_stores.money <= 0;
dbms_output.put_line(child_stores.money );
end loop;
close wallet;
end;
/

drop table wallet_contents purge;