我在数据库中创建了一个对象类型,并想在包中声明一个记录类型,以便使用引用游标循环提取数据,但这似乎不适用于对象类型。如何在不创建虚拟表的情况下实现这一点?我想使用如下所示的on可能会奏效,但我不知道该怎么做。type_object
type_record
%ROWTYPE
type_table
/* type_object has been created before */
declare
type type_table is table of type_object;
l_rec type_table%ROWTYPE; -- doesn't work
l_refcursor sys_refcursor;
begin
open l_refcursor for 'select * from mytable';
loop
fetch l_refcursor into l_rec;
exit when l_refcursor%notfound;
-- do something with l_rec
end loop;
close l_refcursor;
end;
你不能,语法不支持它。
但是,您可以使用光标的
CURSOR
然后:%ROWTYPE
或者
MYTABLE%ROWTYPE
:或者类似地,使用强类型游标:
或者在查询中使用
type_object
并作为中间变量的类型:小提琴