You are on page 1of 1

create table stock(It_code varchar2(6)primary key,It_nm varchar2(6),Quantity

number(6),price number(8,2));
create table sales(It_code varchar2(6),Quantity number(6));

insert into stock values('i001','maggi',40,10);


insert into stock values('i002','fruity',50,12);
insert into stock values('i003','lays',100,10);
insert into stock values('i004','gooday',140,5);
insert into stock values('i005','unibic',150,10);
insert into stock values('i007','kissan',40,80);

insert into sales values('i003',10);


insert into sales values('i007',2);

-------------------------------------------------------

----------------------------------------------------------------
create or replace function
getqnt(scd in varchar2) return number is
slqt number;
begin
select quantity into slqt from sales where it_code=scd;
return slqt;
Exception
when no_data_found then
return 0;
end;
/
----------------------------------------------------------------
declare
cursor c1 is select it_code,it_nm,quantity from stock for update of quantity;
icd stock.it_code%type;
snm stock.it_nm%type;
qty stock.quantity%type;
slqt stock.quantity%type;
begin
open c1;
loop
fetch c1 into icd,snm,qty;
exit when c1%notfound;
slqt:= getqnt(icd);
update stock
set quantity=qty-slqt where current of c1;
end loop;
close c1;
end;
/
-----------------------------------------------------------------------------------
-----

You might also like