<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="begin-end">
      </a>
      15.6.1 BEGIN ... END Compound Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045176510544">
  </a>
  <a class="indexterm" name="idm46045176509504">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85547753"><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 punctuation">[</span><em class="replaceable">begin_label</em>:<span class="token punctuation">]</span> <span class="token keyword">BEGIN</span>
    <span class="token punctuation">[</span><em class="replaceable">statement_list</em><span class="token punctuation">]</span>
<span class="token keyword">END</span> <span class="token punctuation">[</span><em class="replaceable">end_label</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
    <code class="literal">
     BEGIN ... END
    </code>
   </a>
   syntax is used for writing compound statements, which can appear
      within stored programs (stored procedures and functions, triggers,
      and events). A compound statement can contain multiple statements,
      enclosed by the
   <code class="literal">
    BEGIN
   </code>
   and
   <code class="literal">
    END
   </code>
   keywords.
   <em class="replaceable">
    <code>
     statement_list
    </code>
   </em>
   represents a list of one
      or more statements, each terminated by a semicolon
      (
   <code class="literal">
    ;
   </code>
   ) statement delimiter. The
   <em class="replaceable">
    <code>
     statement_list
    </code>
   </em>
   itself is optional, so
      the empty compound statement (
   <code class="literal">
    BEGIN END
   </code>
   ) is
      legal.
  </p>
  <p>
   <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
    <code class="literal">
     BEGIN ... END
    </code>
   </a>
   blocks can be nested.
  </p>
  <p>
   Use of multiple statements requires that a client is able to send
      statement strings containing the
   <code class="literal">
    ;
   </code>
   statement
      delimiter. In the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   command-line client,
      this is handled with the
   <code class="literal">
    delimiter
   </code>
   command.
      Changing the
   <code class="literal">
    ;
   </code>
   end-of-statement delimiter (for
      example, to
   <code class="literal">
    //
   </code>
   ) permit
   <code class="literal">
    ;
   </code>
   to
      be used in a program body. For an example, see
   <a class="xref" href="stored-programs-defining.html" title="27.1 Defining Stored Programs">
    Section 27.1, “Defining Stored Programs”
   </a>
   .
  </p>
  <p>
   A
   <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
    <code class="literal">
     BEGIN ...
      END
    </code>
   </a>
   block can be labeled. See
   <a class="xref" href="statement-labels.html" title="15.6.2 Statement Labels">
    Section 15.6.2, “Statement Labels”
   </a>
   .
  </p>
  <p>
   The optional
   <code class="literal">
    [NOT] ATOMIC
   </code>
   clause is not
      supported. This means that no transactional savepoint is set at
      the start of the instruction block and the
   <code class="literal">
    BEGIN
   </code>
   clause used in this context has no effect
      on the current transaction.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Within all stored programs, the parser treats
    <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
     <code class="literal">
      BEGIN [WORK]
     </code>
    </a>
    as the beginning of a
    <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
     <code class="literal">
      BEGIN ...
        END
     </code>
    </a>
    block. To begin a transaction in this context, use
    <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
     <code class="literal">
      START
        TRANSACTION
     </code>
    </a>
    instead.
   </p>
  </div>
 </div>
 <br/>
</div>
