我是 PL/SQL 的新手,编写了一个程序,但无法发现错误。
实现细节:
我使用很少的游标来遍历一个表并将一些相关数据存储在一个嵌套表中(TYPE .. IS TABLE OF varchar(8))
。
具体来说,表先决条件存储给定课程的先决条件课程。我必须找到给定课程的直接先决条件和先决条件的先决条件,如果有的话。
代码:
这里是 precoll,
TYPE precoll IS TABLE of varchar2(8);
在包中声明,下面的过程在包体中。程序:
procedure disp_prereq(p_dept_code IN varchar2, p_courseno IN number, c_prereq OUT SYS_REFCURSOR)
IS
counter INTEGER ;
preserved INTEGER ;
prelist precoll := precoll();
row prerequisites%ROWTYPE;
BEGIN
counter := 1;
preserved := 1;
cursor cr is select * from prerequisites where dept_code = p_dept_code and course# = p_courseno;
open cr;
loop
fetch cr into row;
exit when row%notfound;
prelist(counter) := (row.pre_dept_code || row.pre_course#) ;
counter := counter + 1;
end loop;
close cr;
preserved := prelist.count;
preserved := preserved + 1;
counter := 1;
cursor indr is select * from prerequisites;
open indr;
loop
fetch indr into row;
exit when row%notfound;
if (prelist(counter) = (m.dept_code||m.course#)) then
prelist(preserved) := m.pre_dept_code||m.pre_course# ;
preserved := preserved + 1;
end if;
counter := counter + 1;
end loop;
close indr;
open c_prereq FOR select * from prelist;
END disp_prereq;
并显示错误给了我:
62/9 PLS-00103: Encountered the symbol "CR" when expecting one of the
following:
:= . ( @ % ;
还有我的第二个问题,prelist 是 precoll 的变量(TYPE precoll IS TABLE of varchar2(8);)我可以通过 select 查询来查询 TYPE precoll,因为它是 varchar 的表吗?