I need to use this code in a PL/SQL package:
Var_All Varchar2(100) := '''var1'',''var2''';
Select ... many fields ...
Bulk Collect Into ResultTable
From ... many tables with joins
Where my_table.MC01 IN (Var_All);
As far as I know, I cannot use the variable Var_All with an IN clause because the data is lost due to the apostrophes.
The variables var1, var2, varN are strings that actually only contain numbers, so it would also be good if I could compare the value of the my_table.MC01 field with numbers.
I found two solutions, but I don’t like either of them.
-
Dynamic SQL
-
Cursor, where I make some of these changes:
Instead of IN clause: Where my.table.MC01 = record.var;
And instead of “Bulk Collect Into”, I would call a separate procedure where I put the data into the ResultTable.
Is there a better solution?