简体   繁体   中英

Is it possible to pass a table of rowtype from java to an oracle stored procedure?

I got this type in oracle:

TYPE "RequestTable" IS TABLE OF "Requests"%ROWTYPE;

I have used this type as an IN(or out) parameter of some stored procedures, like this: create or replace PROCEDURE

"RegisterRequestsBulk" 
(
  Par_RequestsBulk IN "TableTypes"."RequestTable"  
, ErrorCodeTable OUT "TableTypes"."ErrorCodeTable"
) AS 
BEGIN
...

Now, I need to call this SP from Java. How should I pass this kind of parameters?

The link in the comments is the "correct" way to do this. But you could create a table on the fly in a declare begin end block, and pass that to your proc call. In java, create a string like this

  declare 
    lvTable RequestTable; 
    lvError ErrorCodeTable;
  begin 
      select col1, col2 
      BULK COLLECT INTO lvTable          
      from ( 
     ****
     java loop to create lvTable in java string 
      SELECT col1, col2 -- row 1
       FROM dual
      union all          
      SELECT col1, col2 -- row n
       FROM dual
     ****
     );
     RegisterRequestsBulk(lvTable, lvError); 
     open :? for select * from table(lvError); 
  end;

Then you can call your proc with this constructed string and expect the errors in a cursor. http://docs.oracle.com/cd/A84870_01/doc/java.816/a81354/samapp2.htm

Hope that makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM