问题描述
我想实现一个SQL用户定义的聚合函数语言Java.我开始用一种 “hello world” 功能,这是微不足道的代码在PL/SQL-请参阅https://livesql.oracle.com/apex/livesql/s/finvtl1sfarg4x2ywvvdiwrjh
在下一步中,我使用Java类定义了一个类型来实现ODCIAggregate函数,如下所示:
但是编译失败了
我认为这是将IN OUT参数传递给Java方法的问题。
在这一点上,我被卡住了,我没有找到一些有用的引用或Java实现的用户定义的聚合函数的例子。
任何帮助都将受到高度赞赏。
在下一步中,我使用Java类定义了一个类型来实现ODCIAggregate函数,如下所示:
CREATE OR REPLACE TYPE j_hw_type AS OBJECT EXTERNAL NAME 'JHelloWorld' LANGUAGE JAVA USING SQLData( STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT j_hw_type ) RETURN NUMBER EXTERNAL NAME 'ODCIAggregateInitialize(JHelloWorld) return int', MEMBER FUNCTION ODCIAggregateIterate(self IN OUT j_hw_type , VALUE IN VARCHAR2 ) RETURN NUMBER EXTERNAL NAME 'ODCIAggregateIterate(String) return int', MEMBER FUNCTION ODCIAggregateTerminate(self IN j_hw_type, returnValue OUT VARCHAR2, flags IN NUMBER) RETURN NUMBER EXTERNAL NAME 'ODCIAggregateTerminate(String, int) return int', MEMBER FUNCTION ODCIAggregateMerge(self IN OUT j_hw_type, ctx2 IN StringAggType) RETURN NUMBER EXTERNAL NAME 'ODCIAggregateMerge(JHelloWorld) return int' ); /复制
但是编译失败了
PLS-00235: the external type is not appropriate for the parameter复制
我认为这是将IN OUT参数传递给Java方法的问题。
在这一点上,我被卡住了,我没有找到一些有用的引用或Java实现的用户定义的聚合函数的例子。
任何帮助都将受到高度赞赏。
专家解答
您觉得需要使用Java的任何特殊原因?你确定你不能用PL/SQL做到这一点?;)
你的Java代码的来源到底是什么?
可以将out参数与Java包装器一起使用。但是:
In Java and other object-oriented languages, a method cannot assign values to objects passed as arguments. When calling a method from SQL or PL/SQL, to change the value of an argument, you must declare it as an OUT or IN OUT parameter in the call specification. The corresponding Java parameter must be an array with only one element.
You can replace the element value with another Java object of the appropriate type, or you can modify the value, if the Java type permits. Either way, the new value propagates back to the caller. For example, you map a call specification OUT parameter of the NUMBER type to a Java parameter declared as float[] p, and then assign a new value to p[0].
http://docs.oracle.com/database/122/JJDEV/defining-call-specifications.htm#JJDEV13260
您可以在 (寻找raiseSal) 上看到一个示例:
http://docs.oracle.com/database/122/JJDEV/writing-object-type-call-specifications.htm#JJDEV13272
你的Java代码的来源到底是什么?
可以将out参数与Java包装器一起使用。但是:
In Java and other object-oriented languages, a method cannot assign values to objects passed as arguments. When calling a method from SQL or PL/SQL, to change the value of an argument, you must declare it as an OUT or IN OUT parameter in the call specification. The corresponding Java parameter must be an array with only one element.
You can replace the element value with another Java object of the appropriate type, or you can modify the value, if the Java type permits. Either way, the new value propagates back to the caller. For example, you map a call specification OUT parameter of the NUMBER type to a Java parameter declared as float[] p, and then assign a new value to p[0].
http://docs.oracle.com/database/122/JJDEV/defining-call-specifications.htm#JJDEV13260
您可以在 (寻找raiseSal) 上看到一个示例:
http://docs.oracle.com/database/122/JJDEV/writing-object-type-call-specifications.htm#JJDEV13272
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
Oracle DataGuard高可用性解决方案详解
孙莹
498次阅读
2025-03-26 23:27:33
Oracle RAC 一键安装翻车?手把手教你如何排错!
Lucifer三思而后行
476次阅读
2025-04-15 17:24:06
墨天轮个人数说知识点合集
JiekeXu
401次阅读
2025-04-01 15:56:03
XTTS跨版本迁移升级方案(11g to 19c RAC for Linux)
zwtian
395次阅读
2025-04-08 09:12:48
Oracle SQL 执行计划分析与优化指南
Digital Observer
368次阅读
2025-04-01 11:08:44
【纯干货】Oracle 19C RU 19.27 发布,如何快速升级和安装?
Lucifer三思而后行
357次阅读
2025-04-18 14:18:38
Oracle 19c RAC更换IP实战,运维必看!
szrsu
338次阅读
2025-04-08 23:57:08
oracle定时任务常用攻略
virvle
313次阅读
2025-03-25 16:05:19
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
312次阅读
2025-04-15 14:48:05
风口浪尖!诚通证券扩容采购Oracle 793万...
Roger的数据库专栏
309次阅读
2025-03-24 09:42:53