ORA-00932 如果在 where 子句中的递归 CTE 中使用了集合

ORA-00932 if collection used in recursive CTE in where clause

我有集合类型列的递归 CTE(这里使用 sys.ku$_vcnt 因为它是内置的,任何集合类型都可以重现问题)。当集合列用于 where 子句中 CTE 的递归部分时,查询失败并出现 ORA-00932: inconsistent datatypes: expected UDT got SYS.KU$_VCNT 错误。

这是最小化的示例,在实际情况下,集合内容在 where 子句中检查。任何集合的出现似乎都足以使查询失败——例如,不进行空检查,如下例所示:

with r (l, dummy_coll, b) as (
  select 1 as l, sys.ku$_vcnt(), null from dual
  union all
  select l + 1
       , r.dummy_coll
       , case when r.dummy_coll is not null then 'not null' else 'null' end as b
  from r
  where l < 5 and r.dummy_coll is not null
)
select * from r;

如果从 where 子句中删除 and r.dummy_coll is not null,则查询成功。 select 子句中集合的出现不是问题(b 列显示集合实际上不为空)。

为什么它不起作用以及如何强制 Oracle 在 where 子句中查看先前递归级别的集合列?

转载于 Oracle 11 和 Oracle 18 (dbfiddle)。

谢谢!

是的,我觉得这像是一个错误。标量 select 似乎是一种解决方法。这对你有用吗?

SQL> with r (l, dummy_coll, b) as (
  2    select 1 as l, sys.ku$_vcnt(), null from dual
  3    union all
  4    select l + 1
  5         , r.dummy_coll
  6         , case when r.dummy_coll is not null then 'not null' else 'null' end as b
  7    from r
  8    where l < 5 and ( select r.dummy_coll from dual ) is not null
  9  )
 10  select * from r;

L,DUMMY_COLL,B
1,KU$_VCNT(),
2,KU$_VCNT(),not null
3,KU$_VCNT(),not null
4,KU$_VCNT(),not null
5,KU$_VCNT(),not null