514 lines
31 KiB
HTML
514 lines
31 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="without operators, expression,
|
||
|
with arithmetic operators, arithmetic, operators, arithmetic operators,
|
||
|
prefix operator, plus, unary, minus, infix operators, multiplication operator,
|
||
|
subtraction operator, division operator, exponentiation operator, * (multiply),
|
||
|
** (exponentiation), / (divide), - (subtraction), + (addition), integer operands,
|
||
|
integer, operand, decimal operands, numeric operands, decimal, numeric,
|
||
|
in results of arithmetic operations, scale of data, decimal data,
|
||
|
floating-point operands, floating point, distinct type operands, distinct type,
|
||
|
with concatenation operator, concatenation operator (CONCAT),
|
||
|
CONCAT (concatenation operator), || (concatenation operator), definition,
|
||
|
scalar-fullselect, scalar fullselect, scalar subselect, date and time operands,
|
||
|
date and time, labeled, duration, labeled duration, date, time, timestamp" />
|
||
|
<title>Expressions</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="ch2expr"></a>
|
||
|
<h2 id="ch2expr"><a href="rbafzmst02.htm#ToC_250">Expressions</a></h2>
|
||
|
<p>An expression specifies a value.</p>
|
||
|
<a href="rbafzmstch2expr.htm#synexpressions"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
||
|
<a name="wq335"></a>
|
||
|
<div class="fignone" id="wq335">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn20.htm"
|
||
|
border="0" /></span><a href="#skipsyn-19"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a> .-operator-------------------------.
|
||
|
V |
|
||
|
>>---+-----+--+-<span class="italic">function</span>------------+-+------------------------><
|
||
|
+- + -+ +-<span class="italic">(expression)</span>--------+
|
||
|
'- - -' +-<span class="italic">constant</span>------------+
|
||
|
+-<span class="italic">column-name</span>---------+
|
||
|
+-<span><span class="italic">variable</span></span>------------+
|
||
|
+-<span class="italic">special-register</span>----+
|
||
|
+-<span><span class="italic">(scalar-fullselect)</span></span>-+
|
||
|
+-<span class="italic">labeled-duration</span>----+
|
||
|
+-<span class="italic">case-expression</span>-----+
|
||
|
+-<span class="italic">cast-specification</span>--+
|
||
|
+-<span><span class="italic">OLAP-specification</span></span>--+
|
||
|
'-<span class="italic">sequence-reference</span>--'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-19" id="skipsyn-19"></a>
|
||
|
<p><span class="bold">operator:</span></p>
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn21.htm"
|
||
|
border="0" /></span><a href="#skipsyn-20"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>>>-+-CONCAT-+--------------------------------------------------><
|
||
|
+- || ----+
|
||
|
+- / ----+
|
||
|
+- * ----+
|
||
|
+- ** ---+
|
||
|
+- + ----+
|
||
|
'- - ----'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-20" id="skipsyn-20"></a>
|
||
|
<a name="labdur"></a>
|
||
|
<p id="labdur"><span class="bold">labeled-duration:</span></p>
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn22.htm"
|
||
|
border="0" /></span><a href="#skipsyn-21"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>>>-+-<span class="italic">function</span>-----+--+-YEAR---------+--------------------------><
|
||
|
+-<span class="italic">(expression)</span>-+ +-YEARS--------+
|
||
|
+-<span class="italic">constant</span>-----+ +-MONTH--------+
|
||
|
+-<span class="italic">column-name</span>--+ +-MONTHS-------+
|
||
|
'-<span><span class="italic">variable</span></span>-----' +-DAY----------+
|
||
|
+-DAYS---------+
|
||
|
+-HOUR---------+
|
||
|
+-HOURS--------+
|
||
|
+-MINUTE-------+
|
||
|
+-MINUTES------+
|
||
|
+-SECOND-------+
|
||
|
+-SECONDS------+
|
||
|
+-MICROSECOND--+
|
||
|
'-MICROSECONDS-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-21" id="skipsyn-21"></a></div>
|
||
|
<a name="synexpressions"></a>
|
||
|
<h3 id="synexpressions"><a href="rbafzmst02.htm#ToC_251">Without operators</a></h3>
|
||
|
<p><a id="idx655" name="idx655"></a></p>
|
||
|
<p>If no operators are used, the result of the expression is the specified
|
||
|
value.</p>
|
||
|
<a name="wq336"></a>
|
||
|
<h4 id="wq336">Example</h4>
|
||
|
<pre class="xmp"> SALARY :SALARY 'SALARY' <span class="bold">MAX(</span>SALARY<span class="bold">)</span></pre>
|
||
|
<a name="wq337"></a>
|
||
|
<h3 id="wq337"><a href="rbafzmst02.htm#ToC_253">With arithmetic operators</a></h3><a id="idx656" name="idx656"></a><a id="idx657" name="idx657"></a><a id="idx658" name="idx658"></a><a id="idx659" name="idx659"></a><a id="idx660" name="idx660"></a><a id="idx661" name="idx661"></a><a id="idx662" name="idx662"></a><a id="idx663" name="idx663"></a><a id="idx664" name="idx664"></a><a id="idx665" name="idx665"></a><a id="idx666" name="idx666"></a><a id="idx667" name="idx667"></a><a id="idx668" name="idx668"></a><a id="idx669" name="idx669"></a><a id="idx670" name="idx670"></a><a id="idx671" name="idx671"></a><a id="idx672" name="idx672"></a>
|
||
|
<p>If arithmetic operators are used, the result of the expression is a number
|
||
|
derived from the application of the operators to the values of the operands.</p>
|
||
|
<p>If any operand can be null, the result can be null. If any operand
|
||
|
has the null value, the result of the expression is the null value.</p>
|
||
|
<p>If one operand of an arithmetic operator is numeric, the other operand
|
||
|
can be a string. The string is first converted to the data type of the numeric
|
||
|
operand and must contain a valid string representation of a number.</p>
|
||
|
<p>The prefix operator + (<span class="italic">unary plus</span>) does not change
|
||
|
its operand. The prefix operator - (<span class="italic">unary minus</span>) reverses
|
||
|
the sign of a nonzero operand. If the data type of A is small integer, the
|
||
|
data type of - A is large integer. The first character of the token following
|
||
|
a prefix operator must not be a plus or minus sign.</p>
|
||
|
<p>The <span class="italic">infix operators</span>, +, -, *, /, and **, specify
|
||
|
addition, subtraction, multiplication, division, and exponentiation, respectively.
|
||
|
The value of the second operand of division must not be zero.</p>
|
||
|
<p>In COBOL, blanks must precede and follow a minus sign to avoid any ambiguity
|
||
|
with COBOL host variable names (which allow use of a dash).</p>
|
||
|
<p>The result of an exponentiation (**) operator is a double-precision floating-point
|
||
|
number. The result of the other operators depends on the type of the operand.</p>
|
||
|
<p>Operands with a NUMERIC data type are converted to DECIMAL operands
|
||
|
prior to performing the arithmetic operation.</p>
|
||
|
<a name="wq338"></a>
|
||
|
<h4 id="wq338">Two integer operands</h4><a id="idx673" name="idx673"></a><a id="idx674" name="idx674"></a>
|
||
|
<p>If both operands of an arithmetic operator are integers with zero scale,
|
||
|
the operation is performed in binary, and the result is a large integer unless
|
||
|
either (or both) operand is a big integer, in which case the result is a big
|
||
|
integer. Any remainder of division is lost. The result of an integer arithmetic
|
||
|
operation (including unary minus) must be within the range of large integers.
|
||
|
If either integer operand has nonzero scale, it is converted to a decimal
|
||
|
operand with the same precision and scale.</p>
|
||
|
<a name="wq339"></a>
|
||
|
<h4 id="wq339">Integer and decimal operands</h4><a id="idx675" name="idx675"></a><a id="idx676" name="idx676"></a><a id="idx677" name="idx677"></a><a id="idx678" name="idx678"></a><a id="idx679" name="idx679"></a><a id="idx680" name="idx680"></a>
|
||
|
<p>If one operand is an integer with zero scale and the other is decimal,
|
||
|
the operation is performed in decimal using a temporary copy of the integer
|
||
|
that has been converted to a decimal number with precision and scale 0 as
|
||
|
defined in the following table:</p>
|
||
|
<a name="wq340"></a>
|
||
|
<table id="wq340" width="100%" summary="" border="1" frame="border" rules="all">
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq341" width="50%" align="left" valign="bottom"><span class="bold">Operand</span></th>
|
||
|
<th id="wq342" width="50%" align="left" valign="bottom"><span class="bold">Precision of Decimal
|
||
|
Copy</span></th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq341">Column or variable: big integer</td>
|
||
|
<td align="left" valign="top" headers="wq342">19</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq341">Column or variable: large integer</td>
|
||
|
<td align="left" valign="top" headers="wq342">11</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq341">Column or variable: small integer</td>
|
||
|
<td align="left" valign="top" headers="wq342">5</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq341">Constant (including leading zeros)</td>
|
||
|
<td align="left" valign="top" headers="wq342">Same as the number of digits in the constant</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<p>If one operand is an integer with nonzero scale, it is first converted
|
||
|
to a decimal operand with the same precision and scale.</p>
|
||
|
<a name="wq343"></a>
|
||
|
<h4 id="wq343">Two decimal operands</h4><a id="idx681" name="idx681"></a><a id="idx682" name="idx682"></a><a id="idx683" name="idx683"></a><a id="idx684" name="idx684"></a><a id="idx685" name="idx685"></a>
|
||
|
<p>If both operands are decimal, the operation is performed in decimal. The
|
||
|
result of any decimal arithmetic operation is a decimal number with a precision
|
||
|
and scale that are dependent on the operation and the precision and scale
|
||
|
of the operands. If the operation is addition or subtraction and the operands
|
||
|
do not have the same scale, the operation is performed with a temporary copy
|
||
|
of one of the operands. The copy of the shorter operand is extended with trailing
|
||
|
zeros so that its fractional part has the same number of digits as the longer
|
||
|
operand.</p>
|
||
|
<p>Unless specified otherwise, all functions and operations that accept decimal
|
||
|
numbers allow a precision of up to 63 digits. The result of a decimal operation
|
||
|
must not have a precision greater than 63.</p>
|
||
|
<a name="decarithmetic"></a>
|
||
|
<h4 id="decarithmetic">Decimal arithmetic in SQL</h4><a id="idx686" name="idx686"></a>
|
||
|
<p>The following formulas define the precision and scale of the result of
|
||
|
decimal operations in SQL. The symbols <span class="italic">p</span> and <span class="italic">s</span> denote the precision
|
||
|
and scale of the first operand and the symbols <span class="italic">p</span>'
|
||
|
and <span class="italic">s</span>' denote the precision and scale of the second
|
||
|
operand.</p>
|
||
|
<p>The symbol <span class="italic">mp</span> denotes the maximum precision. The
|
||
|
value of <span class="italic">mp</span> is 63 if:</p>
|
||
|
<ul>
|
||
|
<li>either w or y is greater than 31, or</li>
|
||
|
<li>a value of 63 was explicitly specified for the maximum precision.</li></ul><p class="indatacontent">Otherwise, the value of <span class="italic">mp</span> is 31.</p>
|
||
|
<p>The symbol <span class="italic">ms</span> denotes the maximum scale.
|
||
|
The default value of <span class="italic">ms</span> is 31. <span class="italic">ms</span> can be explicitly set to any number from 0 to the maximum precision.</p>
|
||
|
<p>The symbol <span class="italic">mds</span> denotes the minimum divide
|
||
|
scale. The default value of <span class="italic">mds</span> is 0. <span class="italic">mds</span> can be explicitly set to any number from 0 to the maximum scale.</p>
|
||
|
<p>The maximum precision, maximum scale, and minimum divide scale
|
||
|
can be explicitly specified on the DECRESULT parameter of the CRTSQLxxx command,
|
||
|
RUNSQLSTM command, or SET OPTION statement. They can also be specified in
|
||
|
ODBC data sources, JDBC properties, OLE DB properties, .NET properties.</p>
|
||
|
<a name="wq344"></a>
|
||
|
<h5 id="wq344">Addition and subtraction</h5>
|
||
|
<p>The scale of the result of addition and subtraction is max (<var class="pv">s,s'</var>).
|
||
|
The precision is min(<span class="italic">mp</span>,max(<var class="pv">p-s,p'-s'</var>) +max(<var class="pv">s,s'</var>)+1).</p>
|
||
|
<a name="wq345"></a>
|
||
|
<h5 id="wq345">Multiplication</h5>
|
||
|
<p>The precision of the result of multiplication is min (<span class="italic">mp</span>,<var class="pv">p</var>+<var class="pv">p'</var>) and the scale is min(<span class="italic">ms</span>,<var class="pv">s</var>+<var class="pv">s'</var>).</p>
|
||
|
<a name="wq346"></a>
|
||
|
<h5 id="wq346">Division</h5>
|
||
|
<p>The precision of the result of division is (<var class="pv">p</var>-<var class="pv">s</var>+<var class="pv">s'</var>) + max(<var class="pv">mds</var>, min(<var class="pv">ms</var>, <var class="pv">mp</var> - (<var class="pv">p</var>-<var class="pv">s</var>+<var class="pv">s'</var>) ) ). The scale is max(<span class="italic">mds</span>, min(<var class="pv">ms</var>, <var class="pv">mp</var> - (<var class="pv">p</var>-<var class="pv">s</var>+<var class="pv">s'</var>) ) ). The scale
|
||
|
must not be negative.</p>
|
||
|
<a name="wq347"></a>
|
||
|
<h4 id="wq347">Floating-point operands</h4><a id="idx687" name="idx687"></a><a id="idx688" name="idx688"></a>
|
||
|
<p>If either operand of an arithmetic operator is floating point, the operation
|
||
|
is performed in floating point. The operands are first converted to double-precision
|
||
|
floating-point numbers, if necessary. Thus, if any element of an expression
|
||
|
is a floating-point number, the result of the expression is a double-precision
|
||
|
floating-point number.</p>
|
||
|
<p>An operation involving a floating-point number and an integer is performed
|
||
|
with a temporary copy of the integer converted to double-precision floating
|
||
|
point. An operation involving a floating-point number and a decimal number
|
||
|
is performed with a temporary copy of the decimal number that has been converted
|
||
|
to double-precision floating point. The result of a floating-point operation
|
||
|
must be within the range of floating-point numbers.</p>
|
||
|
<p>The order in which floating-point operands (or arguments to functions)
|
||
|
are processed can slightly affect results because floating-point operands
|
||
|
are approximate representations of real numbers. Since the order in which
|
||
|
operands are processed may be implicitly modified by the optimizer (for example,
|
||
|
the optimizer may decide what degree of parallelism to use and what access
|
||
|
plan to use), an application should not depend on the results being precisely
|
||
|
the same each time an SQL statement is executed that uses floating-point operands.</p>
|
||
|
<a name="wq348"></a>
|
||
|
<h4 id="wq348">Distinct types as operands</h4><a id="idx689" name="idx689"></a><a id="idx690" name="idx690"></a>
|
||
|
<p>A distinct type cannot be used with arithmetic operators even if its source data
|
||
|
type is numeric. To perform an arithmetic operation, create a function with
|
||
|
the arithmetic operator as its source. For example, if there were distinct
|
||
|
types INCOME and EXPENSES, both of which had DECIMAL(8,2) data types, then
|
||
|
the following user-defined function, REVENUE, could be used to subtract one
|
||
|
from the other.</p>
|
||
|
<pre class="xmp"> <span class="bold">CREATE FUNCTION </span>REVENUE <span class="bold">(</span> INCOME, EXPENSES <span class="bold">)</span>
|
||
|
<span class="bold">RETURNS DECIMAL(</span>8,2<span class="bold">) SOURCE</span> "-" <span class="bold">( DECIMAL, DECIMAL)</span></pre>
|
||
|
<p>Alternately, the - (minus) operator could be overloaded using a user-defined
|
||
|
function to subtract the new data types. </p>
|
||
|
<pre class="xmp"> <span class="bold">CREATE FUNCTION</span> "-" <span class="bold">(</span> INCOME, EXPENSES <span class="bold">)</span>
|
||
|
<span class="bold">RETURNS DECIMAL(</span>8,2<span class="bold">) SOURCE</span> "-" <span class="bold">( DECIMAL, DECIMAL)</span></pre>
|
||
|
<a name="wtco"></a>
|
||
|
<h3 id="wtco"><a href="rbafzmst02.htm#ToC_263">With the concatenation operator</a></h3><a id="idx691" name="idx691"></a><a id="idx692" name="idx692"></a><a id="idx693" name="idx693"></a><a id="idx694" name="idx694"></a>
|
||
|
<p>If the concatenation operator (CONCAT or ||) is used, the result of the
|
||
|
expression is a string. </p>
|
||
|
<p>The operands of concatenation must be compatible strings or numeric data
|
||
|
types. The operands must not be distinct types. If a numeric operand is specified,
|
||
|
it is CAST to the equivalent character string prior to concatenation. Note
|
||
|
that a binary string cannot be concatenated with a character string, including
|
||
|
character strings defined as FOR BIT DATA.</p>
|
||
|
<p>The data type of the result is determined by the data types of the operands.
|
||
|
The data type of the result is summarized in the following table:</p>
|
||
|
<a name="wq349"></a>
|
||
|
<table id="wq349" width="100%" summary="" border="1" frame="border" rules="rows">
|
||
|
<caption>Table 23. Result Data Types With Concatenation</caption>
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq350" width="25%" align="left" valign="bottom">If one operand column is ...</th>
|
||
|
<th id="wq351" width="25%" align="left" valign="bottom">And the other operand is ...</th>
|
||
|
<th id="wq352" width="50%" align="left" valign="bottom">The data type of the result column is
|
||
|
...</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">DBCLOB(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y)* or VARCHAR(y)*
|
||
|
or CLOB(y)* or GRAPHIC(y) or VARGRAPHIC(y) or DBCLOB(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">DBCLOB(z) where z = MIN(x + y, maximum length
|
||
|
of a DBCLOB)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">VARGRAPHIC(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y)* or VARCHAR(y)*
|
||
|
or GRAPHIC(y) or VARGRAPHIC(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">VARGRAPHIC(z) where z = MIN(x + y, maximum
|
||
|
length of a VARGRAPHIC)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">GRAPHIC(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y)* mixed data</td>
|
||
|
<td align="left" valign="top" headers="wq352">VARGRAPHIC(z) where z = MIN(x + y, maximum
|
||
|
length of a VARGRAPHIC)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">GRAPHIC(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y)* SBCS data or GRAPHIC(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">GRAPHIC(z) where z = MIN(x + y, maximum length
|
||
|
of a GRAPHIC)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">CLOB(x)*</td>
|
||
|
<td align="left" valign="top" headers="wq351">GRAPHIC(y) or VARGRAPHIC(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">DBCLOB(z) where z = MIN(x + y, maximum length
|
||
|
of a DBCLOB)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">VARCHAR(x)*</td>
|
||
|
<td align="left" valign="top" headers="wq351">GRAPHIC(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">VARGRAPHIC(z) where z = MIN(x + y, maximum
|
||
|
length of a VARGRAPHIC)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">CLOB(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y) or VARCHAR(y) or CLOB(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">CLOB(z) where z = MIN(x + y, maximum length
|
||
|
of a CLOB)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">VARCHAR(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y) or VARCHAR(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">VARCHAR(z) where z = MIN(x + y, maximum length
|
||
|
of a VARCHAR)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">CHAR(x) mixed data</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">VARCHAR(z) where z = MIN(x + y, maximum length
|
||
|
of a VARCHAR)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">CHAR(x) SBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq351">CHAR(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">CHAR(z) where z = MIN(x + y, maximum length
|
||
|
of a CHAR)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">BLOB(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">BINARY(y) or VARBINARY(y) or BLOB(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">BLOB(z) where z = MIN(x + y, maximum length
|
||
|
of a BLOB)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">VARBINARY(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">BINARY(y) or VARBINARY(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">VARBINARY(z) where z = MIN(x + y, maximum
|
||
|
length of a VARBINARY)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq350">BINARY(x)</td>
|
||
|
<td align="left" valign="top" headers="wq351">BINARY(y)</td>
|
||
|
<td align="left" valign="top" headers="wq352">BINARY(z) where z = MIN(x + y, maximum length
|
||
|
of a BINARY)</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td colspan="3" headers="wq350 wq351 wq352">
|
||
|
<a name="wq353"></a>
|
||
|
<div class="notetitle" id="wq353">Note:</div>
|
||
|
<div class="notebody">
|
||
|
<p>* Character strings are
|
||
|
only allowed when the other operand is a graphic string if the graphic string
|
||
|
is UTF-16 or UCS-2.</p></div></td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<a name="wq354"></a>
|
||
|
<table id="wq354" width="100%" summary="" border="1" frame="border" rules="rows">
|
||
|
<caption>Table 24. Result Encoding Schemes With Concatenation</caption>
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq355" width="25%" align="left" valign="bottom">If one operand column is ...</th>
|
||
|
<th id="wq356" width="25%" align="left" valign="bottom">And the other operand is ...</th>
|
||
|
<th id="wq357" width="50%" align="left" valign="bottom">The data type of the result column is
|
||
|
...</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq355">Unicode data</td>
|
||
|
<td align="left" valign="top" headers="wq356">Unicode data or DBCS or mixed or SBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq357">Unicode data</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq355">DBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq356">DBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq357">DBCS data</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq355">bit data</td>
|
||
|
<td align="left" valign="top" headers="wq356">mixed or SBCS or bit data</td>
|
||
|
<td align="left" valign="top" headers="wq357">bit data</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq355">mixed data</td>
|
||
|
<td align="left" valign="top" headers="wq356">mixed or SBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq357">mixed data</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq355">SBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq356">SBCS data</td>
|
||
|
<td align="left" valign="top" headers="wq357">SBCS data</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<p>If the sum of the lengths of the operands exceeds the maximum length attribute
|
||
|
of the resulting data type:</p>
|
||
|
<ul>
|
||
|
<li>The length atttribute of the result is the maximum length of the resulting
|
||
|
data type.<sup class="fn"><a id="wq358" name="wq358" href="rbafzmstch2expr.htm#wq359">36</a></sup></li>
|
||
|
<li>If only blanks are truncated no warning or error occurs.</li>
|
||
|
<li>If non-blanks are truncated, an error occurs.</li></ul>
|
||
|
<p>If either operand can be null, the result can be null, and if either is
|
||
|
null, the result is the null value. Otherwise, the result consists of the
|
||
|
first operand string followed by the second.</p>
|
||
|
<p>With mixed data this result will not have redundant shift codes "at the
|
||
|
seam". Thus, if the first operand is a string ending with a "shift-in" character (<span class="hex">X'0F'</span>), while the second operand is a character string
|
||
|
beginning with a "shift-out" character (<span class="hex">X'0E'</span>), these two bytes
|
||
|
are eliminated from the result.</p>
|
||
|
<p>The actual length of the result is the sum of the lengths of the operands
|
||
|
unless redundant shifts are eliminated; in which case, the actual length is
|
||
|
two less than the sum of the lengths of the operands.</p>
|
||
|
<p>The CCSID of the result is determined by the CCSID of the operands as explained
|
||
|
under <a href="rbafzmstuuall.htm#uuall">Conversion rules for operations that combine strings</a>. Note that as a result of these rules: </p>
|
||
|
<ul>
|
||
|
<li>If any operand is bit data, the result is bit data.</li>
|
||
|
<li>If one operand is mixed data and the other is SBCS data, the result is
|
||
|
mixed data. However, this does not necessarily mean that the result is well-formed
|
||
|
mixed data.</li></ul>
|
||
|
<a name="wq360"></a>
|
||
|
<h4 id="wq360">Example</h4>
|
||
|
<p>Concatenate the column FIRSTNME with a blank and the column LASTNAME. </p>
|
||
|
<pre class="xmp"> FIRSTNME <span class="bold">CONCAT</span> ' ' <span class="bold">CONCAT</span> LASTNAME</pre>
|
||
|
<a name="scalarsubs"></a>
|
||
|
<h3 id="scalarsubs"><a href="rbafzmst02.htm#ToC_265">Scalar fullselect</a></h3><a id="idx695" name="idx695"></a><a id="idx696" name="idx696"></a>
|
||
|
<p>A scalar fullselect as supported in an expression is a fullselect,
|
||
|
enclosed in parentheses, that returns a single row consisting of a single
|
||
|
column value. If the fullselect does not return a row, the result of the expression
|
||
|
is the null value. If the select list element is an expression that is simply
|
||
|
a column name, the result column name is based on the name of the column.
|
||
|
See <a href="rbafzmstmark.htm#mark">fullselect</a> for more information.</p>
|
||
|
<p>A scalar fullselect is not allowed if the query specifies:</p>
|
||
|
<ul>
|
||
|
<li>lateral correlation,</li>
|
||
|
<li>a sort sequence,</li>
|
||
|
<li>an operation that requires CCSID conversion,</li>
|
||
|
<li>a UTF-8 or UTF-16 argument in a CHARACTER_LENGTH, POSITION, or SUBSTRING
|
||
|
scalar function,</li>
|
||
|
<li>a distributed table,</li>
|
||
|
<li>a table with a read trigger, or</li>
|
||
|
<li>a logical file built over multiple physical file members.</li></ul><a id="idx697" name="idx697"></a>
|
||
|
<p>A scalar subselect as supported in an expression is a subselect,
|
||
|
enclosed in parentheses, that returns a single row consisting of a single
|
||
|
column value. If the subselect does not return a row, the result of the expression
|
||
|
is the null value. If the select list element is an expression that is simply
|
||
|
a column name, the result column name is based on the name of the column.
|
||
|
See <a href="rbafzmstmark.htm#mark">fullselect</a> for more information.</p>
|
||
|
<a name="dtdur"></a>
|
||
|
<h3 id="dtdur"><a href="rbafzmst02.htm#ToC_266">Datetime operands and durations</a></h3><a id="idx698" name="idx698"></a><a id="idx699" name="idx699"></a><a id="idx700" name="idx700"></a><a id="idx701" name="idx701"></a>
|
||
|
<p>Datetime values can be incremented, decremented, and subtracted. These
|
||
|
operations may involve decimal numbers called <span class="italic">durations</span>. A <span class="italic">duration</span> is a positive or negative number
|
||
|
representing an interval of time. There are four types of durations: </p>
|
||
|
<dl>
|
||
|
<dt class="bold">Labeled durations (see <span><a href="rbafzmstch2expr.htm#labdur">diagram</a> on
|
||
|
page 125</span>)</dt>
|
||
|
<dd>A <span class="italic">labeled duration</span> represents a specific unit of time as
|
||
|
expressed by a number (which can be the result of an expression) followed
|
||
|
by one of the seven duration keywords: YEARS, MONTHS, DAYS, HOURS, MINUTES,
|
||
|
SECONDS, or MICROSECONDS<sup class="fn"><a href="rbafzmstch2expr.htm#fn17">37</a></sup>. The number specified is converted
|
||
|
as if it were assigned to a DECIMAL(15,0) number.
|
||
|
<p>A labeled duration can
|
||
|
only be used as an operand of an arithmetic operator in which the other operand
|
||
|
is a value of data type DATE, TIME, or TIMESTAMP. Thus, the expression HIREDATE
|
||
|
+ 2 MONTHS + 14 DAYS is valid whereas the expression HIREDATE + (2 MONTHS
|
||
|
+ 14 DAYS) is not. In both of these expressions, the labeled durations are
|
||
|
2 MONTHS and 14 DAYS.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">Date duration</dt><a id="idx702" name="idx702"></a><a id="idx703" name="idx703"></a>
|
||
|
<dd>A <span class="italic">date duration</span> represents a number of years,
|
||
|
months, and days, expressed as a DECIMAL(8,0) number. To be properly interpreted,
|
||
|
the number must have the format <span class="italic">yyyymmdd</span>, where <span class="italic">yyyy</span> represents the number of years, <span class="italic">mm</span> the number of months, and <span class="italic">dd</span> the number of
|
||
|
days. The result of subtracting one date value from another, as in the expression
|
||
|
HIREDATE - BRTHDATE, is a date duration.
|
||
|
</dd>
|
||
|
<dt class="bold">Time duration</dt><a id="idx704" name="idx704"></a><a id="idx705" name="idx705"></a>
|
||
|
<dd>A <span class="italic">time duration</span> represents a number of hours,
|
||
|
minutes, and seconds, expressed as a DECIMAL(6,0) number. To be properly interpreted,
|
||
|
the number must have the format <span class="italic">hhmmss</span> where <span class="italic">hh</span> represents the number of hours, <span class="italic">mm</span> the number
|
||
|
of minutes, and <span class="italic">ss</span> the number of seconds. The result
|
||
|
of subtracting one time value from another is a time duration.
|
||
|
</dd>
|
||
|
<dt class="bold">Timestamp duration</dt><a id="idx706" name="idx706"></a><a id="idx707" name="idx707"></a>
|
||
|
<dd>A <span class="italic">timestamp duration</span> represents a number of
|
||
|
years, months, days, hours, minutes, seconds, and microseconds, expressed
|
||
|
as a DECIMAL(20,6) number. To be properly interpreted, the number must have
|
||
|
the format <span class="italic">yyyymmddhhmmsszzzzzz,</span> where <span class="italic">yyyy, mm, dd, hh, mm, ss, <span class="base">and</span> zzzzzz</span> represent,
|
||
|
respectively, the number of years, months, days, hours, minutes, seconds,
|
||
|
and microseconds. The result of subtracting one timestamp value from another
|
||
|
is a timestamp duration.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<hr /><div class="fnnum"><a id="wq359" name="wq359" href="rbafzmstch2expr.htm#wq358">36</a>.</div>
|
||
|
<div class="fntext">If the expression is in the select-list, the length attribute
|
||
|
may be further reduced in order to fit within the maximum record size. For
|
||
|
more information, see <a href="rbafzmsthctabl.htm#maxrcd">Maximum row sizes</a>.</div><div class="fnnum"><a id="fn17" name="fn17">37</a>.</div>
|
||
|
<div class="fntext">Note that the singular form of these keywords is also
|
||
|
acceptable: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and MICROSECOND.</div>
|
||
|
<br />
|
||
|
<hr /><br />
|
||
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstch2function.htm">Previous Page</a> | <a href="rbafzmstdatetimearith.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>
|