如何在PL/SQL存储过程中调用另一个过程的输出变量?
解决PL/SQL存储过程调用的PLS-00225错误
你遇到的PLS-00225错误,核心原因是错误地将独立存储过程MinMaxGPA当作包含子过程的包来调用。p_maxStudentGPA和p_minStudentGPA是MinMaxGPA的OUT类型参数,并非可直接调用的子过程,当前调用语法完全不符合PL/SQL规则。
要通过存储过程实现需求,你需要先声明变量接收MinMaxGPA的输出值,调用存储过程获取最大、最小GPA后,再将这些值传入StudentWithGivenGPA。
修改后的ClassEnrollmentReport存储过程
create or replace procedure ClassEnrollmentReport (p_CLASSNAME in class.classname%TYPE) as v_max_gpa student.gpa%type; v_min_gpa student.gpa%type; begin -- 调用MinMaxGPA存储过程,获取最大和最小GPA MinMaxGPA(p_CLASSNAME, v_max_gpa, v_min_gpa); dbms_output.put_line('Max gpa:'); StudentWithGivenGPA(v_max_gpa); dbms_output.put_line('Min gpa:'); StudentWithGivenGPA(v_min_gpa); end ClassEnrollmentReport;
优化MinMaxGPA存储过程(可选)
原MinMaxGPA执行了两次查询,可合并为一次查询减少表访问,提升执行效率:
create or replace procedure MinMaxGPA ( p_CLASSNAME in class.classname%type, p_maxStudentGPA OUT student.gpa%type, p_minStudentGPA OUT student.gpa%type ) as begin select max(gpa), min(gpa) into p_maxStudentGPA, p_minStudentGPA from student where classno = (select classno from class where upper(classname) = upper(p_CLASSNAME)); end MinMaxGPA;
内容的提问来源于stack exchange,提问作者Liprim
相关产品推荐
相关产品推荐

