PL/SQL: Inserting the values of a column of a table into an array or VARRAY to be accessed by java?

StackOverflow https://stackoverflow.com/questions/13428939

Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top