Asynchronous Stored Procedure Calls

2019-02-17 18:43发布

Is it possible to call a stored procedure from another stored procedure asynchronously?

Edit: Specifically I'm working with a DB2 database. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

3条回答
一纸荒年 Trace。
2楼-- · 2019-02-17 19:14

With MS Sql Server 2005, try the Service Broker and/or CLR stored procedures. I don't think there's anything built directly into TSQL.

查看更多
放荡不羁爱自由
3楼-- · 2019-02-17 19:31

Executive summary: Yes, if your database has a message queue service.

You can push a message onto a queue and the queue processor will consume it asynchronously.

  • Oracle: queues
  • Sql Server: service broker
  • DB2: event broker

For "pure" stored procedure languages (PL/Sql or T-Sql) the answer is no, since it works against the fundamental transaction model most databases have.

However, if your database has a queuing mechanism, you can use that to get the same result.

查看更多
可以哭但决不认输i
4楼-- · 2019-02-17 19:39

It sounds like you need to put some scheduled jobs in place with Cron (or windows equiv). You could use the initial stored proc call to set some kind of flag in the DB, which is then checked periodically by a cron job. If you need to have a specific delay before the 2nd job executes, you should be able to do that by having the task scheduled by the cron job.

查看更多
登录 后发表回答