DBMS 中的外部过程

发布于 2024-10-24 19:16:38 字数 183 浏览 1 评论 0原文

如果我们使用外部程序,我可以用其他语言执行一些代码,我想使用一些数值方法库进行一些矩阵计算并将结果存储在 SQL、Oracle 或任何 DBMS 中,这可能吗?

也许在 SQL 中有一个表,并告诉外部代码来处理它,我希望这尽可能快。

  • 如何实现这一点呢?
  • 外部程序是最佳选择吗?

If we use external procedures, can I execute some code in other language, I want to use some numerical methods libraries to do some matrix computing and store the result in SQL, Oracle or whatever DBMS, Is this possible?

Maybe have a table in SQL, and tell the external code, to process it, I would like this to be the fast as possible.

  • How to acommplish this?
  • Are external procedures the best choice?

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

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

发布评论

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

评论(3

几味少女 2024-10-31 19:16:38

根据您想要执行的“矩阵计算”,您可以使用 UTL_NA 包

Depending on what "matrix computing" you want to do, you may be able to do it inside Oracle itself (in 10gR2 and later) using the UTL_NA package.

那伤。 2024-10-31 19:16:38

作为一般规则。

CASE 
  WHEN "can do it in SQL" THEN SQL
  WHEN "can do it in PL/SQL" THEN PL/SQL
  WHEN "can do it in Java" THEN Java
  ELSE "External Procedure"
END

一般来说,“尽可能快”是一个糟糕的目标,因为它会导致在最好的硬件(SSD、高容量、低延迟网络组件......)上花费大量资金。 “在预算为 x 的情况下尽可能快”只是稍微合理一些。

选择一个可衡量的目标,例如 10 分钟内处理 100 万个数据项。
然后采取一种方法并计时。如果太慢,则寻找最慢的部分(例如磁盘、网络)并消除它们或优化它们。

As a general rule.

CASE 
  WHEN "can do it in SQL" THEN SQL
  WHEN "can do it in PL/SQL" THEN PL/SQL
  WHEN "can do it in Java" THEN Java
  ELSE "External Procedure"
END

Generally, "as fast as possible" is a poor target as it results in spending vast quantities of money on the very best hardware (SSDs, high capacity, low latency networking components...). "As fast as possible given a budget of $x" is only slightly more reasonable.

Pick a measurable target, such as 1 million data items processed in 10 minutes.
Then take an approach and time it. If it is too slow, then look for the slowest parts (eg disk, network) and eliminate them or optimize them.

携余温的黄昏 2024-10-31 19:16:38

您的问题确实清楚地解释了您想要实现的目标。从您的个人资料中,我可以看到您提出了很多有关 Matlab 的问题,因此我认为您想了解如何针对数据库使用 Matlab 功能。

在 Oracle 中,外部过程是服务器端操作系统例程,我们可以从数据库内的 PL/SQL 过程调用它。此功能的正常用途是将深奥的 C 功能合并到我们的代码中。近年来,由于内置 Oracle 提供的范围大幅增加,加上我们从 Java 存储过程获得的可扩展性,外部过程的使用已经越来越少。

存储过程的优点是它们在数据库内部运行,这使得它们在处理大量记录时非常有效。如果您想针对大量数据运行一些 Matlab 函数,那么将其包装为外部过程可能是正确的方法。基本上,您需要为 DLL 创建一个 LIBRARY 对象,然后为所需的库调用创建 PL/SQL 过程或函数。 了解详情

然而,数据库服务器往往针对某些类型的操作进行优化,而密集的数学并不是其中之一。因此,如果性能是关键标准,那么您最好支付 I/O 费用并通过 ODBC 连接到数据库。 了解更多

Your question does clearly explain what you want to achieve. From your profile I can see that you ask a lot of questions about Matlab so I presume you want to know about using Matlab functionality against a database.

In Oracle an external procedure is a server-side OS routine which we can call from a PL/SQL procedure inside the database. The normal use for this functionality is to incorporate esoteric C functionality into our code. External procedures have become less used in recent years due to the vast increase in the range of built-ins Oracle providss, plus the extensibility we gain from Java Stored Procedures.

The advantage of stored procedures is that they run inside the database, which makes them very efficient at processing large volumes of records. If you want to run some Matlab function againsts shedloads of data then wrapping it as an external procedure may be the right way to go. Basically you need to create a LIBRARY object for the DLL and then create PL/SQL procedures or functions for the required library calls. Find out more.

However, database servers tend to be optimized for certain types of operation, and intense mathematics is not one of them. So if performance is the key criterion then perhaps you would be better off paying the I/O toll and connect to the database through ODBC. Find out more.

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