Assuming that you mean a collection of numbers (there are three collection types in PL/SQL, one of which is an associative array, but that doesn't sound like what you want here), you could do something like
CREATE OR REPLACE TYPE num_tbl
AS TABLE OF NUMBER;
Then, in your procedure
l_nums num_tbl;
BEGIN
SELECT some_number
BULK COLLECT INTO l_nums
FROM <<your query to get the numbers>>;
<<more code>>
OPEN O_SHIPMENTS_CURSOR FOR
SELECT *
FROM Q194977.AN_SHIPMENT_INFO SI
WHERE INTERNAL_ASN IN (SELECT column_value
FROM TABLE( l_nums ))
ORDER BY INTERNAL_ASN;
That is syntactically valid. Whether it is actually going to be useful to you, however, is a separate question.
- Collections are stored in the relatively expensive PGA memory on the database server. If you're storing a couple hundred numbers in a collection, that's probably not a huge concern. If, on the other hand, you're storing 10's or 100's of MB of data and running this in multiple sessions, this one bit of code could easily consume many GB of the RAM on the database server leading to lots of performance issues.
- Moving large quantities of data from SQL to PL/SQL and then back to SQL can also be somewhat problematic from a performance standpoint-- it's generally more efficient to leave everything in SQL and let the SQL engine handle it.
- If you use a collection in this way, you're preventing the optimizer from considering join orders and query plans that merge the two queries in a more efficient manner. If you are certain that the most efficient plan is one where a small number of
internal_asn
values are used to probe thean_shipment_info
table using an index, that may not be a major concern. If you're not sure about what the best query plan is, and particularly if your actual queries are more complicated than what you posted, however, you might be preventing the optimizer from using the most efficient plan for each query.
What is the problem that you're trying to solve? You talk about not wanting to duplicate code. That would lead me to suspect that you really just want a view that you can reference in your queries rather than repeating the code for a complicated SQL statement. But that presumes that the issue you're trying to solve is one of code elegance which may or may not be accurate.