[英]Calling oracle function using database link
我在远程数据库中创建了一个名为getEmployee(id in varchar)
的 oracle function ,我正在尝试使用数据库链接从本地数据库中调用它。
在getEmployee
,我试图返回带有员工数据的 cursor。(表:员工(ID,姓名,地址)):
SELECT schema.getEmployee@dblink(id)
FROM DUAL;
如何获得带有列名(ID、名称、地址)的结果集?
根据Contrad,我像这样更改了我的本地function;
FUNCTION LocalGetEmployee(ID in varchar2)
RETURN Schema.SomeRefCursor
AS
OUTPUT Schema.SomeRefCursor;
BEGIN
OUTPUT := schema.getEmployee@dblink(ID);
RETURN OUTPUT;
END;
但是,当我从 Java 代码中调用此 function 时,会出现以下错误:
“ORA-24338: 语句句柄未执行”
在远程站点获取 Ref Cursor:
假设我们有两个站点涉及分布式事务,Server1 和 Server2。 在 Server1 过程中打开的 Ref Cursor 无法在 Server2 站点获取。 如果我们尝试获取此 cursor oracle 会引发异常:
[ORA-02055: distributed update operation failed; rollback required
ORA-24338: statement handle not executed]
“我们不能在 DBLink 上使用 Ref Cursor”
解决方案:
As far as I can tell your question isn't really about database links but rather how, from a Java client, to call a function that returns a cursor and retrieve the data from that cursor. 我相信在 Java 中做到这一点的唯一方法是将 function 调用包装在一些“程序”代码中。 我面前没有 Oracle 所以这是一些猜测:
String fncall = "begin ? := schema.getEmployee@dblink(?) end";
CallableStatement stm = con.prepareCall(fncall);
stm.registerOutParameter(1, Types.CURSOR);
stm.setInt(2, 123);
stm.execute();
ResultSet rs = (ResultSet) stm.getObject(1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.