2
create view ccc as select * from company where company_id=&cid; create cursor ddd (id in number) is products - pno,pname,categoryid,co mpanyid create cursor pro_info (pid in number) select pno,pname,category_name, company_name, select sum(amount) from purchase where prono=pid, select sum(amount) from sales where prono=pid, from products, categories, companies where products.companyid=companies.com pid a nd products.categoryid = categories.category_id and products.pno = pid; declare cominfo company_cur%ROWTYPE; begin OPEN company_cur(101); loop while company_cur % found FETCH company_cur into cominfo; insert into othercompany values(cominfo.company _id, comi nfo.company_name, cominfo.company_city); end loop; CLOSE company_cur; end; declare cominfo company_cur%ROWTYPE; begin OPEN company_cur(101); loop FETCH company_cur into cominfo; EXIT WHEN company_cur % NOTFOUND; insert into othercompany values(cominfo.compan y_id, cominfo.comp any_name, cominfo.company_city); end loop; CLOSE company_cur; end;

Cursor in Oracle

Embed Size (px)

Citation preview

Page 1: Cursor in Oracle

 

create view ccc as select * from company where company_id=&cid;create cursor ddd (id in number) is

products - pno,pname,categoryid,companyid

create cursor pro_info (pid in number)select pno,pname,category_name, company_name,select sum(amount) from purchase where prono=pid,select sum(amount) from sales where prono=pid,from products, categories, companies where products.companyid=companies.compid andproducts.categoryid = categories.category_id andproducts.pno = pid;

declarecominfo company_cur%ROWTYPE;

beginOPEN company_cur(101);loop while company_cur % found

FETCH company_cur into cominfo;insert into othercompany values(cominfo.company_id, comi

nfo.company_name, cominfo.company_city);end loop;CLOSE company_cur;

end;

declarecominfo company_cur%ROWTYPE;

beginOPEN company_cur(101);loop

FETCH company_cur into cominfo;EXIT WHEN company_cur % NOTFOUND;insert into othercompany values(cominfo.company_id, cominfo.comp

any_name, cominfo.company_city);end loop;CLOSE company_cur;

end;

Page 2: Cursor in Oracle