?? 1.txt
字號:
5、 利用表tab_student在PL/SQL中編寫一過程,同時利用游標取出指定條件的學生信息輸出,要求:
1) 條件可能是學號、姓名或年齡中的一個,其中對于學號和姓名應該支持模糊查詢,對于年齡搜索比輸入值小的所有記錄;
2) 用包來編寫,其中應有一個過程或函數用來判斷用戶選擇的是什么條件
SQL> create table tab_student
2 (sno varchar2(8),
3 sname varchar2(20),
4 age integer);
insert into tab_student values('001','huang',20);
SQL> create or replace package test_package
2 is
3 procedure show_out(v_sname tab_student.sname%type);
4 procedure proc_selectby_sno(v_sno tab_student.sno%type);
5 procedure proc_selectby_sname(v_sname tab_student.sname%type);
6 procedure proc_selectby_age(v_age tab_student.age%type);
7 procedure proc_select(index_value integer,canshu varchar2);
end test_package;
------------------------------------------------------
create or replace package body test_package
as
procedure show_out(v_sname tab_student.sname%type)
as
begin
dbms_output.put_line(v_sname);
end show_out;
--begin select by sno
procedure proc_selectby_sno(v_sno tab_student.sno%type)
as
sno tab_student.sno%type;
v_sname tab_student.sname%type;
cursor mycursor(var_sno tab_student.sno%type) is select sname from tab_student where sno like var_sno;
begin
sno:=v_sno||'%';
open mycursor(sno);
loop
fetch mycursor into v_sname;
exit when mycursor%notfound;
show_out(v_sname);
end loop;
close mycursor;
end proc_selectby_sno;
--end select by sno
--begin select by sname
procedure proc_selectby_sname(v_sname tab_student.sname%type)
as
sname tab_student.sname%type;
v1_sname tab_student.sname%type;
cursor mycursor(var_sname tab_student.sname%type) is select sname from tab_student where sname like var_sname;
begin
sname:=v_sname||'%';
open mycursor(sname);
loop
fetch mycursor into v1_sname;
exit when mycursor%notfound;
show_out(v1_sname);
end loop;
close mycursor;
end proc_selectby_sname;
-- end select by sname
--begin select by age
procedure proc_selectby_age(v_age tab_student.age%type)
as
--sno tab_student.sno%type;
v_sname tab_student.sname%type;
cursor mycursor(var_age tab_student.age%type) is select sname from tab_student where age>=var_age;
begin
open mycursor(v_age);
loop
fetch mycursor into v_sname;
exit when mycursor%notfound;
show_out(v_sname);
end loop;
close mycursor;
end proc_selectby_age;
--end select by age
--begin select
procedure proc_select(index_value integer,canshu varchar2)
as
begin
case index_value
when 1 then
proc_selectby_sno(canshu);
when 2 then
proc_selectby_sname(canshu);
when 3 then
proc_selectby_age(to_number(canshu));
end case;
end proc_select;
end test_package;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -