简体   繁体   English

是否可以将行类型表从Java传递到oracle存储过程?

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

I got this type in oracle: 我在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 我已将此类型用作某些存储过程的IN(或out)参数,例如:创建或替换PROCEDURE

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

Now, I need to call this SP from Java. 现在,我需要从Java调用此SP。 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. 但是您可以在声明开始结束块中动态创建一个表,并将其传递给proc调用。 In java, create a string like this 在Java中,创建一个像这样的字符串

  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. 然后,您可以使用此构造的字符串调用proc,并在游标中预期错误。 http://docs.oracle.com/cd/A84870_01/doc/java.816/a81354/samapp2.htm http://docs.oracle.com/cd/A84870_01/doc/java.816/a81354/samapp2.htm

Hope that makes sense. 希望有道理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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