My own type
CREATE OR REPLACE TYPE chain_t AS TABLE OF NUMBER(11);
select column as this type in select statement
select
x.id,
cast(multiset(select parent_id from table(x.parents)) as chain_t) as chain
from
xxxx x
if x.parents have values i have next result, for example:
chain_t(22, 44)
or if dont have
chain_t(null)
How i can count rows in chain?? For example in first result 2 rows in second result 0 rows
Use the CARDINALITY()
function. Find out more.
select id, chain, cardinality(chain)
from (
select
x.id,
cast(multiset(select parent_id from x) as chain_t) as chain
from x
)
/
Here is a SQL Fiddle based on this simplified version of your posted code.