109 lines
6.5 KiB
HTML
109 lines
6.5 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="Expressions in the WHERE clause" />
|
|
<meta name="abstract" content="An expression in a WHERE clause names or specifies something you want to compare to something else." />
|
|
<meta name="description" content="An expression in a WHERE clause names or specifies something you want to compare to something else." />
|
|
<meta name="DC.subject" content="SELECT statement, WHERE clause, expressions, predicates, clause, WHERE, expression, column name, WHERE clause, SELECT statement, constant, host variable, host variable, special register, special register, NULL value, NULL value, subquery" />
|
|
<meta name="keywords" content="SELECT statement, WHERE clause, expressions, predicates, clause, WHERE, expression, column name, WHERE clause, SELECT statement, constant, host variable, host variable, special register, special register, NULL value, NULL value, subquery" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafywhere.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafysubquery.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafycomsrch.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstch2expr.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="rbafywhereexp" />
|
|
<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>Expressions in the WHERE clause</title>
|
|
</head>
|
|
<body id="rbafywhereexp"><a name="rbafywhereexp"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Expressions in the WHERE clause</h1>
|
|
<div><p>An expression in a WHERE clause names or specifies something you
|
|
want to compare to something else.</p>
|
|
<div class="section"><p>The expressions you specify can be:</p>
|
|
<ul><li>A <strong>column name</strong> names a column. For example: <pre>… <strong>WHERE</strong> EMPNO = '000200'</pre>
|
|
<p><em>EMPNO</em> names
|
|
a column that is defined as a 6-byte character value.</p>
|
|
</li>
|
|
<li>An <strong>expression</strong> identifies two values that are added (+), subtracted
|
|
(-), multiplied (*), divided (/), have exponentiation (**), or concatenated
|
|
(CONCAT or ||) to result in a value. The most common operands of an expression
|
|
are: <ul><li>A constant</li>
|
|
<li>A column</li>
|
|
<li>A host variable</li>
|
|
<li>A function</li>
|
|
<li>A special register</li>
|
|
<li>A scalar fullselect</li>
|
|
<li>Another expression</li>
|
|
</ul>
|
|
<p>For example: </p>
|
|
<pre>… <strong>WHERE INTEGER</strong>(PRENDATE - PRSTDATE) > 100</pre>
|
|
<p>When
|
|
the order of evaluation is not specified by parentheses, the expression is
|
|
evaluated in the following order: </p>
|
|
<ol><li>Prefix operators</li>
|
|
<li>Exponentiation</li>
|
|
<li>Multiplication, division, and concatenation</li>
|
|
<li>Addition and subtraction</li>
|
|
</ol>
|
|
<p>Operators on the same precedence level are applied from left to right.</p>
|
|
</li>
|
|
<li>A <strong>constant</strong> specifies a literal value for the expression. For example:
|
|
<pre>… <strong>WHERE</strong> 40000 < SALARY</pre>
|
|
<p><em>SALARY</em> names
|
|
a column that is defined as an 9-digit packed decimal value (DECIMAL(9,2)).
|
|
It is compared to the numeric constant 40000.</p>
|
|
</li>
|
|
<li>A <strong>host variable</strong> identifies a variable in an application program.
|
|
For example: <pre>… <strong>WHERE</strong> EMPNO = :EMP</pre>
|
|
</li>
|
|
<li>A <strong>special register</strong> identifies a special value defined by the database
|
|
manager. For example: <pre>… <strong>WHERE</strong> LASTNAME = <strong>USER</strong></pre>
|
|
</li>
|
|
<li>The <strong>NULL</strong> value specifies the condition of having an unknown value.
|
|
<pre>… <strong>WHERE</strong> DUE_DATE <strong>IS NULL</strong></pre>
|
|
</li>
|
|
<li>A scalar fullselect.</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><p>A search condition can specify many predicates separated by AND
|
|
and OR. No matter how complex the search condition, it supplies
|
|
a TRUE or FALSE value when evaluated against a row. There is also an <em>unknown</em> truth
|
|
value, which is effectively false. That is, if the value of a row is null,
|
|
this null value is not returned as a result of a search because it is not
|
|
less than, equal to, or greater than the value specified in the search condition. </p>
|
|
</div>
|
|
<div class="section"><p>To fully understand the WHERE clause, you need to know the order
|
|
SQL evaluates search conditions and predicates, and compares the values of
|
|
expressions. This topic is discussed in the <a href="../db2/rbafzmst02.htm">SQL Reference</a> topic collection.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafywhere.htm" title="The WHERE clause specifies a search condition that identifies the row or rows you want to retrieve, update, or delete.">Specify a search condition using the WHERE clause</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="rbafysubquery.htm" title="You can use subqueries in a search condition as another way to select your data. Subqueries can be used anywhere an expression can be used.">Use subqueries</a></div>
|
|
</div>
|
|
<div class="relref"><strong>Related reference</strong><br />
|
|
<div><a href="rbafycomsrch.htm" title="In addition to the basic comparison predicates (=, >, <, and so on), a search condition can contain any of the predicates BETWEEN, IN, EXISTS, IS NULL, and LIKE.">Define complex search conditions</a></div>
|
|
<div><a href="../db2/rbafzmstch2expr.htm">Expressions</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |