如何将 Map 传递给 Oracle PL/SQL 函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1322162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass Map to Oracle PL/SQL function?
提问by Ula Krukar
I would like to create an equivalent if this Java method as PL/SQL function in Oracle 10g:
如果此 Java 方法作为 Oracle 10g 中的 PL/SQL 函数,我想创建一个等效项:
String myMethod(int par1, Map<String, Object> par2);
Is it possible to pass a Map (or some simillar structure) to Oracle PL/SQL function? I have to be able to call this function from Java somehow.
是否可以将 Map(或一些类似的结构)传递给 Oracle PL/SQL 函数?我必须能够以某种方式从 Java 调用这个函数。
回答by Vincent Malgrat
There is an interesting discussion on AskTomabout passing java objects to Oracle. In particular IMO, this excellent advice from Tom Kyte:
AskTom 上有一个关于将 java 对象传递给 Oracle的有趣讨论。尤其是 IMO,来自 Tom Kyte 的这个极好的建议:
Me, I would juse
create global temporary table gtt ( fname varchar2(20), lname varchar2(20) ) on commit delete rows;
and have the java app BATCH insert into this and then call the procedure, the procedure just uses that tables data as its inputs.
that, in my experience, is the least amount of code between "me" and "being finished"
我,我会判断
在提交删除行时创建全局临时表 gtt ( fname varchar2(20), lname varchar2(20) );
并将 Java 应用程序 BATCH 插入其中,然后调用该过程,该过程仅使用该表数据作为其输入。
根据我的经验,这是“我”和“正在完成”之间的最少代码
i-e: just use a set of relational temporary tables, write into it with java and let pl/sql read from the tables. It will probably be nearly as efficient (as passing objects) and it will be orders of magnitude easier to implement and debug.
即:只需使用一组关系临时表,用java写入并让pl/sql从表中读取。它可能几乎与传递对象一样有效,并且实现和调试将更容易几个数量级。
回答by Andreas Petersson
Down this pathlies horror and despair. I have seen it.
沿着这条路走下去是恐惧和绝望。我已经见过了。
回答by Andrew not the Saint
Read this article on JDBC interface for Oracle collections first
首先阅读这篇关于 Oracle 集合的 JDBC 接口的文章
Basically for complex objects you should use JPublisherto automatically generate the Java classes and the boilerplate code. Otherwise, a simple oracle.sql.ARRAY should do.
基本上对于复杂的对象,您应该使用JPublisher自动生成 Java 类和样板代码。否则,应该使用简单的 oracle.sql.ARRAY。
Note that you also need to create matching PL/SQL objects too, read this article. You don't need to implement any MEMBER methods for just passing around data between Java and Oracle.
请注意,您还需要创建匹配的 PL/SQL 对象,请阅读本文。您不需要实现任何 MEMBER 方法来仅在 Java 和 Oracle 之间传递数据。
Edit 1: Unfortunately, PL/SQL does not have a Map concept like Java. However, you can model a Map as a special (Key,Value) object or as an Index-by table for simple class (sort of like a hash map).
编辑 1:不幸的是,PL/SQL 没有像 Java 那样的 Map 概念。但是,您可以将 Map 建模为特殊的 (Key,Value) 对象或简单类的索引表(有点像散列映射)。