PLSQL-具有多个记录的过程

时间:2018-11-19 01:25:26

标签: stored-procedures plsql oracle12c record

创建一个称为先决条件的过程。使用四个字段创建用户定义的记录:course_no,description,cost和prerequisite_rec。最后一个字段prerequisite_rec应该是用户定义的记录,其中包含三个字段:prereq_no,prereq_desc和prereq_cost。对于所有具有前提课程的课程,请用所有相应的数据填充用户定义的记录,然后在屏幕上显示其信息。

我试图弄清楚这个问题,其措辞令人困惑。据我了解,将与一个带有4个用户定义字段的记录一起创建一个过程,但是这4个字段中的1个也是其中包含3个字段的记录本身。

这正确吗?

这是我到目前为止要做的。

CREATE OR REPLACE PROCEDURE prerequisites (course_no IN NUMBER, 
description OUT VARCHAR2, cost OUT NUMBER, prereq_no OUT NUMBER
,prereq_desc OUT VARCHAR2, prereq_cost OUT NUMBER)
IS
v_course course.course_no%TYPE;

BEGIN
v_course := course_no;
SELECT description, cost, prerequisite
  INTO description, cost, prereq_no
  FROM course
 WHERE course_no = v_course;

SELECT description, cost
  INTO prereq_desc, prereq_cost
  FROM course
 WHERE course_no = prereq_no;


END;
/

DECLARE
TYPE prereqs IS RECORD (prereq_no NUMBER, prereq_desc VARCHAR2(50), prereq_cost NUMBER);
TYPE courses IS RECORD (course_no NUMBER, description VARCHAR2(50), cost NUMBER,
    prerequisite_rec prereqs);

BEGIN
courses.course_no := 25;

prerequisites(courses.course_no, courses.description, courses.cost, prereqs.prereq_no
    ,prereqs.prereq_desc, prereqs.cost);

DBMS_OUTPUT.PUT_LINE(courses.course_no || ' and ' || prereqs.prereq_no);

END;
/

过程很好,但是执行主块时出现ORA-06550错误。

ORA-06550: line 7, column 5:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 7, column 5:
PL/SQL: Statement ignored
ORA-06550: line 9, column 19:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 9, column 5:
PL/SQL: Statement ignored
ORA-06550: line 12, column 26:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 12, column 5:
PL/SQL: Statement ignored

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

认为您对要求的要求是正确的...在声明类型之前,需要先声明子类型。例如(未经测试,请耐心等待)

Declare

 TYPE prerequisite IS RECORD (prereq_no NUMBER, 
    prereq_desc VARCHAR2(50), prereq_cost NUMBER)

 TYPE courses IS RECORD (course_no NUMBER, description VARCHAR2(50), 
    cost NUMBER, prerequisite_rec prerequisite);

v_blah courses;

begin
   do stuff
end;
/