Table Creation:
create table ebbill(cusno number,cus_name varchar2(20),init_read number(5),cur_read number(5),category varchar2(20));
alter table ebbill add total number(5);
Creating Function
create or replace function fun(i number,j number)
return number is s number;
begin
s:=i-j;
return s;
end;
Calling a function
declare
tno ebbill.cusno%type;
tname ebbill.cus_name%type;
initial ebbill.init_read%type;
current ebbill.cur_read%type;
category ebbill.category%type;
t number(6,2);
cursor cc is
select cusno,cus_name,init_read,cur_read,category from ebbill;
begin
open cc;
if cc%isopen then
loop
fetch cc into tno,tname,initial,current,category;
exit when cc%notfound;
if cc%found then
t:=fun(current,initial);
update ebbill set total=t where tno=ebbill.cusno;
end if;
end loop;
end if;
close cc;
end;
/
create table ebbill(cusno number,cus_name varchar2(20),init_read number(5),cur_read number(5),category varchar2(20));
alter table ebbill add total number(5);
Creating Function
create or replace function fun(i number,j number)
return number is s number;
begin
s:=i-j;
return s;
end;
Calling a function
declare
tno ebbill.cusno%type;
tname ebbill.cus_name%type;
initial ebbill.init_read%type;
current ebbill.cur_read%type;
category ebbill.category%type;
t number(6,2);
cursor cc is
select cusno,cus_name,init_read,cur_read,category from ebbill;
begin
open cc;
if cc%isopen then
loop
fetch cc into tno,tname,initial,current,category;
exit when cc%notfound;
if cc%found then
t:=fun(current,initial);
update ebbill set total=t where tno=ebbill.cusno;
end if;
end loop;
end if;
close cc;
end;
/
No comments:
Post a Comment