简体   繁体   English

如何将Map传递给Oracle PL / SQL函数?

[英]How to pass Map to Oracle PL/SQL function?

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? 是否可以将Map(或某些类似的结构)传递给Oracle PL / SQL函数? I have to be able to call this function from Java somehow. 我必须能够以某种方式从Java调用此函数。

There is an interesting discussion on AskTom about passing java objects to Oracle. 在AskTom上有一个有趣的讨论,关于将Java对象传递给Oracle。 In particular IMO, this excellent advice from Tom Kyte : 特别是IMO, 汤姆·凯特(Tom Kyte)的出色建议

Me, I would juse 我,我会逗

create global temporary table gtt ( fname varchar2(20), lname varchar2(20) ) on commit delete rows; 在提交删除行上创建全局临时表gtt(fname varchar2(20),lname varchar2(20));

and have the java app BATCH insert into this and then call the procedure, the procedure just uses that tables data as its inputs. 然后将Java应用程序BATCH插入其中,然后调用该过程,该过程仅将表数据用作其输入。

that, in my experience, is the least amount of code between "me" and "being finished" 以我的经验,这是“我”和“完成”之间最少的代码量

ie: just use a set of relational temporary tables, write into it with java and let pl/sql read from the tables. 即:只使用一组关系临时表,用Java写入其中,并让pl / sql从表中读取。 It will probably be nearly as efficient (as passing objects) and it will be orders of magnitude easier to implement and debug. 它的效率(与传递对象的效率)几乎一样,并且易于实现和调试几个数量级。

Down this path lies horror and despair. 这条道路上充满着恐惧和绝望。 I have seen it. 我已经看过了。

Read this article on JDBC interface for Oracle collections first 首先阅读有关Oracle集合的JDBC接口的本文

Basically for complex objects you should use JPublisher to automatically generate the Java classes and the boilerplate code. 基本上,对于复杂对象,应使用JPublisher自动生成Java类和样板代码。 Otherwise, a simple oracle.sql.ARRAY should do. 否则,应该执行一个简单的oracle.sql.ARRAY。

Note that you also need to create matching PL/SQL objects too, read this article . 请注意,您还需要创建匹配的PL / SQL对象,请阅读本文 You don't need to implement any MEMBER methods for just passing around data between Java and Oracle. 您不需要为在Java和Oracle之间传递数据而实现任何MEMBER方法。


Edit 1: Unfortunately, PL/SQL does not have a Map concept like Java. 编辑1:不幸的是,PL / SQL没有像Java这样的Map概念。 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). 但是,您可以将Map建模为特殊(键,值)对象,也可以将其建模为简单类的Index-by表(有点像哈希映射)。

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

相关问题 如何使用 simplejdbccall 将 VARRAY(oracle PL/SQL) 参数传递给过程? - How pass VARRAY(oracle PL/SQL) param to procedure with simplejdbccall? 通过Java调用Oracle PL / SQL函数 - Call Oracle pl/sql function through java 如何使用 jOOQ 将 Oracle PL/SQL 常量作为参数传递? - How do I pass Oracle PL/SQL constants as parameters using jOOQ? 从Oracle PL / SQL将数据集传递到Java的适当方法 - Appropriate way to pass a dataset to Java from Oracle PL/SQL 如何在PL/SQL 中返回Map 中的结果? - How to return the result in Map in PL/SQL? 如何在WebSphere 7中捕获Oracle JDBC PL / SQL函数调用的参数值 - How to Capture Oracle JDBC PL/SQL Function Call's Parameter Values in WebSphere 7 如何调用具有IN / OUT参数并通过DB Link返回BLOB的Oracle PL / SQL函数 - How to call Oracle PL/SQL Function which has IN/OUT argument and returns BLOB through DB Link How to correctly develop, upload java library with dependencies to Oracle DB and call my Java function from PL\SQL? - How to correctly develop, upload java library with dependencies to Oracle DB and call my Java function from PL\SQL? 在Java中调用oracle PL / SQL函数-无效的列类型错误 - calling oracle PL/SQL function in java - Invalid column type error 调用从Java返回Oracle类型的PL / SQL函数 - Call PL/SQL function returning Oracle type from Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM