PL/SQL 等待 Oracle 中的更新

发布于 2024-10-30 10:40:30 字数 380 浏览 3 评论 0原文

如何创建 PL/SQL 函数,该函数在指定的超时时间内等待某行的更新,然后返回。

我想要完成的是 - 我有一个长时间运行的进程,它将通过 process_id 将其状态更新为 ASYNC_PROCESS 表。我需要在该过程完成时返回 true/false 的函数,而且我还需要该函数等待该过程完成一段时间,超时返回或在过程完成时立即返回 true。我不想使用 sleep(1 sec),因为在这种情况下我会有 1 秒的延迟。我不想使用 sleep(1 msec),因为在这种情况下我会消耗 cpu 资源(和 1 msec 滞后)。

有经验的程序员有什么好方法可以实现这一点吗?

该函数将从 .NET 调用(因此我需要数据库操作和 .NET/UI 之间的最小延迟)

THNX, 牛肉

How do I create PL/SQL function which waits for update on some row for specified timeout and then returns.

What I want to accomplish is - I have long running process which will update it's status to ASYNC_PROCESS table by process_id. I need function which returns with true/false when this process has completed, but also I need this function to wait some time for this process complete, return on timeout or return imediately with true, when process has completed. I don't want to use sleep(1 sec), because in such case I will be having 1 sec lag. I don't want to use sleep(1 msec), because in such case I am spending cpu resources (and 1msec lag).

Is there a good way how experienced programmer would accomplish this?

That function will be called from .NET (So I need minimal lag between DB operation and .NET/UI)

THNX,
Beef

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

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

发布评论

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

评论(3

挖鼻大婶 2024-11-06 10:40:30

我认为在这种情况下最明智的做法是使用 update 在该 ASYNC_PROCESS 表上触发

您还应该查看 DBMS_ALERT 包。以下是该文档的编辑摘录:

创建警报:

DBMS_ALERT.REGISTER('emp_table_alert');

在表上创建触发器来触发警报:

CREATE TRIGGER emptrig AFTER INSERT ON emp
BEGIN 
   DBMS_ALERT.SIGNAL('emp_table_alert', 'message_text'); 
END;

从您的 .net 代码中,您可以使用调用此内容的内容:

DBMS_ALERT.WAITONE('emp_table_alert', :message, :status, :timeout); 

请确保阅读有关 :status:timeout 功能的文档。

I think the most sensible thing to do in this case is to use update triggers on that ASYNC_PROCESS table.

You should also look into the DBMS_ALERT package. Here's an edited excerpt from that doc:

Create an alert:

DBMS_ALERT.REGISTER('emp_table_alert');

Create a trigger on your table to fire the alert:

CREATE TRIGGER emptrig AFTER INSERT ON emp
BEGIN 
   DBMS_ALERT.SIGNAL('emp_table_alert', 'message_text'); 
END;

From your .net code, you can the use something that calls this:

DBMS_ALERT.WAITONE('emp_table_alert', :message, :status, :timeout); 

Make sure you read the docs for what :status and :timeout do.

阿楠 2024-11-06 10:40:30

您应该查看 Oracle高级排队。它提供了您正在寻找的功能。

您可能需要一个单独的队列表,其中 ASYNC_PROCESS 上的触发器插入消息。然后,您可以使用 AQ 函数检索(或等待)队列表中的下一条消息。

You should look at Oracle Advanced Queuing. It offers the kind of functions your looking for.

You'll probably need a separate queue table where a trigger on ASYNC_PROCESS inserts messages. You then use the AQ functions to retrieve (or wait for) the next message in the queue table.

辞旧 2024-11-06 10:40:30

如果您在 C#.NET 中执行此操作,为什么不简单地生成一个工作线程来执行更新(通过 ODAC)?当(看起来)您希望 .NET 进程进行更新调用(在后台)并让主进程收到更新完成通知时,为什么要将责任交给 Oracle?

请参阅此处此处 为例,尽管 .NET 中有多种方法(委托、事件、异步回调、线程池等)

If you're doing this in C#.NET, why wouldn't you simply spawn a worker thread to do the update (via ODAC)? Why hand the responsibility over to Oracle when (it seems) you want a .NET process to make the update call (in background) and have the main process be notified of its completion.

See here and here for examples, although there are several approaches in .NET for this (delegates, events, async callbacks, thread pools, etc)

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