Question

I need to take the values from a specific column in a table and place them into an array. I'm thinking to use a PL/SQL Stored procedure then calling the procedure in java and using something like:

    CallableStatement.getArray(2, myArray);

I was thinking of using something like:

SELECT column1 
INTO myVARRAY
FROM table1
WHERE table_id = t_id;

In a stored procedure But that didn't work

Was it helpful?

Solution

Presume that myVARRAY is of type varchar2. In this case you could try something like

p_col   VARCHAR2 (32);

SELECT column1 
INTO p_col
FROM table1
WHERE table_id = t_id;

and then you add p_col into your array by

myVARRAY.EXTEND;
myVARRAY (1) := p_col;

RETURN myVARRAY;

And from Java call your array by

callablestatement.registerOutParameter(2, OracleTypes.ARRAY, "MYVARRAY");

Hope this will be helpful, otherwise provide more information about your function/procedure and the type of errors you are getting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top