|
create or replace procedure PrintStudentInfo isbeginfor student_cur in (select * from student) loopdbms_output.put(student_cur.sid || '/');dbms_output.put(student_cur.sname|| '/');dbms_output.put_line(student_cur.saddress);end loop;end PrintStudentInfo
create or replace package USER_PKG isTYPE student_info is record (ID student.sid%type,name student.sname%type,birth student.sbirth%type,addr student.saddress%type);procedure PrintStudentInfo;function GetStudentInfo(id in varchar2) return student_info;end USER_PKG;
create or replace package body USER_PKG iscursor student_cur is select sid,sname,sbirth,saddress from student;procedure PrintStudentInfo isStudentInfo student_info;beginopen student_cur;fetch student_cur into StudentInfo;while student_cur%found loopdbms_output.put(StudentInfo.ID || '/');dbms_output.put(StudentInfo.name|| '/');dbms_output.put(StudentInfo.birth|| '/');dbms_output.put_line(StudentInfo.addr|| '/');fetch student_cur into StudentInfo;end loop;close student_cur;exceptionwhen invalid_cursor thendbms_output.put_line('invalid cursor');when cursor_already_open thendbms_output.put_line('cursor already open');end PrintStudentInfo;function GetStudentInfo(id in varchar2) return student_infoisStudentInfo student_info;beginselect sid,sname, sbirth,saddressinto StudentInfofrom studentwhere sid = id;return StudentInfo;exceptionwhen no_data_found thendbms_output.put_line('no data found');end GetStudentInfo;end USER_PKG; |
|
|