Uploaded by Rama Mercy cs

14

advertisement
PL/SQL Block Using Explicit Cursors
Program Coding:
Creation of Table:
create table elec(name varchar2(10),address varchar2(30),city varchar2(10),unit
number(4));
Insertion of Values:
insert into elec values('&name','&address','&city',&unit);
PL/SQL BLOCK:
set serveroutput on;
declare
CURSOR tot IS select * from elec;
e electric61%ROWTYPE;
begin
OPEN tot;
dbms_output.put_line('name '||' address '||' city '||' unit ');
loop
FETCH tot into e;
if(tot%NOTFOUND)then
exit;
else
if(e.unit<100)then
dbms_output.put_line(e.name||'
'||e.address||' '||e.city||' '||e.unit*1);
elsif(e.unit>=200 AND e.unit<300)then
dbms_output.put_line(e.name||'
'||e.address||' '||e.city||' '||e.unit*2);
elsif(e.unit>=300 AND e.unit<500)then
dbms_output.put_line(e.name||''||e.address||''||e.city||''||e.unit*3);
else
dbms_output.put_line(e.name||''||e.address||''||e.city||''||e.unit*5);
end if;
end if;
end loop;
CLOSE tot;
end;
/
To Display the Table:
Select * from elec;
Download