<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="do">
      </a>
      15.2.3 DO Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045182811488">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa67072904"><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">DO</span> <em class="replaceable">expr</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">expr</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>
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   executes the expressions but
      does not return any results. In most respects,
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   is shorthand for
   <code class="literal">
    SELECT
    <em class="replaceable">
     <code>
      expr
     </code>
    </em>
    , ...
   </code>
   , but has the
      advantage that it is slightly faster when you do not care about
      the result.
  </p>
  <p>
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   is useful primarily with
      functions that have side effects, such as
   <a class="link" href="locking-functions.html#function_release-lock">
    <code class="literal">
     RELEASE_LOCK()
    </code>
   </a>
   .
  </p>
  <p>
   Example: This
   <a class="link" href="select.html" title="15.2.13 SELECT Statement">
    <code class="literal">
     SELECT
    </code>
   </a>
   statement
      pauses, but also produces a result set:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47891606"><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">SELECT</span> <span class="token function">SLEEP</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</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>
<span class="token output"><span class="token punctuation">|</span> SLEEP(5) <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>
<span class="token output"><span class="token punctuation">|</span>        0 <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>
<span class="token output">1 row in set (5.02 sec)</span></code></pre>
  </div>
  <p>
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   , on the other hand, pauses
      without producing a result set.:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21997559"><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">DO</span> <span class="token function">SLEEP</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (4.99 sec)</span></code></pre>
  </div>
  <p>
   This could be useful, for example in a stored function or trigger,
      which prohibit statements that produce result sets.
  </p>
  <p>
   <a class="link" href="do.html" title="15.2.3 DO Statement">
    <code class="literal">
     DO
    </code>
   </a>
   only executes expressions. It
      cannot be used in all cases where
   <code class="literal">
    SELECT
   </code>
   can be
      used. For example,
   <code class="literal">
    DO id FROM t1
   </code>
   is invalid
      because it references a table.
  </p>
 </div>
 <br/>
</div>
