I’ve got a SQL statement of the form:
BEGIN\n
UPDATE tab
SET stuff
WHERE stuff
RETURNING intA, intB, stringC
INTO ?,?,?
I’ve registered the appropriate Out parameters.
Here’s where I have some questions: Do I call stmt.executeQuery() or stmt.execute()? Further, I know with a normal SELECT query I can loop through the resultSet and populate my object — what’s the equivalent for multiple rows of Out parameters?
EDIT:
Perhaps I can register a single out parameter of type CURSOR and loop over this result.
EDIT2:
Could I potentially have multiple resultSet’s that I need to loop over?
Thanks!
I believe you can achieve what you are looking for, but you will need to handle PL/SQL arrays rather than cursors or result sets. Below is a demonstration.
I have a table, called
TEST, with the following structure:and containing the following data:
SQL> select * from test; A B C ---------- ---------- ---------- 1 2 3 4 5 6 7 8 9I need to create an array type for each type of column used. Here, I only have
NUMBERs, but if you have one or moreVARCHAR2columns as well, you’ll need to create a type for those too.The table and any necessary types are all we need to set up in the database. Once we’ve done that, we can write a short Java class that does an
UPDATE ... RETURNING ..., returning multiple values to Java:When I run this, I get the following output:
The outputs displayed are the values returned from the columns
A,BandCrespectively. There are only two values for each column since we filtered out the row withBequal to 5.You might want the values grouped by row instead of grouped by column. In other words, you might want the output to contain
[11, 2, 3]and[17, 8, 9]instead. If that’s what you want, I’m afraid you’ll need to do that part yourself.