通过 dblink 的 Oracle sql 类型

发布于 2024-07-15 04:33:18 字数 515 浏览 5 评论 0原文

我有两个模式: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;

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

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

也许谁知道另一种互动?

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.

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云之铃。 2024-07-22 04:33:18

我过去也遇到过类似的问题。 然后我得出的结论是,从根本上来说,Oracle 的数据库链接对于除简单 SQL 类型之外的任何内容都是“损坏的”(尤其是 UDT、CLOBS 可能有问题,XMLType 也可能有问题)。 如果您能让 OID 解决方案正常运行,那么祝您好运。

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

Java 存储过程的特征:

  1. 可以返回“丰富的类型集”,几乎所有复杂类型(UDT、表/数组/varrays)请参见 Oracle 在线文档了解详细信息。 Oracle 在从 java 编组复杂(或丰富)类型方面比从 DBLink 做得更好。
  2. 存储的 Java 可以获取“默认连接”(与数据库的 SQL 连接在同一会话中运行 - 没有身份验证问题)。
  3. 存储的 Java 调用远程 DB 上的 PL/SQL 过程,并且 java JDBC 层从远程 DB 进行封送。
  4. 存储的Java将结果打包并将结果返回给SQL或PL/SQL层。

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

我希望这有帮助。

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.

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

Characteristics of the Java Stored Procedure:

  1. Can return a "rich set of types", just about all of the complex types (UDT's, tables/arrays/varrays) see Oracle online documentation for 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.

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.

I hope this helps.

南街女流氓 2024-07-22 04:33:18

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

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

世俗缘 2024-07-22 04:33:18

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

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

My solution.
On the side B i create temporary table like the collection record. At the A side 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文