简体   繁体   English

MySQL-更新和插入过程中最后选择的输出

[英]MySQL - Output of last select in procedure with update and insert

I have a stored procedure that executes the following statements: 我有一个执行以下语句的存储过程:

  1. A select to populate a variable 选择填充变量
  2. An update utilizing said variable 使用所述变量的更新
  3. Another select to populate a second variable 另一个选择填充第二个变量
  4. An insert using the second variable 使用第二个变量的插入
  5. A select of last_insert_id() to spit out 4's insert ID to the calling application. 选择last_insert_id()将4的插入ID吐出到调用应用程序。

The SP is returning the first variable, since it is the first select. SP正在返回第一个变量,因为它是第一个选择。

Is there any way I can retrieve that last insert id, instead? 有什么办法可以代替我获取最后一个插入ID?

I know I could use the last insert id on my application's cursor, but that breaks a model I'm using. 我知道我可以在应用程序的游标上使用最后一个插入ID,但这会破坏我正在使用的模型。 I suppose I could do that as a last resort, but I'm searching for additional options. 我想我可以作为最后的选择,但是我正在寻找其他选项。

您可以在存储过程中使用OUPUT参数,存储最后插入ID的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM