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

时间:2016-07-03 23:43:09

标签: mysql stored-procedures

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

python get-pip.py

1 个答案:

答案 0 :(得分:0)

这个问题的答案部分或大部分都是在我的Answer中回答的(我在其他人面前肯定)。伪代码如下(使用伪代码并添加一点)。

主要存储程序(a.k.a. Main)

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)

请注意,如果您是唯一的人,或者说维护例程,在上述情况发生时有任何机会可以随时使用上述表格,那么会话和会话#的概念就完全没有了适用。在这种情况下,您只能自由使用表,因为没有并发问题。至少在那些工作表中。