<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="declare-local-variable">
      </a>
      15.6.4.1 Local Variable DECLARE Statement
     </h4>
    </div>
   </div>
  </div>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa94203297"><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> <em class="replaceable">var_name</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">var_name</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword"><em class="replaceable">type</em></span> <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span> <span class="token keyword"><em class="replaceable">value</em></span><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   This statement declares local variables within stored programs.
        To provide a default value for a variable, include a
   <code class="literal">
    DEFAULT
   </code>
   clause. The value can be specified as
        an expression; it need not be a constant. If the
   <code class="literal">
    DEFAULT
   </code>
   clause is missing, the initial value
        is
   <code class="literal">
    NULL
   </code>
   .
  </p>
  <p>
   Local variables are treated like stored routine parameters with
        respect to data type and overflow checking. See
   <a class="xref" href="create-procedure.html" title="15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements">
    Section 15.1.17, “CREATE PROCEDURE and CREATE FUNCTION Statements”
   </a>
   .
  </p>
  <p>
   Variable declarations must appear before cursor or handler
        declarations.
  </p>
  <p>
   Local variable names are not case-sensitive. Permissible
        characters and quoting rules are the same as for other
        identifiers, as described in
   <a class="xref" href="identifiers.html" title="11.2 Schema Object Names">
    Section 11.2, “Schema Object Names”
   </a>
   .
  </p>
  <p>
   The scope of a local variable is the
   <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
    <code class="literal">
     BEGIN ...
        END
    </code>
   </a>
   block within which it is declared. The variable
        can be referred to in blocks nested within the declaring block,
        except those blocks that declare a variable with the same name.
  </p>
  <p>
   For examples of variable declarations, see
   <a class="xref" href="local-variable-scope.html" title="15.6.4.2 Local Variable Scope and Resolution">
    Section 15.6.4.2, “Local Variable Scope and Resolution”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
