Following query fails on ORA-00904
. Why?
with t (id, parent_id) as (
select 1, 2 from dual
)
, wrapper (id, parent_id) as (
select * from t where parent_id = 2
)
, wrapper_with_elements (id, elements) as (
select u.id, sys.odcinumberlist(1) as elements
from wrapper u
)
select (
select cast(collect(cast(ru.id as number)) as sys.odcinumberlist)
from wrapper_with_elements ru
) as agg1
, (
select cast(collect(cast(ru.id as number)) as sys.odcinumberlist)
from wrapper_with_elements ru
) as agg2
from wrapper w
ORA-00904: "PARENT_ID": invalid identifier
Db fiddle for Oracle 11g, however it works same way even on newest Oracle 21c version.
The query comes from more complex practical query and after minimization it became somewhat nonsense. However any attempt of further simplification makes error disappear, namely:
- replacing any or both
from wrapper
forfrom t
as it is same data - replacing
sys.odcinumberlist(1)
fornull
or any scalar value - inlining
wrapper_with_elements
intofrom
clause in correlated subqueries of main query - removing any of
agg1
,agg2
columns
Does someone has an idea what is going wrong there? Although the query is silly I would expect it to return value.
I suspect this is some Oracle bug related to collection usage (because once I managed to make some workaround run without bind variables but with bind variables it failed with ORA-600: Internal Error Code, Arguments: [qcsfbdnp:1]
which disappeared only after collection handling removal) but I don't want it to be treated as misleading conclusion. In real case I use custom nested table type but the effect is the same, I used sys.odcinumberlist
just to make example easily reproducible.