ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzajp_5.4.0.1/rzajpindvar.htm

107 lines
6.1 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 lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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="DC.Type" content="reference" />
<meta name="DC.Title" content="Indicator variables in applications that use SQL" />
<meta name="abstract" content="An indicator variable is a halfword integer variable used to indicate whether its associated host variable has been assigned a null value." />
<meta name="description" content="An indicator variable is a halfword integer variable used to indicate whether its associated host variable has been assigned a null value." />
<meta name="DC.subject" content="indicator variable, definition, definitions, variable, indicator" />
<meta name="keywords" content="indicator variable, definition, definitions, variable, indicator" />
<meta name="DC.Relation" scheme="URI" content="rzajphostvar.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajphostindvar.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpnullvar.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstch2pred.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzajpindvar" />
<meta name="DC.Language" 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. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Indicator variables in applications that use SQL</title>
</head>
<body id="rzajpindvar"><a name="rzajpindvar"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Indicator variables in applications that use SQL</h1>
<div><p>An <em>indicator variable</em> is a halfword integer variable used
to indicate whether its associated host variable has been assigned a null
value.</p>
<div class="section"><ul><li>If the value for the result column is null, SQL puts a -1 in the indicator
variable.</li>
<li>If you do not use an indicator variable and the result column is a null
value, a negative SQLCODE is returned.</li>
<li>If the value for the result column causes a data mapping error. SQL sets
the indicator variable to -2.</li>
</ul>
</div>
<div class="section"><p>You can also use an indicator variable to verify that a retrieved
string value has not been truncated. If truncation occurs, the indicator variable
contains a positive integer that specifies the original length of the string.
If the string represents a large object (LOB), and the original length of
the string is greater than 32767, the value that is stored in the indicator
variable is 32767, since no larger value can be stored in a halfword integer.</p>
<p>When
the database manager returns a value from a result column, you can test the
indicator variable. If the value of the indicator variable is less than zero,
you know the value of the results column is null. When the database manager
returns a null value, the host variable will be set to the default value for
the result column.</p>
</div>
<div class="section"><div class="p">You specify an indicator variable (preceded by a colon) immediately
after the host variable or immediately after the keyword INDICATOR. For example: <pre>EXEC SQL
<strong>SELECT COUNT</strong>(*), <strong>AVG</strong>(SALARY)
<strong>INTO</strong> :PLICNT, :PLISAL:INDNULL
<strong>FROM</strong> CORPDATA.EMPLOYEE
<strong>WHERE</strong> EDLEVEL &lt; 18
END-EXEC.</pre>
</div>
</div>
<div class="section"><p>You can then test INDNULL to see if it contains a negative value.
If it does, you know SQL returned a null value.</p>
</div>
<div class="section"><p>Always test for NULL in a column by using the <strong><var class="varname">IS NULL</var></strong> predicate.
For example:</p>
<pre><strong>WHERE</strong> expression <strong>IS NULL</strong>
</pre>
</div>
<div class="section"><p>Do not test for NULL in this way:</p>
<pre><strong>MOVE</strong> -1 <strong>TO HUIND.</strong>
EXEC SQL...<strong>WHERE</strong> column-name = :HUI :HUIND
</pre>
</div>
<div class="section"><p>The EQUAL predicate will always be evaluated as false when it
compares a null value. The result of this example will select
no rows.</p>
</div>
<div class="section"><p>The DISTINCT predicate can be used to perform comparisons when
null values may exist.</p>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rzajphostindvar.htm">Indicator variables used with host structures</a></strong><br />
You can also specify an <em>indicator structure</em> (defined
as an array of halfword integer variables) to support a host structure.</li>
<li class="ulchildlink"><strong><a href="rzajpnullvar.htm">Indicator variables used to set null values</a></strong><br />
You can use an indicator variable to set a null value in a column.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajphostvar.htm" title="When your program retrieves data, the values are put into data items defined by your program and specified with the INTO clause of a SELECT INTO or FETCH statement. The data items are called host variables.">Use host variables in SQL statements</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../db2/rbafzmstch2pred.htm">Predicates</a></div>
</div>
</div>
</body>
</html>