<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="stored-routines-last-insert-id">
      </a>
      27.2.4 Stored Procedures, Functions, Triggers, and LAST_INSERT_ID()
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045082444688">
  </a>
  <a class="indexterm" name="idm46045082443200">
  </a>
  <a class="indexterm" name="idm46045082441712">
  </a>
  <a class="indexterm" name="idm46045082440224">
  </a>
  <p>
   Within the body of a stored routine (procedure or function) or a
      trigger, the value of
   <a class="link" href="information-functions.html#function_last-insert-id">
    <code class="literal">
     LAST_INSERT_ID()
    </code>
   </a>
   changes the same
      way as for statements executed outside the body of these kinds of
      objects (see
   <a class="xref" href="information-functions.html" title="14.15 Information Functions">
    Section 14.15, “Information Functions”
   </a>
   ). The effect
      of a stored routine or trigger upon the value of
   <a class="link" href="information-functions.html#function_last-insert-id">
    <code class="literal">
     LAST_INSERT_ID()
    </code>
   </a>
   that is seen by
      following statements depends on the kind of routine:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      If a stored procedure executes statements that change the
          value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      , the
          changed value is seen by statements that follow the procedure
          call.
     </p>
    </li>
    <li class="listitem">
     <p>
      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.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
