I’d like to pass a set of record identifiers into an Oracle procedure, using a comma-separated string. I want to place this into a temp table and then join off that in further processing. How would I go about this?
Better approaches than CSV’s would be great to hear about too. I’m using ODP.Net for data access.
I don’t know anything about ODP.net, but why concatenate all the record identifiers into a CSV string?
A better approach may be to create an array parameter in your procedure and pass an array of identifiers in. I guess it depends on where you get your list of identifiers from and whether they start off as an array or CSV string?
Here is an example of using an array type and joining that to your query without using a temporary table (you could do something similar with an IN list but its harder to bind):
Note that the query in the test procedure used the ‘table’ function to turn the passed in array into a table in the query you can actually join other real tables to.
Also not that the subquery ‘a’, uses a trick to create a fake test table that contains 10 rows with values from 1 to 10 (this is just test data to prove this works).
Using the following block, we can test the code works:
So long as dbms_output is on, this should print 1 – 5, as the test data table is joined with your array!