ORA-21700在SQL查询中使用polimorphism时

时间:2015-11-16 07:58:58

标签: sql oracle plsql

我有一个Oracle对象类型的层次结构,例如:

parent_t 
child_1_t under parent_t
child_2_t under parent_t

我也有一个parent_t对象的集合类型:

col_t is table of parent_t

返回此集合的函数。返回的集合可能包含child_1_t或child_2_t对象。

如果以这种方式调用,这在PL / SQL中工作正常:

l_col := fun();
-- process l_col

但是,如果从SQL调用:

select * from table(fun());

我得到ORA-21700:对象不存在或被标记为删除。

如果我更改函数的签名以仅返回子对象的集合,则一切正常。

有没有办法让它在SQL中使用父对象集合的签名?

2 个答案:

答案 0 :(得分:0)

我为您描述的方案创建了一个快速测试脚本 它按预期工作。你的功能或类型可能有问题,我希望这个工作脚本可以帮助你

select * from table(my_foo);

    ID
1   1
2   2

create or replace type parent_t as object(
id int
) not final;

create or replace type child_1_t  under parent_t
(name varchar2(10));

create or replace type child_2_t  under parent_t
(descr varchar2(10));

create or replace type collection_parent_t as table of parent_t;

create or replace function my_foo return collection_parent_t
as
  t1 child_1_t;
  t2 child_2_t;
  res collection_parent_t := collection_parent_t();
begin

  t1 :=  child_1_t(1, '1');
  t2 :=  child_2_t(2, '2');

  res.extend;
  res(res.count) := t1;

  res.extend;
  res(res.count) := t2;

  return res;
end;

答案 1 :(得分:0)

似乎我遇到了这些问题,因为我的对象类型在某种程度上被破坏了。我删除了类型,重新创建它们,现在一切都按预期工作。