表格:stud_master
create table stud_master
(
stud_no number(5) primary key,
name varchar(10),
dob date
);
表格:stud_marksheet
create table stud_marksheet
(
stud_no number(5) references stud_master,
sub1 number(3) check(sub1>=1 and sub1<=100,
sub2 number(3) check(sub2>=1 and sub2<=100,
sub3 number(3) check(sub3>=1 and sub3<=100,
total number(5),
percentage number (5,2),
result varchar(5) check(result in('Pass','Fail'))
);
这些都是我的桌子
我曾经尝试过做一个程序,但是我不知道该怎么做。
create or replace procedure prorange
(min in out number, max in out number) is
begin
min:=&min;
max:=&max;
select * from stud_master s full join stud_marksheet m on s.stud_no=m.stud_no and s.total:=min and s.total:=max;
for i in min..max
loop
dbms_output.put_line('stud_no:'||' '||i.stud_no);
dbms_output.put_line('name:'||' '||i.name);
dbms_output.put_line('sub1:'||' '||i.sub1);
dbms_output.put_line('sub2:'||' '||i.sub2);
dbms_output.put_line('sub3:'||' '||i.sub3);
dbms_output.put_line('total:'||' '||i.total);
end loop;
end;
答案 0 :(得分:0)
尝试以下操作:
create or replace procedure prorange
(min in out number, max in out number)
is
begin
FOR i IN (select s.stud_no
, s.name
, m.sub1
, m.sub2
, m.sub3
, m.total
from stud_master s
full join stud_marksheet m
on s.stud_no=m.stud_no
where m.total between min and max)
LOOP
dbms_output.put_line('stud_no:'||' '||i.stud_no);
dbms_output.put_line('name:'||' '||i.name);
dbms_output.put_line('sub1:'||' '||i.sub1);
dbms_output.put_line('sub2:'||' '||i.sub2);
dbms_output.put_line('sub3:'||' '||i.sub3);
dbms_output.put_line('total:'||' '||i.total);
end loop;
end;
您的代码中还有一些代码异味: