<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="call">
      </a>
      15.2.1 CALL Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045183065056">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96773000"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">CALL</span> <em class="replaceable">sp_name</em><span class="token punctuation">(</span><span class="token punctuation">[</span><em class="replaceable">parameter</em><span class="token punctuation">[</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token keyword">CALL</span> <em class="replaceable">sp_name</em><span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   The
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   statement invokes a stored
      procedure that was defined previously with
   <a class="link" href="create-procedure.html" title="15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements">
    <code class="literal">
     CREATE PROCEDURE
    </code>
   </a>
   .
  </p>
  <p>
   Stored procedures that take no arguments can be invoked without
      parentheses. That is,
   <code class="literal">
    CALL p()
   </code>
   and
   <code class="literal">
    CALL p
   </code>
   are equivalent.
  </p>
  <p>
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   can pass back values to its
      caller using parameters that are declared as
   <code class="literal">
    OUT
   </code>
   or
   <code class="literal">
    INOUT
   </code>
   parameters.
      When the procedure returns, a client program can also obtain the
      number of rows affected for the final statement executed within
      the routine: At the SQL level, call the
   <a class="link" href="information-functions.html#function_row-count">
    <code class="literal">
     ROW_COUNT()
    </code>
   </a>
   function; from the C
      API, call the
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-affected-rows.html" target="_top">
    <code class="literal">
     mysql_affected_rows()
    </code>
   </a>
   function.
  </p>
  <p>
   For information about the effect of unhandled conditions on
      procedure parameters, see
   <a class="xref" href="conditions-and-parameters.html" title="15.6.7.8 Condition Handling and OUT or INOUT Parameters">
    Section 15.6.7.8, “Condition Handling and OUT or INOUT Parameters”
   </a>
   .
  </p>
  <p>
   To get back a value from a procedure using an
   <code class="literal">
    OUT
   </code>
   or
   <code class="literal">
    INOUT
   </code>
   parameter, pass
      the parameter by means of a user variable, and then check the
      value of the variable after the procedure returns. (If you are
      calling the procedure from within another stored procedure or
      function, you can also pass a routine parameter or local routine
      variable as an
   <code class="literal">
    IN
   </code>
   or
   <code class="literal">
    INOUT
   </code>
   parameter.) For an
   <code class="literal">
    INOUT
   </code>
   parameter, initialize
      its value before passing it to the procedure. The following
      procedure has an
   <code class="literal">
    OUT
   </code>
   parameter that the
      procedure sets to the current server version, and an
   <code class="literal">
    INOUT
   </code>
   value that the procedure increments by
      one from its current value:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24794474"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DELIMITER</span> <span class="token comment" spellcheck="true">//</span>

<span class="token keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> p <span class="token punctuation">(</span><span class="token keyword">OUT</span> ver_param <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">25</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">INOUT</span> incr_param <span class="token datatype">INT</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token comment" spellcheck="true"># Set value of OUT parameter</span>
  <span class="token keyword">SELECT</span> <span class="token function">VERSION</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">INTO</span> ver_param<span class="token punctuation">;</span>
  <span class="token comment" spellcheck="true"># Increment value of INOUT parameter</span>
  <span class="token keyword">SET</span> incr_param <span class="token operator">=</span> incr_param <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">END</span> <span class="token comment" spellcheck="true">//</span>

<span class="token keyword">DELIMITER</span> <span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Before calling the procedure, initialize the variable to be passed
      as the
   <code class="literal">
    INOUT
   </code>
   parameter. After calling the
      procedure, you can see that the values of the two variables are
      set or modified:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10057317"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@increment</span> <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">CALL</span> p<span class="token punctuation">(</span><span class="token variable">@version</span><span class="token punctuation">,</span> <span class="token variable">@increment</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token variable">@version</span><span class="token punctuation">,</span> <span class="token variable">@increment</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> @version <span class="token punctuation">|</span> @increment <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 8.4.3   <span class="token punctuation">|</span>         11 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <p>
   In prepared
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   statements used
      with
   <a class="link" href="prepare.html" title="15.5.1 PREPARE Statement">
    <code class="literal">
     PREPARE
    </code>
   </a>
   and
   <a class="link" href="execute.html" title="15.5.2 EXECUTE Statement">
    <code class="literal">
     EXECUTE
    </code>
   </a>
   , placeholders can be used
      for
   <code class="literal">
    IN
   </code>
   parameters,
   <code class="literal">
    OUT
   </code>
   , and
   <code class="literal">
    INOUT
   </code>
   parameters. These types of parameters can
      be used as follows:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa31879145"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@increment</span> <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">PREPARE</span> s <span class="token keyword">FROM</span> <span class="token string">'CALL p(?, ?)'</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">EXECUTE</span> s <span class="token keyword">USING</span> <span class="token variable">@version</span><span class="token punctuation">,</span> <span class="token variable">@increment</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token variable">@version</span><span class="token punctuation">,</span> <span class="token variable">@increment</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> @version <span class="token punctuation">|</span> @increment <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 8.4.3   <span class="token punctuation">|</span>         11 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <p>
   To write C programs that use the
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   SQL statement to execute
      stored procedures that produce result sets, the
   <code class="literal">
    CLIENT_MULTI_RESULTS
   </code>
   flag must be enabled. This
      is because each
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   returns a
      result to indicate the call status, in addition to any result sets
      that might be returned by statements executed within the
      procedure.
   <code class="literal">
    CLIENT_MULTI_RESULTS
   </code>
   must also be
      enabled if
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   is used to execute
      any stored procedure that contains prepared statements. It cannot
      be determined when such a procedure is loaded whether those
      statements produce result sets, so it is necessary to assume that
      they do so.
  </p>
  <p>
   <code class="literal">
    CLIENT_MULTI_RESULTS
   </code>
   can be enabled when you
      call
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-real-connect.html" target="_top">
    <code class="literal">
     mysql_real_connect()
    </code>
   </a>
   , either
      explicitly by passing the
   <code class="literal">
    CLIENT_MULTI_RESULTS
   </code>
   flag itself, or implicitly by passing
   <code class="literal">
    CLIENT_MULTI_STATEMENTS
   </code>
   (which also enables
   <code class="literal">
    CLIENT_MULTI_RESULTS
   </code>
   ).
   <code class="literal">
    CLIENT_MULTI_RESULTS
   </code>
   is enabled by default.
  </p>
  <p>
   To process the result of a
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   statement executed using
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-query.html" target="_top">
    <code class="literal">
     mysql_query()
    </code>
   </a>
   or
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-real-query.html" target="_top">
    <code class="literal">
     mysql_real_query()
    </code>
   </a>
   , use a loop
      that calls
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-next-result.html" target="_top">
    <code class="literal">
     mysql_next_result()
    </code>
   </a>
   to
      determine whether there are more results. For an example, see
   <a class="ulink" href="/doc/c-api/8.4/en/c-api-multiple-queries.html" target="_top">
    Multiple Statement Execution Support
   </a>
   .
  </p>
  <p>
   C programs can use the prepared-statement interface to execute
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   statements and access
   <code class="literal">
    OUT
   </code>
   and
   <code class="literal">
    INOUT
   </code>
   parameters.
      This is done by processing the result of a
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   statement using a loop that
      calls
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-stmt-next-result.html" target="_top">
    <code class="literal">
     mysql_stmt_next_result()
    </code>
   </a>
   to
      determine whether there are more results. For an example, see
   <a class="ulink" href="/doc/c-api/8.4/en/c-api-prepared-call-statements.html" target="_top">
    Prepared CALL Statement Support
   </a>
   . Languages that
      provide a MySQL interface can use prepared
   <a class="link" href="call.html" title="15.2.1 CALL Statement">
    <code class="literal">
     CALL
    </code>
   </a>
   statements to directly
      retrieve
   <code class="literal">
    OUT
   </code>
   and
   <code class="literal">
    INOUT
   </code>
   procedure parameters.
  </p>
  <p>
   Metadata changes to objects referred to by stored programs are
      detected and cause automatic reparsing of the affected statements
      when the program is next executed. For more information, see
   <a class="xref" href="statement-caching.html" title="10.10.3 Caching of Prepared Statements and Stored Programs">
    Section 10.10.3, “Caching of Prepared Statements and Stored Programs”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
