dblink 上的 Oracle sql 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/642035/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:55:18  来源:igfitidea点击:

Oracle sql types over dblink

oraclecollectionsuser-defined-typesdblink

提问by drnk

I have two schemas: A and B (Oracle 9). At the A there is a dblink to B. At the B there is a package, that i calls from A. Procedures in B package can returns varying count results and i think that returning a collection is a better way for this reason.

我有两个模式:A 和 B(Oracle 9)。在 A 处有一个到 B 的 dblink。在 B 处有一个包,我从 A 调用它。B 包中的过程可以返回不同的计数结果,我认为由于这个原因,返回一个集合是更好的方法。

create type B.tr_rad as object (
  name     varchar2(64)
 ,code     number
 ,vendor   number
 ,val      varchar2(255)
 ,num      number
);

create type B.tt_rad as varray(256) of B.tr_rad;

But from A scheme I cannot use tt_rad type because using SQL-types by dblink is not supported. DBMS_SQL is not supported cursors. Create types with same OID is impossible.

但是从方案中我不能使用 tt_rad 类型,因为不支持通过 dblink 使用 SQL 类型。DBMS_SQL 不支持游标。创建具有相同 OID 的类型是不可能的。

I think to use temporary tables. But firstly it is not that good (after the remote function returns the value, calling side must select collection from remote table). And there are fears of a slowdown of work with temporary tables.

我想使用临时表。但首先它不是那么好(远程函数返回值后,调用方必须从远程表中选择集合)。并且担心临时表的工作速度会减慢。

Maybe who knows the alternative interaction?

也许谁知道替代交互?

采纳答案by Aussie Craig

I've had similar problems in the past. Then I came to the conclusion that fundamentally Oracle's db links are "broken" for anything but simple SQL types (especially UDT's, CLOBS may have problems, XMLType may as well). If you can get the OID solution working then good luck to you.

我过去也遇到过类似的问题。然后我得出的结论是,除了简单的 SQL 类型(尤其是 UDT,CLOBS 可能有问题,XMLType 也可能有问题),Oracle 的 db 链接从根本上说是“损坏的”。如果你能让 OID 解决方案工作,那么祝你好运。

The solution I resorted to was to use a Java Stored procedure, instead of the DB Link.

我采用的解决方案是使用 Java 存储过程,而不是 DB Link。

Characteristics of the Java Stored Procedure:

Java存储过程的特点:

  1. Can return a "rich set of types", just about all of the complex types (UDT's, tables/arrays/varrays) see Oracle online documentationfor details. Oracle does a much better job of marshalling complex (or rich) types from java, than from a DBLink.
  2. Stored Java can acquire the "default connection" (runs in the same session as the SQL connection to the db - no authentication issues).
  3. Stored Java calls the PL/SQL proc on the remote DB, and the java JDBC layer does the marshaling from the remote DB.
  4. Stored Java packages up the result and returns the results to the SQL or PL/SQL layer.
  1. 可以返回“丰富的类型集”,几乎所有复杂类型(UDT、表/数组/变量)请参阅Oracle 在线文档了解详细信息。与 DBLink 相比,Oracle 在从 Java 编组复杂(或丰富)类型方面做得更好。
  2. 存储的 Java 可以获得“默认连接”(在与数据库的 SQL 连接相同的会话中运行 - 没有身份验证问题)。
  3. 存储的 Java 调用远程 DB 上的 PL/SQL proc,Java JDBC 层从远程 DB 执行封送处理。
  4. Stored Java 将结果打包并返回到 SQL 或 PL/SQL 层。

It's a bit of work, but if you have a bit of java, you should be able to "cut and paste" a solution together from the Oracle documentation and sample.

这需要一些工作,但是如果您有一些 Java,您应该能够从 Oracle 文档和示例中“剪切和粘贴”一个解决方案。

I hope this helps.

我希望这有帮助。

回答by drnk

My solution. On the side Bi create temporary table like the collection record. At the Aside i have a DBMS_SQL wrapper that calls procedure over dblink. This procedure writes result collection in the temporary table. After successful completion remote procedure i select results from remote temporary table and transform it to local collection type.

我的解决方案。在B侧,我创建了临时表,如集合记录。在A端,我有一个 DBMS_SQL 包装器,它通过 dblink 调用过程。此过程将结果集合写入临时表中。成功完成远程过程后,我从远程临时表中选择结果并将其转换为本地集合类型。

Limitations 1. the need for permanent object synchronization. 2. impossibility use A-side procedure (that call remote procedure) in SQL query. 3. the complexity of using.

限制 1. 需要永久对象同步。2. 不可能在 SQL 查询中使用 A 端过程(即调用远程过程)。3.使用的复杂性。

回答by Matthew Watson

回答by tuinstoel

An alternative interaction is to have onedatabase with schemas A and B instead of two databases with a database link.

另一种交互是拥有一个具有模式 A 和 B 的数据库,而不是具有数据库链接的两个数据库。