<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="signal">
      </a>
      15.6.7.5 SIGNAL Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045175667120">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59702304"><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">SIGNAL</span> <em class="replaceable">condition_value</em>
    <span class="token punctuation">[</span><span class="token keyword">SET</span> <em class="replaceable">signal_information_item</em>
    <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">signal_information_item</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>

<em class="replaceable">condition_value</em>: {
    <span class="token keyword">SQLSTATE</span> <span class="token punctuation">[</span><span class="token keyword">VALUE</span><span class="token punctuation">]</span> <em class="replaceable">sqlstate_value</em>
  <span class="token operator">|</span> <em class="replaceable">condition_name</em>
}

<em class="replaceable">signal_information_item</em>:
    <em class="replaceable">condition_information_item_name</em> <span class="token operator">=</span> <em class="replaceable">simple_value_specification</em>

<em class="replaceable">condition_information_item_name</em>: {
    <span class="token keyword">CLASS_ORIGIN</span>
  <span class="token operator">|</span> <span class="token keyword">SUBCLASS_ORIGIN</span>
  <span class="token operator">|</span> <span class="token keyword">MESSAGE_TEXT</span>
  <span class="token operator">|</span> <span class="token keyword">MYSQL_ERRNO</span>
  <span class="token operator">|</span> <span class="token keyword">CONSTRAINT_CATALOG</span>
  <span class="token operator">|</span> <span class="token keyword">CONSTRAINT_SCHEMA</span>
  <span class="token operator">|</span> <span class="token keyword">CONSTRAINT_NAME</span>
  <span class="token operator">|</span> <span class="token keyword">CATALOG_NAME</span>
  <span class="token operator">|</span> <span class="token keyword">SCHEMA_NAME</span>
  <span class="token operator">|</span> <span class="token keyword">TABLE_NAME</span>
  <span class="token operator">|</span> <span class="token keyword">COLUMN_NAME</span>
  <span class="token operator">|</span> <span class="token keyword">CURSOR_NAME</span>
}

<em class="replaceable">condition_name</em><span class="token punctuation">,</span> <em class="replaceable">simple_value_specification</em>:
    <span class="token punctuation">(</span>see <span class="token keyword">following</span> discussion<span class="token punctuation">)</span></code></pre>
  </div>
  <p>
   <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
    <code class="literal">
     SIGNAL
    </code>
   </a>
   is the way to
   <span class="quote">
    “
    <span class="quote">
     return
    </span>
    ”
   </span>
   an error.
   <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
    <code class="literal">
     SIGNAL
    </code>
   </a>
   provides error information
        to a handler, to an outer portion of the application, or to the
        client. Also, it provides control over the error's
        characteristics (error number,
   <code class="literal">
    SQLSTATE
   </code>
   value, message). Without
   <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
    <code class="literal">
     SIGNAL
    </code>
   </a>
   ,
        it is necessary to resort to workarounds such as deliberately
        referring to a nonexistent table to cause a routine to return an
        error.
  </p>
  <p>
   No privileges are required to execute the
   <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
    <code class="literal">
     SIGNAL
    </code>
   </a>
   statement.
  </p>
  <p>
   To retrieve information from the diagnostics area, use the
   <a class="link" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
    <code class="literal">
     GET DIAGNOSTICS
    </code>
   </a>
   statement (see
   <a class="xref" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
    Section 15.6.7.3, “GET DIAGNOSTICS Statement”
   </a>
   ). For information about the
        diagnostics area, see
   <a class="xref" href="diagnostics-area.html" title="15.6.7.7 The MySQL Diagnostics Area">
    Section 15.6.7.7, “The MySQL Diagnostics Area”
   </a>
   .
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="signal.html#signal-overview" title="SIGNAL Overview">
       SIGNAL Overview
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="signal.html#signal-condition-information-items" title="Signal Condition Information Items">
       Signal Condition Information Items
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="signal.html#signal-effects" title="Effect of Signals on Handlers, Cursors, and Statements">
       Effect of Signals on Handlers, Cursors, and Statements
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="signal-overview">
       </a>
       SIGNAL Overview
      </h5>
     </div>
    </div>
   </div>
   <p>
    The
    <em class="replaceable">
     <code>
      condition_value
     </code>
    </em>
    in a
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement indicates the
          error value to be returned. It can be an
    <code class="literal">
     SQLSTATE
    </code>
    value (a 5-character string
          literal) or a
    <em class="replaceable">
     <code>
      condition_name
     </code>
    </em>
    that
          refers to a named condition previously defined with
    <a class="link" href="declare-condition.html" title="15.6.7.1 DECLARE ... CONDITION Statement">
     <code class="literal">
      DECLARE ...
          CONDITION
     </code>
    </a>
    (see
    <a class="xref" href="declare-condition.html" title="15.6.7.1 DECLARE ... CONDITION Statement">
     Section 15.6.7.1, “DECLARE ... CONDITION Statement”
    </a>
    ).
   </p>
   <p>
    An
    <code class="literal">
     SQLSTATE
    </code>
    value can indicate errors,
          warnings, or
    <span class="quote">
     “
     <span class="quote">
      not found.
     </span>
     ”
    </span>
    The first two
          characters of the value indicate its error class, as discussed
          in
    <a class="xref" href="signal.html#signal-condition-information-items" title="Signal Condition Information Items">
     Signal Condition Information Items
    </a>
    . Some
          signal values cause statement termination; see
    <a class="xref" href="signal.html#signal-effects" title="Effect of Signals on Handlers, Cursors, and Statements">
     Effect of Signals on Handlers, Cursors, and Statements
    </a>
    .
   </p>
   <p>
    The
    <code class="literal">
     SQLSTATE
    </code>
    value for a
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement should not
          start with
    <code class="literal">
     '00'
    </code>
    because such values
          indicate success and are not valid for signaling an error.
          This is true whether the
    <code class="literal">
     SQLSTATE
    </code>
    value is
          specified directly in the
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement or in a named
          condition referred to in the statement. If the value is
          invalid, a
    <code class="literal">
     Bad SQLSTATE
    </code>
    error occurs.
   </p>
   <p>
    To signal a generic
    <code class="literal">
     SQLSTATE
    </code>
    value, use
    <code class="literal">
     '45000'
    </code>
    , which means
    <span class="quote">
     “
     <span class="quote">
      unhandled
          user-defined exception.
     </span>
     ”
    </span>
   </p>
   <p>
    The
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement optionally
          includes a
    <code class="literal">
     SET
    </code>
    clause that contains
          multiple signal items, in a list of
    <em class="replaceable">
     <code>
      condition_information_item_name
     </code>
    </em>
    =
    <em class="replaceable">
     <code>
      simple_value_specification
     </code>
    </em>
    assignments, separated by commas.
   </p>
   <p>
    Each
    <em class="replaceable">
     <code>
      condition_information_item_name
     </code>
    </em>
    may
          be specified only once in the
    <code class="literal">
     SET
    </code>
    clause.
          Otherwise, a
    <code class="literal">
     Duplicate condition information
          item
    </code>
    error occurs.
   </p>
   <p>
    Valid
    <em class="replaceable">
     <code>
      simple_value_specification
     </code>
    </em>
    designators can be specified using stored procedure or
          function parameters, stored program local variables declared
          with
    <a class="link" href="declare.html" title="15.6.3 DECLARE Statement">
     <code class="literal">
      DECLARE
     </code>
    </a>
    , user-defined
          variables, system variables, or literals. A character literal
          may include a
    <em class="replaceable">
     <code>
      _charset
     </code>
    </em>
    introducer.
   </p>
   <p>
    For information about permissible
    <em class="replaceable">
     <code>
      condition_information_item_name
     </code>
    </em>
    values, see
    <a class="xref" href="signal.html#signal-condition-information-items" title="Signal Condition Information Items">
     Signal Condition Information Items
    </a>
    .
   </p>
   <p>
    The following procedure signals an error or warning depending
          on the value of
    <code class="literal">
     pval
    </code>
    , its input parameter:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7279585"><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">CREATE</span> <span class="token keyword">PROCEDURE</span> p <span class="token punctuation">(</span>pval <span class="token datatype">INT</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token keyword">DECLARE</span> specialty <span class="token keyword">CONDITION</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'45000'</span><span class="token punctuation">;</span>
  <span class="token keyword">IF</span> pval <span class="token operator">=</span> <span class="token number">0</span> <span class="token keyword">THEN</span>
    <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'01000'</span><span class="token punctuation">;</span>
  <span class="token keyword">ELSEIF</span> pval <span class="token operator">=</span> <span class="token number">1</span> <span class="token keyword">THEN</span>
    <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'45000'</span>
      <span class="token keyword">SET</span> <span class="token keyword">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'An error occurred'</span><span class="token punctuation">;</span>
  <span class="token keyword">ELSEIF</span> pval <span class="token operator">=</span> <span class="token number">2</span> <span class="token keyword">THEN</span>
    <span class="token keyword">SIGNAL</span> specialty
      <span class="token keyword">SET</span> <span class="token keyword">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'An error occurred'</span><span class="token punctuation">;</span>
  <span class="token keyword">ELSE</span>
    <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'01000'</span>
      <span class="token keyword">SET</span> <span class="token keyword">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'A warning occurred'</span><span class="token punctuation">,</span> <span class="token keyword">MYSQL_ERRNO</span> <span class="token operator">=</span> <span class="token number">1000</span><span class="token punctuation">;</span>
    <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'45000'</span>
      <span class="token keyword">SET</span> <span class="token keyword">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'An error occurred'</span><span class="token punctuation">,</span> <span class="token keyword">MYSQL_ERRNO</span> <span class="token operator">=</span> <span class="token number">1001</span><span class="token punctuation">;</span>
  <span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    If
    <code class="literal">
     pval
    </code>
    is 0,
    <code class="literal">
     p()
    </code>
    signals a warning because
    <code class="literal">
     SQLSTATE
    </code>
    values
          that begin with
    <code class="literal">
     '01'
    </code>
    are signals in the
          warning class. The warning does not terminate the procedure,
          and can be seen with
    <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement">
     <code class="literal">
      SHOW
          WARNINGS
     </code>
    </a>
    after the procedure returns.
   </p>
   <p>
    If
    <code class="literal">
     pval
    </code>
    is 1,
    <code class="literal">
     p()
    </code>
    signals an error and sets the
    <code class="literal">
     MESSAGE_TEXT
    </code>
    condition information item. The error terminates the
          procedure, and the text is returned with the error
          information.
   </p>
   <p>
    If
    <code class="literal">
     pval
    </code>
    is 2, the same error is signaled,
          although the
    <code class="literal">
     SQLSTATE
    </code>
    value is specified
          using a named condition in this case.
   </p>
   <p>
    If
    <code class="literal">
     pval
    </code>
    is anything else,
    <code class="literal">
     p()
    </code>
    first signals a warning and sets the
          message text and error number condition information items.
          This warning does not terminate the procedure, so execution
          continues and
    <code class="literal">
     p()
    </code>
    then signals an error.
          The error does terminate the procedure. The message text and
          error number set by the warning are replaced by the values set
          by the error, which are returned with the error information.
   </p>
   <p>
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    is typically used within
          stored programs, but it is a MySQL extension that it is
          permitted outside handler context. For example, if you invoke
          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>
    client program, you can enter any
          of these statements at the prompt:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45363892"><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">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'77777'</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">TRIGGER</span> t_bi <span class="token keyword">BEFORE</span> <span class="token keyword">INSERT</span> <span class="token keyword">ON</span> t
  <span class="token keyword">FOR</span> <span class="token keyword">EACH</span> <span class="token keyword">ROW</span> <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'77777'</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">EVENT</span> e <span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span> <span class="token keyword">EVERY</span> <span class="token number">1</span> <span class="token keyword">SECOND</span>
  <span class="token keyword">DO</span> <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'77777'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    executes according to
          the following rules:
   </p>
   <p>
    If the
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement
          indicates a particular
    <code class="literal">
     SQLSTATE
    </code>
    value, that
          value is used to signal the condition specified. Example:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69391285"><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">CREATE</span> <span class="token keyword">PROCEDURE</span> p <span class="token punctuation">(</span>divisor <span class="token datatype">INT</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token keyword">IF</span> divisor <span class="token operator">=</span> <span class="token number">0</span> <span class="token keyword">THEN</span>
    <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'22012'</span><span class="token punctuation">;</span>
  <span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    If the
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement uses a
          named condition, the condition must be declared in some scope
          that applies to the
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement, and must be defined using an
    <code class="literal">
     SQLSTATE
    </code>
    value, not a MySQL error number.
          Example:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61550705"><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">CREATE</span> <span class="token keyword">PROCEDURE</span> p <span class="token punctuation">(</span>divisor <span class="token datatype">INT</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token keyword">DECLARE</span> divide_by_zero <span class="token keyword">CONDITION</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'22012'</span><span class="token punctuation">;</span>
  <span class="token keyword">IF</span> divisor <span class="token operator">=</span> <span class="token number">0</span> <span class="token keyword">THEN</span>
    <span class="token keyword">SIGNAL</span> divide_by_zero<span class="token punctuation">;</span>
  <span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    If the named condition does not exist in the scope of the
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement, an
    <code class="literal">
     Undefined CONDITION
    </code>
    error occurs.
   </p>
   <p>
    If
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    refers to a named
          condition that is defined with a MySQL error number rather
          than an
    <code class="literal">
     SQLSTATE
    </code>
    value, a
    <code class="literal">
     SIGNAL/RESIGNAL can only use a CONDITION defined with
          SQLSTATE
    </code>
    error occurs. The following statements
          cause that error because the named condition is associated
          with a MySQL error number:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41350643"><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">DECLARE</span> no_such_table <span class="token keyword">CONDITION</span> <span class="token keyword">FOR</span> <span class="token number">1051</span><span class="token punctuation">;</span>
<span class="token keyword">SIGNAL</span> no_such_table<span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    If a condition with a given name is declared multiple times in
          different scopes, the declaration with the most local scope
          applies. Consider the following procedure:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36879047"><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">CREATE</span> <span class="token keyword">PROCEDURE</span> p <span class="token punctuation">(</span>divisor <span class="token datatype">INT</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token keyword">DECLARE</span> my_error <span class="token keyword">CONDITION</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'45000'</span><span class="token punctuation">;</span>
  <span class="token keyword">IF</span> divisor <span class="token operator">=</span> <span class="token number">0</span> <span class="token keyword">THEN</span>
    <span class="token keyword">BEGIN</span>
      <span class="token keyword">DECLARE</span> my_error <span class="token keyword">CONDITION</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'22012'</span><span class="token punctuation">;</span>
      <span class="token keyword">SIGNAL</span> my_error<span class="token punctuation">;</span>
    <span class="token keyword">END</span><span class="token punctuation">;</span>
  <span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
  <span class="token keyword">SIGNAL</span> my_error<span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    If
    <code class="literal">
     divisor
    </code>
    is 0, the first
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement executes. The
          innermost
    <code class="literal">
     my_error
    </code>
    condition declaration
          applies, raising
    <code class="literal">
     SQLSTATE
    </code>
    <code class="literal">
     '22012'
    </code>
    .
   </p>
   <p>
    If
    <code class="literal">
     divisor
    </code>
    is not 0, the second
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement executes. The
          outermost
    <code class="literal">
     my_error
    </code>
    condition declaration
          applies, raising
    <code class="literal">
     SQLSTATE
    </code>
    <code class="literal">
     '45000'
    </code>
    .
   </p>
   <p>
    For information about how the server chooses handlers when a
          condition occurs, see
    <a class="xref" href="handler-scope.html" title="15.6.7.6 Scope Rules for Handlers">
     Section 15.6.7.6, “Scope Rules for Handlers”
    </a>
    .
   </p>
   <p>
    Signals can be raised within exception handlers:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74884565"><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">CREATE</span> <span class="token keyword">PROCEDURE</span> p <span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
  <span class="token keyword">DECLARE</span> <span class="token keyword">EXIT</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLEXCEPTION</span>
  <span class="token keyword">BEGIN</span>
    <span class="token keyword">SIGNAL</span> <span class="token keyword">SQLSTATE</span> <span class="token keyword">VALUE</span> <span class="token string">'99999'</span>
      <span class="token keyword">SET</span> <span class="token keyword">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'An error occurred'</span><span class="token punctuation">;</span>
  <span class="token keyword">END</span><span class="token punctuation">;</span>
  <span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> no_such_table<span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    <code class="literal">
     CALL p()
    </code>
    reaches the
    <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
     <code class="literal">
      DROP TABLE
     </code>
    </a>
    statement. There is
          no table named
    <code class="literal">
     no_such_table
    </code>
    , so the error
          handler is activated. The error handler destroys the original
          error (
    <span class="quote">
     “
     <span class="quote">
      no such table
     </span>
     ”
    </span>
    ) and makes a new error
          with
    <code class="literal">
     SQLSTATE
    </code>
    <code class="literal">
     '99999'
    </code>
    and message
    <code class="literal">
     An error occurred
    </code>
    .
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="signal-condition-information-items">
       </a>
       Signal Condition Information Items
      </h5>
     </div>
    </div>
   </div>
   <p>
    The following table lists the names of diagnostics area
          condition information items that can be set in a
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    (or
    <a class="link" href="resignal.html" title="15.6.7.4 RESIGNAL Statement">
     <code class="literal">
      RESIGNAL
     </code>
    </a>
    ) statement. All items
          are standard SQL except
    <code class="literal">
     MYSQL_ERRNO
    </code>
    , which
          is a MySQL extension. For more information about these items
          see
    <a class="xref" href="diagnostics-area.html" title="15.6.7.7 The MySQL Diagnostics Area">
     Section 15.6.7.7, “The MySQL Diagnostics Area”
    </a>
    .
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-none"><div class="docs-select-all right" id="sa73481612"><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-none">Item Name             Definition
---------             ----------
CLASS_ORIGIN          VARCHAR(64)
SUBCLASS_ORIGIN       VARCHAR(64)
CONSTRAINT_CATALOG    VARCHAR(64)
CONSTRAINT_SCHEMA     VARCHAR(64)
CONSTRAINT_NAME       VARCHAR(64)
CATALOG_NAME          VARCHAR(64)
SCHEMA_NAME           VARCHAR(64)
TABLE_NAME            VARCHAR(64)
COLUMN_NAME           VARCHAR(64)
CURSOR_NAME           VARCHAR(64)
MESSAGE_TEXT          VARCHAR(128)
MYSQL_ERRNO           SMALLINT UNSIGNED</code></pre>
   </div>
   <p>
    The character set for character items is UTF-8.
   </p>
   <p>
    It is illegal to assign
    <code class="literal">
     NULL
    </code>
    to a condition
          information item in a
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement.
   </p>
   <p>
    A
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement always
          specifies an
    <code class="literal">
     SQLSTATE
    </code>
    value, either
          directly, or indirectly by referring to a named condition
          defined with an
    <code class="literal">
     SQLSTATE
    </code>
    value. The first
          two characters of an
    <code class="literal">
     SQLSTATE
    </code>
    value are its
          class, and the class determines the default value for the
          condition information items:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '00'
       </code>
       (success)
      </p>
      <p>
       Illegal.
       <code class="literal">
        SQLSTATE
       </code>
       values that begin
              with
       <code class="literal">
        '00'
       </code>
       indicate success and are not
              valid for
       <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
        <code class="literal">
         SIGNAL
        </code>
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '01'
       </code>
       (warning)
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14701011"><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">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'Unhandled user-defined warning condition'</span><span class="token punctuation">;</span>
<span class="token keyword">MYSQL_ERRNO</span> <span class="token operator">=</span> ER_SIGNAL_WARN</code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '02'
       </code>
       (not found)
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa93113130"><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">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'Unhandled user-defined not found condition'</span><span class="token punctuation">;</span>
<span class="token keyword">MYSQL_ERRNO</span> <span class="token operator">=</span> ER_SIGNAL_NOT_FOUND</code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Class &gt;
       <code class="literal">
        '02'
       </code>
       (exception)
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24968433"><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">MESSAGE_TEXT</span> <span class="token operator">=</span> <span class="token string">'Unhandled user-defined exception condition'</span><span class="token punctuation">;</span>
<span class="token keyword">MYSQL_ERRNO</span> <span class="token operator">=</span> ER_SIGNAL_EXCEPTION</code></pre>
      </div>
     </li>
    </ul>
   </div>
   <p>
    For legal classes, the other condition information items are
          set as follows:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74721402"><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">CLASS_ORIGIN</span> <span class="token operator">=</span> <span class="token keyword">SUBCLASS_ORIGIN</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
<span class="token keyword">CONSTRAINT_CATALOG</span> <span class="token operator">=</span> <span class="token keyword">CONSTRAINT_SCHEMA</span> <span class="token operator">=</span> <span class="token keyword">CONSTRAINT_NAME</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
<span class="token keyword">CATALOG_NAME</span> <span class="token operator">=</span> <span class="token keyword">SCHEMA_NAME</span> <span class="token operator">=</span> <span class="token keyword">TABLE_NAME</span> <span class="token operator">=</span> <span class="token keyword">COLUMN_NAME</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
<span class="token keyword">CURSOR_NAME</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    The error values that are accessible after
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    executes are the
    <code class="literal">
     SQLSTATE
    </code>
    value raised by the
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    statement and the
    <code class="literal">
     MESSAGE_TEXT
    </code>
    and
    <code class="literal">
     MYSQL_ERRNO
    </code>
    items. These values are
          available from the C API:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-sqlstate.html" target="_top">
        <code class="literal">
         mysql_sqlstate()
        </code>
       </a>
       returns
              the
       <code class="literal">
        SQLSTATE
       </code>
       value.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-errno.html" target="_top">
        <code class="literal">
         mysql_errno()
        </code>
       </a>
       returns the
       <code class="literal">
        MYSQL_ERRNO
       </code>
       value.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-error.html" target="_top">
        <code class="literal">
         mysql_error()
        </code>
       </a>
       returns the
       <code class="literal">
        MESSAGE_TEXT
       </code>
       value.
      </p>
     </li>
    </ul>
   </div>
   <p>
    At the SQL level, the output from
    <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement">
     <code class="literal">
      SHOW
          WARNINGS
     </code>
    </a>
    and
    <a class="link" href="show-errors.html" title="15.7.7.18 SHOW ERRORS Statement">
     <code class="literal">
      SHOW
          ERRORS
     </code>
    </a>
    indicates the
    <code class="literal">
     MYSQL_ERRNO
    </code>
    and
    <code class="literal">
     MESSAGE_TEXT
    </code>
    values in the
    <code class="literal">
     Code
    </code>
    and
    <code class="literal">
     Message
    </code>
    columns.
   </p>
   <p>
    To retrieve information from the diagnostics area, use the
    <a class="link" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
     <code class="literal">
      GET DIAGNOSTICS
     </code>
    </a>
    statement (see
    <a class="xref" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
     Section 15.6.7.3, “GET DIAGNOSTICS Statement”
    </a>
    ). For information about the
          diagnostics area, see
    <a class="xref" href="diagnostics-area.html" title="15.6.7.7 The MySQL Diagnostics Area">
     Section 15.6.7.7, “The MySQL Diagnostics Area”
    </a>
    .
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="signal-effects">
       </a>
       Effect of Signals on Handlers, Cursors, and Statements
      </h5>
     </div>
    </div>
   </div>
   <p>
    Signals have different effects on statement execution
          depending on the signal class. The class determines how severe
          an error is. MySQL ignores the value of the
    <a class="link" href="server-system-variables.html#sysvar_sql_mode">
     <code class="literal">
      sql_mode
     </code>
    </a>
    system variable; in
          particular, strict SQL mode does not matter. MySQL also
          ignores
    <code class="literal">
     IGNORE
    </code>
    : The intent of
    <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
     <code class="literal">
      SIGNAL
     </code>
    </a>
    is to raise a
          user-generated error explicitly, so a signal is never ignored.
   </p>
   <p>
    In the following descriptions,
    <span class="quote">
     “
     <span class="quote">
      unhandled
     </span>
     ”
    </span>
    means
          that no handler for the signaled
    <code class="literal">
     SQLSTATE
    </code>
    value has been defined with
    <a class="link" href="declare-handler.html" title="15.6.7.2 DECLARE ... HANDLER Statement">
     <code class="literal">
      DECLARE ...
          HANDLER
     </code>
    </a>
    .
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '00'
       </code>
       (success)
      </p>
      <p>
       Illegal.
       <code class="literal">
        SQLSTATE
       </code>
       values that begin
              with
       <code class="literal">
        '00'
       </code>
       indicate success and are not
              valid for
       <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
        <code class="literal">
         SIGNAL
        </code>
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '01'
       </code>
       (warning)
      </p>
      <p>
       The value of the
       <a class="link" href="server-system-variables.html#sysvar_warning_count">
        <code class="literal">
         warning_count
        </code>
       </a>
       system
              variable goes up.
       <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement">
        <code class="literal">
         SHOW
              WARNINGS
        </code>
       </a>
       shows the signal.
       <code class="literal">
        SQLWARNING
       </code>
       handlers catch the signal.
      </p>
      <p>
       Warnings cannot be returned from stored functions because
              the
       <a class="link" href="return.html" title="15.6.5.7 RETURN Statement">
        <code class="literal">
         RETURN
        </code>
       </a>
       statement that
              causes the function to return clears the diagnostic area.
              The statement thus clears any warnings that may have been
              present there (and resets
       <a class="link" href="server-system-variables.html#sysvar_warning_count">
        <code class="literal">
         warning_count
        </code>
       </a>
       to 0).
      </p>
     </li>
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '02'
       </code>
       (not found)
      </p>
      <p>
       <code class="literal">
        NOT FOUND
       </code>
       handlers catch the signal.
              There is no effect on cursors. If the signal is unhandled
              in a stored function, statements end.
      </p>
     </li>
     <li class="listitem">
      <p>
       Class &gt;
       <code class="literal">
        '02'
       </code>
       (exception)
      </p>
      <p>
       <code class="literal">
        SQLEXCEPTION
       </code>
       handlers catch the signal.
              If the signal is unhandled in a stored function,
              statements end.
      </p>
     </li>
     <li class="listitem">
      <p>
       Class =
       <code class="literal">
        '40'
       </code>
      </p>
      <p>
       Treated as an ordinary exception.
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
