Sie sind auf Seite 1von 3

create table customer26(

customerid varchar2(20)
constraint customer26_custid_chk check(customerid like 'C%')
constraint customer26_custid_pk primary key,
name varchar2(20) constraint customer26_name_nnull not null,
address varchar2(30) constraint customer26_address_nnull not null,
contactno number(10)
);

INSERT INTO customer26 values('C100','John','VV Mohala,Mysore',5544099);


INSERT INTO customer26 values('C200','Paul','Jayalakshmipuram',4555670);
INSERT INTO customer26 values('C300','Allen','Anna nagar',234567);

create table instructor26(


instructorid number(4) constraint instructor26_instructorid_pk primary key,
name varchar2(20) constraint instructor26_name_nnull not null,
yearsofexp number(2) constraint instructor26_yearsofexp_chk check(yearsofexp>0)
);

INSERT INTO instructor26 values(1,'Mathew',4);


INSERT INTO instructor26 values(2,'Mohammed',3);
INSERT INTO instructor26 values(3,'Rex',5);

create table workout_schedule26(


customerid varchar2(4) constraint wkrout_sch26_custid_fk references customer26(c
ustomerid),
instructorid number(4) constraint wkrout_sch26_instrid_fk references instructor2
6(instructorid),
programme varchar2(2) constraint wkrout_sch26_pg_chk check(programme in('WL','WG
')),
startdate date constraint wkrout_sch26_strtdt_nnull NOT NULL,
weight number(3) constraint wkrout_sch26_wt_chk check(weight>30),
constraint wkrout_schedule26_cpk primary key(customerid,instructorid)
);

insert into workout_schedule26 values('C100',1,'WL','01-feb-2006',87);


insert into workout_schedule26 values('C200',1,'WG','05-jan-2006',56);
insert into workout_schedule26 values('C300',1,'WL','10-mar-2006',90);

create or replace function sf_insertgym(


p_customerid in varchar2,
p_instructor in number,
p_prog varchar2,
p_startdate in date,
p_weight number
)return number
is
v_return number;
begin
insert into workout_schedule26 values(p_customerid,p_instructor,p_prog,p_startda
te,p_weight);
v_return:=1;
return v_return;

exception
when no_data_found then
v_return:=2;
return v_return;
when others then
v_return:=0;
return v_return;

end sf_insertgym;
declare
v_Status number(5);
begin
v_Status:=sf_insertgym('C200',3,'WL','28-feb-2007',83);
dbms_output.put_line(v_Status);
end;

create or replace function sf_avgweight(


p_programme in workout_schedule26.programme%type,
p_totalcustomers out number)
return number
is
v_return number;
v_weight number;
v_avgweight number;
v_count number;
begin
select count(*) into v_count from workout_schedule26
where programme=p_programme;
dbms_output.put_line(v_count);
select sum(weight) into v_weight from workout_schedule26
where programme=p_programme;
v_avgweight:=v_weight/v_count;
return v_avgweight;

exception
when no_data_found then
v_return:=2;
return v_return;
when others then
v_return:=0;
return v_return;
end sf_avgweight;
declare
v_Status number(5);
v_out number(4,2);
begin
v_Status:=sf_avgweight('WG',v_out);
dbms_output.put_line(v_Status);
end;

Das könnte Ihnen auch gefallen