TL;博士
在PL\SQL中,我需要返回一个集合类型,我可以对其执行SELECT,但不能从记录表中进行选择:
PLS-00642: local collection types not allowed in SQL statements
.
长版本
我有一个表示图的节点的表和一个表示其定向弧的表:
node_table(
node_id int,
data
)
arc_table(
source_node_id int,
destination_node_id int
)
在一个包中,我有一个表示图遍历的递归算法。它返回当前针对某个条件和若干步骤访问的所有可能节点。它假定我们可以从任何节点开始。伪代码是这样的。
function getPossibleNodes(number_of_steps, condition):
returns node_collection_type
declare
previous_result node_collection_type
result node_collection_type
begin
if number_of_step = 0:
select node_id
bulk collect into result
from node_table;
else
previous_result = getPossibleNodes(number_of_steps - 1, condition);
select destination_node_id
bulk collect into result
from node_table join arc_table on
node_id = source_node_id
where *condition*
end id;
return result;
end;
问题在于返回数据的格式。我想返回一个记录表,声明如下:
TYPE node_search IS RECORD (
ID INT,
error_count INT,
previous_error_count INT, -- for transposition
NODE_CHARACTER VARCHAR(1)
);
TYPE se_node_search_list IS TABLE OF node_search ;
然而,在编译时,我得到了:
PLS-00642:SQL语句中不允许使用本地集合类型
.
我一直在考虑使用光标,但在每一行上循环意味着要进行选择,以便从当前节点访问每一行的节点。另外,我不确定是否可以用这种方式填充另一个游标以返回当前迭代。
我尝试将当前包中的记录类型和表类型声明为全局类型,但它无法访问当前类型。
执行此函数是为了帮助在运行时自动完成,因此我有很强的执行时间约束。但是,节点数不应高于5000。
我可以返回什么集合类型才能使其工作?