tags:

views:

38

answers:

2

Hi guys,

Is it possible to use SELECT FROM when using an associative array? I'm passing an array to a stored procedure through a .NET application, and I wanna be able to use that array as a condition when selecting from another table. Lets say I'm passing an array of IDs to the procedure, I wanna be able to do this:

select * from table1 where userID in (select column_value from array)

The type for the array is defined in the package:

type id_array is type of number index by pls_integer

A: 

No, you can't select from PL/SQL arrays, since you use SQL in select from statements, though you can use DB defined Nested Tables types in SQL. This short article can help you get started.

Take a look a this simple synthetic exmple:

> create type temp_t as table of int;/   
Type created.
> select 'test' from dual where 1 in (select * from table(temp_t(1,2,3)));

'TES
----
test
andr
So there's no way of accessing an associative array at all? Is it only used to pass data?
ashtame
is it possible to cast an associative array as a table?
ashtame
@ashtame not there's no way you can use associative array in SQL, only nested tables and varrays allowed.
andr
@andr: the issue is that i'm passing an associative array from vb.net to the stored procedure. Is there a way to cast an associative array into a table, or maybe a nested table?
ashtame
@ashtame If the indices in your associative array are not crucial for you then for sure you can make a nested table out of AA: just iterate through your array and populate a nested table collection in PL/SQL function
andr
A: 

Yes, it is possible, by wrapping the array with a pipelined function. Here's a good primer on pipelined functions:

http://www.oracle-developer.net/display.php?id=429

Jeffrey Kemp