在存储例程(存储过程或函数)或触发器的主体中,LAST_INSERT_ID() 的值的变化方式与在这些对象主体外执行语句时相同(参见 第 14.15 节,“信息函数”)。存储例程或触发器对 LAST_INSERT_ID() 值的影响,后续语句看到的结果取决于例程的类型:Within the body of a stored routine (procedure or function) or a
trigger, the value of
LAST_INSERT_ID() changes the same
way as for statements executed outside the body of these kinds of
objects (see Section 14.15, “Information Functions”). The effect
of a stored routine or trigger upon the value of
LAST_INSERT_ID() that is seen by
following statements depends on the kind of routine:
如果存储过程执行会改变
LAST_INSERT_ID()值的语句,则在调用该过程后,随后的语句将看到被更改的值。If a stored procedure executes statements that change the value ofLAST_INSERT_ID(), the changed value is seen by statements that follow the procedure call.对于更改该值的存储函数和触发器,当函数或触发器结束时,值会恢复,因此后续语句不会看到已更改的值。For stored functions and triggers that change the value, the value is restored when the function or trigger ends, so following statements do not see a changed value.