Is it possible to create a dynamic SQL statement that pulls from an existing collection?
l_collection := pack.get_items(
i_code => get_items_list.i_code ,
i_name => get_items_list.i_name );
Now, let’s say I want to select a COUNT from that collection using dynamic SQL. Is that possible? Furthermore, I want to do a sub select from that collection as well.
If the collection type is declared at the schema level, it can be used in SQL statements, including dynamic ones. You need to explicitly cast it to the proper collection type, or the SQL engine has no idea what type it is.
I’m not sure if there’s some other reason you want to use dynamic SQL, or if you’re just assuming that it’s necessary in this case. It shouldn’t be necessary if all you want to do is select the count. This inline SQL should work fine:
Of course, if that’s all you want you don’t need SQL at all, just
l_count := l_collection.COUNT.Edit — adding fully worked out example