gpt4 book ai didi

mysql - 如何调用存储过程将另一个存储过程的结果作为参数传递?

转载 作者:行者123 更新时间:2023-11-30 22:16:15 24 4
gpt4 key购买 nike

在伪代码中,这正是我想要实现的目标:

MAIN STORED PROCEDURE

ids = CALL GetListOfIds(_user)

FOREACH (id in ids)
CALL AnotherStoredProcedure(id)

最佳答案

这个问题的答案部分或大部分在这个 Answer 中得到了回答。我的(我相信我之前的其他人)。伪代码如下(使用您的伪代码并添加一点)。

主要存储过程(又名主要)

CALL GetListOfIds(_user) 
Note, the above stored proc populates either (A1) a temp table
or (A2) a permanent table. When I say either, it means you choose
ahead of time your strategy. In the case of (A2), an OUT parameter
is filled in to alert the call of its session# (so the call is
more like: CALL GetListOfIds(_user,mySession) ).

Ok, we have returned at this point back to Main.

Now it is decision time, again, below for choice B.

选项 B1:

Cursor

A Cursor is used to iterate thru a select stmt result against the
table strategy chosen (A1 or A2). Values are fetched into variables.
So let's call this Cursor Fetch.

FOREACH (fetch from Cursor Fetch into vars)
CALL AnotherStoredProcedure(with those vars)

or

选项 B2:

(Always and I mean always more performant, but not always possible):
Figure out the necessary sql calls to Update with a Join Pattern
or work thru other steps necessary without a cursor to arrive at
your destination. Which may include the creation of other
temporary tables or the use of permanent work tables (session-based
or not), depending on concurrency issues (other users doing the
same thing at the same time)

请注意,如果您是唯一有机会在上述情况发生时随时使用上述表格的人或维护例行人员,那么 session 和 session # 的概念根本不适用申请。在这种情况下,您可以自由使用这些表,因为没有并发问题。至少在那些工作台上。

关于mysql - 如何调用存储过程将另一个存储过程的结果作为参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38175309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com