125 lines
7.9 KiB
HTML
125 lines
7.9 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="dc.language" scheme="rfc1766" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow"/>
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="keywords" content="SQL control statements, SQL statements" />
|
|
<title>SQL control statements</title>
|
|
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
|
|
<link rel="stylesheet" type="text/css" href="ic.css" />
|
|
</head>
|
|
<body>
|
|
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
|
|
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
|
|
|
|
|
|
<a name="sqlcontstmts"></a>
|
|
<h1 id="sqlcontstmts"><a href="rbafzmst02.htm#ToC_1405">SQL control statements</a></h1><a id="idx3320" name="idx3320"></a><a id="idx3321" name="idx3321"></a>
|
|
<p>Control statements are SQL statements that allow SQL to be used in a manner
|
|
similar to writing a program in a structured programming language. SQL control
|
|
statements provide the capability to control the logic flow, declare and set
|
|
variables, and handle warnings and exceptions. Some SQL control statements
|
|
include other nested SQL statements.</p>
|
|
<a href="rbafzmstsqlcontstmts.htm#syncontrol"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn404.htm"
|
|
border="0" /></span><a href="#skipsyn-403"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>SQL-control-statement:
|
|
|
|
|--+-<span class="italic">assignment-statement</span>------+--------------------------------|
|
|
+-<span class="italic">CALL-statement</span>------------+
|
|
+-<span class="italic">CASE-statement</span>------------+
|
|
+-<span class="italic">compound-statement</span>--------+
|
|
+-<span class="italic">FOR-statement</span>-------------+
|
|
+-<span class="italic">GET DIAGNOSTICS-statement</span>-+
|
|
+-<span class="italic">GOTO-statement</span>------------+
|
|
+-<span class="italic">IF-statement</span>--------------+
|
|
+-<span class="italic">ITERATE-statement</span>---------+
|
|
+-<span class="italic">LEAVE-statement</span>-----------+
|
|
+-<span class="italic">LOOP-statement</span>------------+
|
|
+-<span class="italic">REPEAT-statement</span>----------+
|
|
+-<span class="italic">RESIGNAL-statement</span>--------+
|
|
+-<span class="italic">RETURN-statement</span>----------+
|
|
+-<span class="italic">SIGNAL-statement</span>----------+
|
|
'-<span class="italic">WHILE-statement</span>-----------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-403" id="skipsyn-403"></a>
|
|
<a name="syncontrol"></a>
|
|
<p id="syncontrol">Control statements are supported in SQL procedures, SQL
|
|
functions, and SQL triggers.</p>
|
|
<p>SQL procedures are created by specifying LANGUAGE SQL and an SQL routine
|
|
body on the CREATE PROCEDURE statement. SQL functions are created by specifying
|
|
LANGUAGE SQL and an SQL routine body on the CREATE FUNCTION statement. SQL
|
|
routines are SQL procedures or SQL functions. SQL triggers are created by
|
|
specifying an SQL routine body on the CREATE TRIGGER statement.</p>
|
|
<p>An SQL routine body must be a single SQL statement which may be an SQL
|
|
control statement.</p>
|
|
<p>The SQL routine body is the executable part of the procedure, function,
|
|
or trigger that is transformed by the database manager into a program or service program.
|
|
When an SQL routine or trigger is created, SQL creates a temporary source
|
|
file (QTEMP/QSQLSRC and QTEMP/QSQLT00000) that will contain C source code
|
|
with embedded SQL statements. If either of these source files exist, they
|
|
will be modified if needed to have the same CCSID as the source. If DBGVIEW(*SOURCE)
|
|
is specified, SQL creates the root source for the routine or trigger in source
|
|
file QSQDSRC in the same library as the procedure, function or trigger.</p>
|
|
<p>An SQL procedure or SQL trigger is created as a program (*PGM) object using
|
|
the CRTPGM command. An SQL function is created as a service program (*SRVPGM)
|
|
object using the CRTSRVPGM command. The program or service program is created
|
|
in the library that is the implicit or explicit qualifier of the procedure,
|
|
function, or trigger name.</p>
|
|
<p>When the program or service program is created, the SQL statements other
|
|
than certain control statements become embedded SQL statements in the program
|
|
or service program. The CALL, SIGNAL, RESIGNAL, and GET DIAGNOSTIC control
|
|
statements also become embedded SQL statements in the program or service program.</p>
|
|
<p>The specified procedure or function is registered in the SYSROUTINES and
|
|
SYSPARMS catalog tables, and an internal link is created from SYSROUTINES
|
|
to the program. When the procedure is called using the SQL CALL statement
|
|
or when the function is invoked in an SQL statement, the program associated
|
|
with the routine is called. The specified SQL trigger is registered in the
|
|
SYSTRIGGER catalog table.</p>
|
|
<p>The remainder of this chapter contains a description of the control statements
|
|
including syntax diagrams, semantic descriptions, usage notes, and examples
|
|
of the use of the statements that constitute the SQL routine body. There is
|
|
also a section on referencing SQL parameters and variables found in <a href="rbafzmstrefsqlv.htm#refsqlv">References to SQL parameters and SQL variables</a>. There are two common elements that are used in describing
|
|
specific SQL control statements. These are:</p>
|
|
<ul>
|
|
<li>SQL control statements as described above</li>
|
|
<li><a href="rbafzmstsqlprocstmt.htm#sqlprocstmt">SQL-procedure-statement</a></li></ul>
|
|
<p>For syntax and additional information on the SQL control statements see
|
|
the following topics:</p>
|
|
<ul>
|
|
<li><a href="rbafzmstassignstmt.htm#assignstmt">assignment-statement</a></li>
|
|
<li><a href="rbafzmstcallstmt.htm#callstmt">CALL statement</a></li>
|
|
<li><a href="rbafzmstcasestmt.htm#casestmt">CASE statement</a></li>
|
|
<li><a href="rbafzmstcompoundstmt.htm#compoundstmt">compound-statement</a></li>
|
|
<li><a href="rbafzmstifstmt.htm#ifstmt">IF statement</a></li>
|
|
<li><a href="rbafzmstforstmt.htm#forstmt">FOR statement</a></li>
|
|
<li><a href="rbafzmstgetdiag2.htm#getdiag2">GET DIAGNOSTICS statement</a></li>
|
|
<li><a href="rbafzmstgotostmt.htm#gotostmt">GOTO statement</a></li>
|
|
<li><a href="rbafzmstiteratestmt.htm#iteratestmt">ITERATE statement</a></li>
|
|
<li><a href="rbafzmstleavestmt.htm#leavestmt">LEAVE statement</a></li>
|
|
<li><a href="rbafzmstloopstmt.htm#loopstmt">LOOP statement</a></li>
|
|
<li><a href="rbafzmstrepeatstmt.htm#repeatstmt">REPEAT statement</a></li>
|
|
<li><a href="rbafzmstresignalstmt.htm#resignalstmt">RESIGNAL statement</a></li>
|
|
<li><a href="rbafzmstreturnstmt.htm#returnstmt">RETURN statement</a></li>
|
|
<li><a href="rbafzmstsignalstmt.htm#signalstmt">SIGNAL statement</a></li>
|
|
<li><a href="rbafzmstwhilestmt.htm#whilestmt">WHILE statement</a></li></ul>
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstwvrr.htm">Previous Page</a> | <a href="rbafzmstrefsqlv.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
|
|
<a href="rbafzmstindex.htm#index">Index</a> ]
|
|
|
|
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
|
|
</body>
|
|
</html>
|