If a collection type is declared at the schema level, it can be used in SQL operations, including dynamic ones. You need to explicitly cast it to the appropriate collection type, or the SQL engine does not know what type it is.
EXECUTE IMMEDIATE
'SELECT COUNT(*) FROM TABLE(CAST(:collection AS collection_type))'
INTO l_count
USING l_collection
;
, , SQL, , . , , , . SQL :
SELECT COUNT(*) INTO l_count FROM TABLE(CAST(l_collection AS collection_type));
, , , SQL, l_count := l_collection.COUNT.
-
CREATE OR REPLACE TYPE testtype AS OBJECT( x NUMBER, y NUMBER);
/
CREATE OR REPLACE TYPE testtypetab AS TABLE OF testtype;
/
DECLARE
t testtypetab := testtypetab();
l_count integer;
BEGIN
SELECT testtype(LEVEL, LEVEL) BULK COLLECT INTO t FROM dual CONNECT BY LEVEL<21;
SELECT count(*) INTO l_count FROM TABLE(CAST(t AS testtypetab));
dbms_output.put_line( l_count );
t.DELETE;
EXECUTE IMMEDIATE 'select count(*) from table(cast(:collection as testtypetab))'
into l_count using t;
dbms_output.put_line( l_count );
END;
/