9666 lines
561 KiB
HTML
9666 lines
561 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="scalar, function, scalar function, nesting,
|
|
ABSVAL, ABS, ABSVAL function, ABS function, ACOS, ACOS function, ADD_MONTHS,
|
|
ANTILOG, ANTILOG function, ASIN, ASIN function, ATAN, ATANH, ATANH function,
|
|
ATAN2, ATAN2 function, BIGINT, BIGINT function, BINARY, BINARY function,
|
|
BIT_LENGTH, BIT_LENGTH function, BLOB, BLOB function, CEILING, CEILING function,
|
|
CHAR, format, date and time, CHARACTER_LENGTH, CHAR_LENGTH,
|
|
CHARACTER_LENGTH function, CHAR_LENGTH function, CLOB, CLOB function, COALESCE,
|
|
COALESCE function, CONCAT, CONCAT function, COS, COS function, COSH,
|
|
COSH function, COT, COT function, CURDATE, CURDATE function, CURTIME,
|
|
CURTIME function, DATABASE, DATAPARTITIONNAME, DATAPARTITIONNAME function,
|
|
DATAPARTITIONNUM, DATAPARTITIONNUM function, DATE, DAY, DAY function, DAYNAME,
|
|
DAYNAME function, DAYOFMONTH, DAYOFMONTH function, DAYOFWEEK, DAYOFWEEK function,
|
|
DAYOFWEEK_ISO, DAYOFWEEK_ISO function, DAYOFYEAR, DAYOFYEAR function, DAYS,
|
|
DAYS function, DBCLOB, DBPARTITIONNAME, DBPARTITIONNAME function, NODENAME,
|
|
NODENAME function, DBPARTITIONNUM, DBPARTITIONNUM function, NODENUMBER,
|
|
NODENUMBER function, DECIMAL, DECIMAL function, DECRYPT_BIT,
|
|
DECRYPT_BIT function, DECRYPT_BINARY, DECRYPT_BINARY function, DECRYPT_CHAR,
|
|
DECRYPT_CHAR function, DECRYPT_DB, DECRYPT_DB function, DEGREES,
|
|
DEGREES function, DIFFERENCE, DIFFERENCE function, DIGITS, DIGITS function,
|
|
DLCOMMENT, DLCOMMENT function, DLLINKTYPE, DLLINKTYPE function, DLURLCOMPLETE,
|
|
DLURLCOMPLETE function, DLURLPATH, DLURLPATH function, DLURLPATHONLY,
|
|
DLURLPATHONLY function, DLURLSCHEME, DLURLSCHEME function, DLURLSERVER,
|
|
DLURLSERVER function, DLVALUE, DLVALUE function, DOUBLE, DOUBLE_PRECISION,
|
|
DOUBLE_PRECISION function, ENCRYPT_RC2, ENCRYPT_RC2 function, ENCRYPT_TDES,
|
|
ENCRYPT_TDES function, EXP, EXP function, EXTRACT, FLOAT, FLOAT function, FLOOR,
|
|
FLOOR function, GENERATE_UNIQUE, GENERATE_UNIQUE function, GETHINT,
|
|
GETHINT function, GRAPHIC, HASH, HASH function, HASHED_VALUE,
|
|
HASHED_VALUE function, PARTITION, PARTITION function, HEX, HEX function, HOUR,
|
|
HOUR function, IDENTITY_VAL_LOCAL, IDENTITY_VAL_LOCAL function, IFNULL,
|
|
IFNULL function, INSERT, INSERT function, INTEGER, INTEGER function, JULIAN_DAY,
|
|
JULIAN_DAY function, LAND, LAND function, LAST_DAY, LCASE, LCASE function, LEFT,
|
|
LEFT function, LENGTH, LENGTH function, LN, LN function, LNOT, LNOT function,
|
|
LOCATE, LOCATE function, LOG, LOG10, LOG10 function, LOG function, LOR,
|
|
LOR function, LOWER, LOWER function, LTRIM function, LTRIM, MAX, MICROSECOND,
|
|
MICROSECOND function, MIDNIGHT_SECONDS, MIDNIGHT_SECONDS function, MIN, MINUTE,
|
|
MINUTE function, MOD, MOD function, MONTH, MONTH function, MONTHNAME,
|
|
MONTHNAME function, MULTIPLY_ALT, NEXT_DAY, NOW, NOW function, NULLIF,
|
|
NULLIF function, OCTET_LENGTH, OCTET_LENGTH function, PI, PI function, POSSTR,
|
|
POSITION, POSSTR function, POSITION function, POWER, POWER function, QUARTER,
|
|
QUARTER function, RADIANS, RADIANS function, RAISE_ERROR, RAISE_ERROR function,
|
|
RAND, RAND function, REAL, REAL function, REPEAT, REPEAT function, REPLACE,
|
|
REPLACE function, RIGHT, RIGHT function, ROUND, ROUND function, ROWID,
|
|
ROWID function, RRN, RRN function, designator, table, RTRIM function, RTRIM,
|
|
SECOND, SECOND function, SIGN, SIGN function, SIN, SIN function, SINH,
|
|
SINH function, SMALLINT, SMALLINT function, SOUNDEX, SOUNDEX function,
|
|
SPACE function, SPACE, SQRT, SQRT function, STRIP, STRIP function,
|
|
SUBSTR (or SUBSTRING), SUBSTR function, SUBSTRING function, TAN, TAN function,
|
|
TANH, TANH function, TIME, TIMESTAMP, TIMESTAMP_ISO, TIMESTAMPDIFF, TRANSLATE,
|
|
TRANSLATE function, TRIM, TRIM function, TRUNCATE, TRUNCATE function, UCASE,
|
|
UCASE function, UPPER, UPPER function, VALUE, VALUE function, VARBINARY,
|
|
VARBINARY function, VARCHAR, VARCHAR_FORMAT, TO_CHAR, VARGRAPHIC, WEEK,
|
|
WEEK function, WEEK_ISO, WEEK_ISO function, XOR, XOR function, YEAR,
|
|
YEAR function, ZONED, ZONED function" />
|
|
<title>Scalar functions</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="scale"></a>
|
|
<h2 id="scale"><a href="rbafzmst02.htm#ToC_340">Scalar functions</a></h2>
|
|
<p>A <var class="pv">scalar function</var> can be used wherever an expression can be used. <a id="idx854" name="idx854"></a><a id="idx855" name="idx855"></a><a id="idx856" name="idx856"></a><a id="idx857" name="idx857"></a> The restrictions on the use of aggregate functions do
|
|
not apply to scalar functions, because a scalar function is applied to single
|
|
parameter values rather than to sets of values. The argument of a scalar function
|
|
can be a function. However, the restrictions that apply to the use of expressions
|
|
and aggregate functions also apply when an expression or aggregate function
|
|
is used within a scalar function. For example, the argument of a scalar function
|
|
can be an aggregate function only if an aggregate function is allowed in the
|
|
context in which the scalar function is used.</p>
|
|
<a name="wq506"></a>
|
|
<h3 id="wq506"><a href="rbafzmst02.htm#ToC_341">Example</a></h3>
|
|
<p>The result of the following SELECT statement has as many rows as there
|
|
are employees in department D01:</p>
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, LASTNAME, <span class="bold">YEAR(CURRENT DATE</span> - BIRTHDATE<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> WORKDEPT = 'D01'</pre>
|
|
<a name="scaabs"></a>
|
|
<h3 id="scaabs"><a href="rbafzmst02.htm#ToC_342">ABS</a></h3><a id="idx858" name="idx858"></a><a id="idx859" name="idx859"></a><a id="idx860" name="idx860"></a><a id="idx861" name="idx861"></a>
|
|
<a href="rbafzmstscale.htm#synabs"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq507"></a>
|
|
<div class="fignone" id="wq507">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn48.htm"
|
|
border="0" /></span><a href="#skipsyn-47"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ABS--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-47" id="skipsyn-47"></a></div>
|
|
<a name="synabs"></a>
|
|
<p id="synabs">The ABS function returns the absolute value of a number.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type and length attribute of the result are the same as the data
|
|
type and length attribute of the argument value, except that the result is
|
|
a large integer if the argument value is a small integer, and the result is
|
|
double-precision floating point if the argument value is single-precision
|
|
floating point.</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<a name="wq508"></a>
|
|
<h4 id="wq508">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> ABSVAL is a synonym for ABS.
|
|
It is supported only for compatibility with previous DB2® releases.</p>
|
|
<a name="wq509"></a>
|
|
<h4 id="wq509">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable PROFIT is a large integer with a value of -50000.
|
|
<pre class="xmp"> <span class="bold">SELECT ABS</span>(:PROFIT)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns the value 50000.</li></ul>
|
|
<a name="scaacos"></a>
|
|
<h3 id="scaacos"><a href="rbafzmst02.htm#ToC_345">ACOS</a></h3><a id="idx862" name="idx862"></a><a id="idx863" name="idx863"></a>
|
|
<a href="rbafzmstscale.htm#synacos"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq510"></a>
|
|
<div class="fignone" id="wq510">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn49.htm"
|
|
border="0" /></span><a href="#skipsyn-48"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ACOS--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-48" id="skipsyn-48"></a></div>
|
|
<a name="synacos"></a>
|
|
<p id="synacos">The ACOS function returns the arc cosine of the argument as
|
|
an angle expressed in radians. The ACOS and COS functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. The value must be greater than or equal to -1 and
|
|
less than or equal to 1.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<p>The result is greater than or equal to 0 and less than or equal to π.</p>
|
|
<a name="wq511"></a>
|
|
<h4 id="wq511">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable ACOSINE is a DECIMAL(10,9) host variable with
|
|
a value of 0.070737202.
|
|
<pre class="xmp"> <span class="bold">SELECT ACOS</span>(:ACOSINE)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns the approximate
|
|
value 1.49.</li></ul>
|
|
<a name="scaaddmonths"></a>
|
|
<h3 id="scaaddmonths"><a href="rbafzmst02.htm#ToC_347">ADD_MONTHS</a></h3><a id="idx864" name="idx864"></a><a id="idx865" name="idx865"></a>
|
|
<a href="rbafzmstscale.htm#synaddmonths"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq512"></a>
|
|
<div class="fignone" id="wq512">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn50.htm"
|
|
border="0" /></span><a href="#skipsyn-49"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ADD_MONTHS--(--<span class="italic">expression</span>--,--<span class="italic">numeric-expression</span>--)---------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-49" id="skipsyn-49"></a></div>
|
|
<a name="synaddmonths"></a>
|
|
<p id="synaddmonths">The ADD_MONTHS function returns a date that represents <var class="pv">expression</var> plus <var class="pv">numeric-expression</var> months.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of
|
|
a built-in numeric data type with zero scale. A negative numeric value is
|
|
allowed.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a date. If either argument can be null, the
|
|
result can be null; if either argument is null, the result is the null value.</p>
|
|
<p>If <var class="pv">expression</var> is the last day of the month or if the resulting
|
|
month has fewer days than the day component of <var class="pv">expression</var>, then the
|
|
result is the last day of the resulting month. Otherwise, the result has the
|
|
same day component as <var class="pv">expression</var>.</p>
|
|
<a name="wq513"></a>
|
|
<h4 id="wq513">Example</h4>
|
|
<ul>
|
|
<li>Assume today is January 31, 2000. Set the host variable ADD_MONTH with
|
|
the last day of January plus 1 month.
|
|
<pre class="xmp"><span class="bold">SET </span>:ADD_MONTH <span class="bold">= ADD_MONTHS(LAST_DAY(CURRENT_DATE),</span> 1<span class="bold"> )</span> </pre>
|
|
<p>The host variable ADD_MONTH is set with the value representing
|
|
the end of February, 2000-02-29.</p></li>
|
|
<li>Assume DATE is a host variable with the value July 27, 1965. Set the host
|
|
variable ADD_MONTH with the value of that day plus 3 months.
|
|
<pre class="xmp"><span class="bold">SET </span>:ADD_MONTH <span class="bold">= ADD_MONTHS(</span>:DATE<span class="bold">, </span>3<span class="bold">)</span></pre>
|
|
<p>The host variable ADD_MONTH is set
|
|
with the value representing the day plus 3 months, 1965-10-27.</p></li>
|
|
<li>It is possible to achieve similar results with the ADD_MONTHS function
|
|
and date arithmetic. The following examples demonstrate the similarities and
|
|
contrasts.
|
|
<pre class="xmp"><span class="bold">SET</span> :DATEHV <span class="bold">= DATE(</span>'2000-2-28'<span class="bold">) +</span> 4 <span class="bold">MONTHS</span>
|
|
<span class="bold">SET</span> :DATEHV <span class="bold">ADD_MONTHS(</span>'2000-2-28'<span class="bold">,</span> 4<span class="bold">)</span>
|
|
</pre>
|
|
<p>In both cases, the host variable DATEHV is set with the value '2000–06–28'.</p>
|
|
<p>Now consider the same examples but with the date '2000–2–29'
|
|
as the argument.</p>
|
|
<pre class="xmp"><span class="bold">SET </span>:DATEHV <span class="bold">= DATE(</span>'2000-2-29'<span class="bold">) + </span>4 <span class="bold">MONTHS</span>
|
|
</pre>
|
|
<p>The host variable DATEHV is set with the value '2000–06–29'.</p>
|
|
<pre class="xmp"><span class="bold">SET </span>:DATEHV <span class="bold">ADD_MONTHS(</span>'2000-2-29'<span class="bold">, </span>4<span class="bold">)</span></pre>
|
|
<p>The host variable DATEHV
|
|
is set with the value '2000–06–30'.</p>
|
|
<p>In this case, the ADD_MONTHS
|
|
function returns the last day of the month, which is June 30, 2000, instead
|
|
of June 29, 2000. The reason is that February 29 is the last day of the month.
|
|
So, the ADD_MONTHS function returns the last day of June.</p></li></ul>
|
|
<a name="scaantilog"></a>
|
|
<h3 id="scaantilog"><a href="rbafzmst02.htm#ToC_349">ANTILOG</a></h3><a id="idx866" name="idx866"></a><a id="idx867" name="idx867"></a>
|
|
<a href="rbafzmstscale.htm#synantilog"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq514"></a>
|
|
<div class="fignone" id="wq514">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn51.htm"
|
|
border="0" /></span><a href="#skipsyn-50"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ANTILOG--(--<span class="italic">expression</span>--)-----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-50" id="skipsyn-50"></a></div>
|
|
<a name="synantilog"></a>
|
|
<p id="synantilog">The ANTILOG function returns the anti-logarithm (base 10)
|
|
of a number. The ANTILOG and LOG functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq515"></a>
|
|
<h4 id="wq515">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable ALOG is a DECIMAL(10,9) host variable with a
|
|
value of 1.499961866.
|
|
<pre class="xmp"> <span class="bold">SELECT ANTILOG</span>(:ALOG)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 31.62.</li></ul>
|
|
<a name="scaasin"></a>
|
|
<h3 id="scaasin"><a href="rbafzmst02.htm#ToC_351">ASIN</a></h3><a id="idx868" name="idx868"></a><a id="idx869" name="idx869"></a>
|
|
<a href="rbafzmstscale.htm#synasin"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq516"></a>
|
|
<div class="fignone" id="wq516">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn52.htm"
|
|
border="0" /></span><a href="#skipsyn-51"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ASIN--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-51" id="skipsyn-51"></a></div>
|
|
<a name="synasin"></a>
|
|
<p id="synasin">The ASIN function returns the arc sine of the argument as
|
|
an angle expressed in radians. The ASIN and SIN functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. The value must be greater than or equal to -1
|
|
and less than or equal to 1.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<p>The result is greater than or equal to -π /2 and less than or equal
|
|
to π /2.</p>
|
|
<a name="wq517"></a>
|
|
<h4 id="wq517">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable ASINE is a DECIMAL(10,9) host variable with a
|
|
value of 0.997494987.
|
|
<pre class="xmp"> <span class="bold">SELECT ASIN</span>(:ASINE)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 1.50.</li></ul>
|
|
<a name="scaatan"></a>
|
|
<h3 id="scaatan"><a href="rbafzmst02.htm#ToC_353">ATAN</a></h3><a id="idx870" name="idx870"></a>
|
|
<a href="rbafzmstscale.htm#synatan"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq518"></a>
|
|
<div class="fignone" id="wq518">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn53.htm"
|
|
border="0" /></span><a href="#skipsyn-52"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ATAN--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-52" id="skipsyn-52"></a></div>
|
|
<a name="synatan"></a>
|
|
<p id="synatan">The ATAN function returns the arc tangent of the argument
|
|
as an angle expressed in radians. The ATAN and TAN functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<p>The result is greater than or equal to -π/2 and less than or equal to
|
|
π/2.</p>
|
|
<a name="wq519"></a>
|
|
<h4 id="wq519">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable ATANGENT is a DECIMAL(10,8) host variable with
|
|
a value of 14.10141995.
|
|
<pre class="xmp"> <span class="bold">SELECT ATAN</span>(:ATANGENT)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 1.50.</li></ul>
|
|
<a name="scaatanh"></a>
|
|
<h3 id="scaatanh"><a href="rbafzmst02.htm#ToC_355">ATANH</a></h3><a id="idx871" name="idx871"></a><a id="idx872" name="idx872"></a>
|
|
<a href="rbafzmstscale.htm#synatanh"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq520"></a>
|
|
<div class="fignone" id="wq520">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn54.htm"
|
|
border="0" /></span><a href="#skipsyn-53"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ATANH--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-53" id="skipsyn-53"></a></div>
|
|
<a name="synatanh"></a>
|
|
<p id="synatanh">The ATANH function returns the hyperbolic arc tangent of
|
|
a number, in radians. The ATANH and TANH functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. The value must be greater than -1 and less than
|
|
1.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq521"></a>
|
|
<h4 id="wq521">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HATAN is a DECIMAL(10,9) host variable with a
|
|
value of 0.905148254.
|
|
<pre class="xmp"> <span class="bold">SELECT ATANH</span>(:HATAN)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 1.50.</li></ul>
|
|
<a name="scaatan2"></a>
|
|
<h3 id="scaatan2"><a href="rbafzmst02.htm#ToC_357">ATAN2</a></h3><a id="idx873" name="idx873"></a><a id="idx874" name="idx874"></a>
|
|
<a href="rbafzmstscale.htm#synatan2"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq522"></a>
|
|
<div class="fignone" id="wq522">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn55.htm"
|
|
border="0" /></span><a href="#skipsyn-54"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ATAN2--(--<span class="italic">expression</span>--,--<span class="italic">expression</span>--)----------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-54" id="skipsyn-54"></a></div>
|
|
<a name="synatan2"></a>
|
|
<p id="synatan2">The ATAN2 function returns the arc tangent of x and y coordinates
|
|
as an angle expressed in radians. The first and second arguments specify the
|
|
x and y coordinates, respectively.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. If one argument is 0, the other argument must not
|
|
be 0.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If any
|
|
argument can be null, the result can be null; if any argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq523"></a>
|
|
<h4 id="wq523">Example</h4>
|
|
<ul>
|
|
<li>Assume that host variables HATAN2A and HATAN2B are DOUBLE host variables
|
|
with values of 1 and 2, respectively.
|
|
<pre class="xmp"> <span class="bold">SELECT ATAN2</span>(:HATAN2A,:HATAN2B)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
a double precision floating-point number with an approximate value of 1.1071487.</li></ul>
|
|
<a name="bigfunc"></a>
|
|
<h3 id="bigfunc"><a href="rbafzmst02.htm#ToC_359">BIGINT</a></h3><a id="idx875" name="idx875"></a><a id="idx876" name="idx876"></a>
|
|
<a href="rbafzmstscale.htm#synbigint"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq524"></a>
|
|
<div class="fignone" id="wq524">
|
|
<p><span class="bold">Numeric to Big Integer</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn56.htm"
|
|
border="0" /></span><a href="#skipsyn-55"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>---BIGINT----(--<span class="italic">numeric-expression</span>--)------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-55" id="skipsyn-55"></a>
|
|
<p><span class="bold">String to Big Integer</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn57.htm"
|
|
border="0" /></span><a href="#skipsyn-56"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>---BIGINT----(--<span class="italic">string-expression</span>--)-------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-56" id="skipsyn-56"></a></div>
|
|
<a name="synbigint"></a>
|
|
<p id="synbigint">The BIGINT function returns a big integer representation
|
|
of:</p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p><span class="bold">Numeric to Big Integer</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>An expression that returns a numeric value of any built-in numeric data
|
|
type.
|
|
<p>If the argument is a <var class="pv">numeric-expression</var>, the result is the
|
|
same number that would occur if the argument were assigned to a big integer
|
|
column or variable. If the whole part of the argument is not within the range
|
|
of big integers, an error is returned. The fractional part of the argument
|
|
is truncated.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">String to Big Integer</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a value that is a character-string or graphic-string
|
|
representation of a number.
|
|
<p>If the argument is a <var class="pv">string-expression</var>,
|
|
the result is the same number that would result from CAST( <var class="pv">string-expression</var> AS BIGINT). Leading and trailing blanks are eliminated and the resulting
|
|
string must conform to the rules for forming a floating-point, integer, or
|
|
decimal constant. If the whole part of the argument is not within the range
|
|
of big integers, an error is returned. Any fractional part of the argument
|
|
is truncated.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a big integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq525"></a>
|
|
<h4 id="wq525">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq526"></a>
|
|
<h4 id="wq526">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, select the EMPNO column in big integer form
|
|
for further processing in the application.
|
|
<pre class="xmp"> <span class="bold">SELECT BIGINT</span>(SALARY)
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scabinary"></a>
|
|
<h3 id="scabinary"><a href="rbafzmst02.htm#ToC_362">BINARY</a></h3><a id="idx877" name="idx877"></a><a id="idx878" name="idx878"></a>
|
|
<a href="rbafzmstscale.htm#synbinary"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq527"></a>
|
|
<div class="fignone" id="wq527">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn58.htm"
|
|
border="0" /></span><a href="#skipsyn-57"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-BINARY--(--<span class="italic">string-expression</span>--+------------+--)-------------><
|
|
'-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-57" id="skipsyn-57"></a></div>
|
|
<a name="synbinary"></a>
|
|
<p id="synbinary">The BINARY function returns a BINARY representation of a
|
|
string of any type.</p>
|
|
<p>The result of the function is a fixed-length binary string. If the first
|
|
argument can be null, the result can be null; if the first argument is null,
|
|
the result is the null value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>A <span class="italic">string-expression</span> whose value must be a built-in
|
|
character string, graphic string, binary string, or row ID data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting binary string. The value must be between 1 and 32766.
|
|
<p>If <var class="pv">integer</var> is not specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">string-expression</span> is the empty string constant,
|
|
the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument, unless the argument is a graphic string.
|
|
In this case, the length attribute of the result is twice the length attribute
|
|
of the argument.</li></ul>
|
|
<p>The actual length is the same as the length attribute of the
|
|
result. If the length of the <span class="italic">string-expression</span> is
|
|
less than the length of the result, the result is padded with hexadecimal
|
|
zeroes up to the length of the result. If the length of the <span class="italic">string-expression</span> is greater than the length attribute of the result,
|
|
truncation is performed. A warning (SQLSTATE 01004) is returned unless the
|
|
first input argument is a character string and all the truncated characters
|
|
are blanks, or the first input argument is a graphic string and all the truncated
|
|
characters are double-byte blanks, or the first input argument is a binary
|
|
string and all the truncated bytes are hexadecimal zeroes.</p>
|
|
</dd>
|
|
</dl>
|
|
<a name="wq528"></a>
|
|
<h4 id="wq528">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the length is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq529"></a>
|
|
<h4 id="wq529">Example</h4>
|
|
<ul>
|
|
<li>The following function returns a BINARY for the string 'This is a BINARY'.
|
|
<pre class="xmp"> <span class="bold">SELECT BINARY(</span>'This is a BINARY'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scabitlen"></a>
|
|
<h3 id="scabitlen"><a href="rbafzmst02.htm#ToC_365">BIT_LENGTH</a></h3><a id="idx879" name="idx879"></a><a id="idx880" name="idx880"></a>
|
|
<a href="rbafzmstscale.htm#synbitlen"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq530"></a>
|
|
<div class="fignone" id="wq530">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn59.htm"
|
|
border="0" /></span><a href="#skipsyn-58"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>---BIT_LENGTH----(--<span class="italic">expression</span>--)----------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-58" id="skipsyn-58"></a></div>
|
|
<a name="synbitlen"></a>
|
|
<p id="synbitlen">The BIT_LENGTH function returns the length of a string expression
|
|
in bits. See <a href="rbafzmstscale.htm#scalength">LENGTH</a> , <a href="rbafzmstscale.htm#charlenf">CHARACTER_LENGTH</a> , and <a href="rbafzmstscale.htm#scaoctetlen">OCTET_LENGTH</a> for similar functions.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is DECIMAL(31). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The result is the number of bits (bytes * 8) in the argument. The length
|
|
of a string includes trailing blanks. The length of a varying-length string
|
|
is the actual length in bits (bytes * 8), not the maximum length.</p>
|
|
<a name="wq531"></a>
|
|
<h4 id="wq531">Example</h4>
|
|
<ul>
|
|
<li>Assume table T1 has a GRAPHIC(10) column called C1.
|
|
<pre class="xmp"> <span class="bold">SELECT BIT_LENGTH(</span> C1 <span class="bold">)</span>
|
|
<span class="bold">FROM</span> T1</pre> Returns the value
|
|
160.</li></ul>
|
|
<a name="scablob"></a>
|
|
<h3 id="scablob"><a href="rbafzmst02.htm#ToC_367">BLOB</a></h3><a id="idx881" name="idx881"></a><a id="idx882" name="idx882"></a>
|
|
<a href="rbafzmstscale.htm#synblob"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq532"></a>
|
|
<div class="fignone" id="wq532">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn60.htm"
|
|
border="0" /></span><a href="#skipsyn-59"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-BLOB--(--<span class="italic">string-expression</span>--+------------+--)---------------><
|
|
'-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-59" id="skipsyn-59"></a></div>
|
|
<a name="synblob"></a>
|
|
<p id="synblob">The BLOB function returns a BLOB representation of a string
|
|
of any type.</p>
|
|
<p>The result of the function is a BLOB. If the first argument can be null,
|
|
the result can be null; if the first argument is null, the result is the null
|
|
value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>A <span class="italic">string-expression</span> whose value can be a character
|
|
string, graphic string, binary string, or row ID.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd>An integer constant that specifies the length attribute for the resulting
|
|
binary string. The value must be between 1 and 2 147 483 647.
|
|
<p>If <var class="pv">integer</var> is not specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">string-expression</span> is the empty string constant,
|
|
the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument, unless the argument is a graphic string.
|
|
In this case, the length attribute of the result is twice the length attribute
|
|
of the argument.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length
|
|
attribute of the result and the actual length of the expression (or twice
|
|
the length of the expression when the input is graphic data). If the length
|
|
of the <span class="italic">string-expression</span> is greater than the length
|
|
attribute of the result, truncation is performed. A warning (SQLSTATE 01004)
|
|
is returned unless the first input argument is a character string and all
|
|
the truncated characters are blanks, or the first input argument is a graphic
|
|
string and all the truncated characters are double-byte blanks, or the first
|
|
input argument is a binary string and all the truncated bytes are hexadecimal
|
|
zeroes.</p>
|
|
</dd>
|
|
</dl>
|
|
<a name="wq533"></a>
|
|
<h4 id="wq533">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the length is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq534"></a>
|
|
<h4 id="wq534">Example</h4>
|
|
<ul>
|
|
<li>The following function returns a BLOB for the string 'This is a BLOB'.
|
|
<pre class="xmp"> <span class="bold">SELECT BLOB(</span>'This is a BLOB'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li>
|
|
<li>The following function returns a BLOB for the large object that is identified
|
|
by locator myclob_locator.
|
|
<pre class="xmp"> <span class="bold">SELECT BLOB(</span>:myclob_locator<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li>
|
|
<li>Assume that a table has a BLOB column named TOPOGRAPHIC_MAP and a VARCHAR
|
|
column named MAP_NAME. Locate any maps that contain the string 'Pellow Island'
|
|
and return a single binary string with the map name concatenated in front
|
|
of the actual map. The following function returns a BLOB for the large object
|
|
that is identified by locator myclob_locator.
|
|
<pre class="xmp"> <span class="bold">SELECT BLOB(</span> MAP_NAME <span class="bold">CONCAT </span> ': ' <span class="bold">CONCAT </span> TOPOGRAPHIC_MAP <span class="bold">)</span>
|
|
<span class="bold">FROM</span> ONTARIO_SERIES_4
|
|
<span class="bold">WHERE</span> TOPOGRAPHIC_MAP <span class="bold">LIKE</span> '%Pellow Island%'</pre></li></ul>
|
|
<a name="scaceiling"></a>
|
|
<h3 id="scaceiling"><a href="rbafzmst02.htm#ToC_370">CEILING</a></h3><a id="idx883" name="idx883"></a><a id="idx884" name="idx884"></a>
|
|
<a href="rbafzmstscale.htm#synceiling"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq535"></a>
|
|
<div class="fignone" id="wq535">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn61.htm"
|
|
border="0" /></span><a href="#skipsyn-60"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-CEILING-+--(--<span class="italic">expression</span>--)-------------------------------><
|
|
'-CEIL----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-60" id="skipsyn-60"></a></div>
|
|
<a name="synceiling"></a>
|
|
<p id="synceiling">The CEIL or CEILING function returns the smallest integer
|
|
value that is greater than or equal to <var class="pv">expression</var>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function has the same data type and length attribute
|
|
of the argument except that the scale is 0 if the argument is DECIMAL or NUMERIC.
|
|
For example, an argument with a data type of DECIMAL(5,5) will result in DECIMAL(5,0).</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<a name="wq536"></a>
|
|
<h4 id="wq536">Examples</h4>
|
|
<ul>
|
|
<li>Find the highest monthly salary for all the employees. Round the result
|
|
up to the next integer. The SALARY column has a decimal data type
|
|
<pre class="xmp"> <span class="bold">SELECT CEIL(MAX(</span>SALARY<span class="bold">)/</span>12
|
|
<span class="bold">FROM</span> EMPLOYEE</pre>This example
|
|
returns 4396.00 because the highest paid employee is Christine Haas who earns
|
|
$52750.00 per year. Her average monthly salary before applying the CEIL function
|
|
is 4395.83.</li>
|
|
<li>Use CEILING on both positive and negative numbers.
|
|
<pre class="xmp"> <span class="bold">SELECT CEILING(</span> 3.5<span class="bold">)</span>,
|
|
<span class="bold">CEILING(</span> 3.1<span class="bold">)</span>,
|
|
<span class="bold">CEILING(</span>-3.1<span class="bold">)</span>,
|
|
<span class="bold">CEILING(</span>-3.5<span class="bold">)</span>,
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>This
|
|
example returns:
|
|
<pre class="xmp">04. 04. -03. -03.</pre>respectively.</li></ul>
|
|
<a name="scachar"></a>
|
|
<h3 id="scachar"><a href="rbafzmst02.htm#ToC_372">CHAR</a></h3><a id="idx885" name="idx885"></a><a id="idx886" name="idx886"></a>
|
|
<a href="rbafzmstscale.htm#synchar"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq537"></a>
|
|
<div class="fignone" id="wq537">
|
|
<p><span class="bold">Datetime to Character</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn62.htm"
|
|
border="0" /></span><a href="#skipsyn-61"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CHAR--(--<span class="italic">datetime-expression</span>--+--------------+--)-----------><
|
|
'-,--+-ISO---+-'
|
|
+-USA---+
|
|
+-EUR---+
|
|
+-JIS---+
|
|
'-LOCAL-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-61" id="skipsyn-61"></a>
|
|
<p><span class="bold">Graphic to Character</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn63.htm"
|
|
border="0" /></span><a href="#skipsyn-62"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CHAR--(--<span class="italic">graphic-expression</span>--+------------+--)--------------><
|
|
'-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-62" id="skipsyn-62"></a>
|
|
<p><span class="bold">Character to Character</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn64.htm"
|
|
border="0" /></span><a href="#skipsyn-63"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CHAR--(--<span class="italic">character-expression</span>--+------------+--)------------><
|
|
'-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-63" id="skipsyn-63"></a>
|
|
<p><span class="bold">Integer to Character</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn65.htm"
|
|
border="0" /></span><a href="#skipsyn-64"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CHAR--(--<span class="italic">integer-expression</span>--)------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-64" id="skipsyn-64"></a>
|
|
<p><span class="bold">Decimal to Character</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn66.htm"
|
|
border="0" /></span><a href="#skipsyn-65"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CHAR--(--<span class="italic">decimal-expression</span>--+----------------------+--)----><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-65" id="skipsyn-65"></a>
|
|
<p><span class="bold">Floating-point to Character</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn67.htm"
|
|
border="0" /></span><a href="#skipsyn-66"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CHAR--------------------------------------------------------->
|
|
|
|
>--(--<span class="italic">floating-point-expression</span>--+----------------------+--)---><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-66" id="skipsyn-66"></a></div>
|
|
<a name="synchar"></a>
|
|
<p id="synchar">The CHAR function returns a fixed-length character-string
|
|
representation of:</p>
|
|
<ul>
|
|
<li>An integer number if the first argument is a SMALLINT, INTEGER, or BIGINT.</li>
|
|
<li>A decimal number if the first argument is a decimal number.</li>
|
|
<li>A double-precision floating-point number if the first argument is a DOUBLE
|
|
or REAL.</li>
|
|
<li>A character string if the first argument is any type of character string.</li>
|
|
<li>A graphic string if the first argument is any type of graphic string.</li>
|
|
<li>A date value if the first argument is a DATE.</li>
|
|
<li>A time value if the first argument is a TIME.</li>
|
|
<li>A timestamp value if the first argument is a TIMESTAMP.</li>
|
|
<li>A row ID value if the first argument is a ROWID.</li></ul>
|
|
<p>The first argument must be a built-in data type other than a BINARY, VARBINARY,
|
|
or BLOB.</p>
|
|
<p>The result of the function is a fixed-length character string. If the first
|
|
argument can be null, the result can be null; if the first argument is null,
|
|
the result is the null value.</p>
|
|
<p><span class="bold">Datetime to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">datetime-expression</var></dt>
|
|
<dd>An expression that is one of the following three built-in data types
|
|
<dl>
|
|
<dt class="bold">date</dt><a id="idx887" name="idx887"></a>
|
|
<dd>The result is the character-string representation of the date in the
|
|
format specified by the second argument. If the second argument is not specified,
|
|
the format used is the default date format. If the format is ISO, USA, EUR,
|
|
or JIS, the length of the result is 10. Otherwise the length of the result
|
|
is the length of the default date format. For more information see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
<dt class="bold">time</dt>
|
|
<dd>The result is the character-string representation of the time in the
|
|
format specified by the second argument. If the second argument is not specified,
|
|
the format used is the default time format. The length of the result is 8.
|
|
For more information see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv"></var>timestamp</dt>
|
|
<dd>The second argument is not applicable and must not be specified.
|
|
<p>The result is the character-string representation of the timestamp. The length
|
|
of the result is 26.</p>
|
|
</dd>
|
|
</dl>The CCSID of the string is the default SBCS CCSID at the current server.
|
|
</dd>
|
|
<dt class="bold">ISO, EUR, USA, or JIS</dt>
|
|
<dd>Specifies the date or time format of the resulting character string.
|
|
For more information, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
<dt class="bold">LOCAL</dt>
|
|
<dd>Specifies that the date or time format of the resulting character string
|
|
should come from the DATFMT, DATSEP, TIMFMT, and TIMSEP attributes of the
|
|
job at the current server.
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Graphic to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">graphic-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in graphic-string
|
|
data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting fixed length character string. The value must be between
|
|
1 and 32766 (32765 if nullable).
|
|
<p>If the second argument is not specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">graphic-expression</span> is the empty string
|
|
constant, the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument.</li></ul>
|
|
<p>The actual length is the same as the length attribute of the
|
|
result. If the length of the <span class="italic">graphic-expression</span> is
|
|
less than the length of the result, the result is padded with blanks up to
|
|
the length of the result. If the length of the <span class="italic">graphic-expression</span> is greater than the length attribute of the result, truncation is performed.
|
|
A warning (SQLSTATE 01004) is returned unless the truncated characters were
|
|
all blanks.</p>
|
|
<p>The CCSID of the string is the default CCSID of the current
|
|
server.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Character to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">character-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in character-string
|
|
data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting fixed length character string. The value must be between
|
|
1 and 32766 (32765 if nullable). If the first argument is mixed data, the
|
|
second argument cannot be less than 4.
|
|
<p>If the second argument is not specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">character-expression</span> is the empty string
|
|
constant, the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument.</li></ul>
|
|
<p>The actual length is the same as the length attribute of the
|
|
result. If the length of the <span class="italic">character-expression</span> is
|
|
less than the length of the result, the result is padded with blanks up to
|
|
the length of the result. If the length of the <span class="italic">character-expression</span> is greater than the length attribute of the result, truncation is performed.
|
|
A warning (SQLSTATE 01004) is returned unless the truncated characters were
|
|
all blanks.</p>
|
|
<p>The CCSID of the string is the CCSID of the <var class="pv">character-expression</var>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Integer to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">integer-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in integer
|
|
data type (either SMALLINT, INTEGER, or BIGINT).
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is the fixed-length character-string representation of
|
|
the argument in the form of an SQL integer constant. The result consists of
|
|
n characters that are the significant digits that represent the value of the
|
|
argument with a preceding minus sign if the argument is negative. The result
|
|
is left justified.</p>
|
|
<ul>
|
|
<li>If the argument is a small integer:
|
|
<p>The length of the result is 6. If
|
|
the number of characters in the result is less than 6, then the result is
|
|
padded on the right with blanks.</p></li>
|
|
<li>If the argument is a large integer:
|
|
<p>The length of the result is 11.
|
|
If the number of characters in the result is less than 11, then the result
|
|
is padded on the right with blanks.</p></li>
|
|
<li>If the argument is a big integer:
|
|
<p>The length of the result is 20. If
|
|
the number of characters in the result is less than 20, then the result is
|
|
padded on the right with blanks.</p></li></ul><p class="indatacontent">The CCSID of the string is the default SBCS CCSID at the current server.</p>
|
|
<p><span class="bold">Decimal to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">decimal-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in decimal data type
|
|
(either DECIMAL or NUMERIC). If a different precision and scale is desired,
|
|
the DECIMAL scalar function can be used to make the change.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a fixed-length character string representation of the
|
|
argument. The result includes a decimal character and up to <var class="pv">p</var> digits,
|
|
where <var class="pv">p</var> is the precision of the <var class="pv">decimal-expression</var> with
|
|
a preceding minus sign if the argument is negative. Leading zeros are not
|
|
returned. Trailing zeros are returned.</p>
|
|
<p>The length of the result is 2+<var class="pv">p</var> where <var class="pv">p</var> is the precision
|
|
of the <var class="pv">decimal-expression</var>. This means that a positive value will
|
|
always include one trailing blank.</p>
|
|
<p>The CCSID of the string is the default SBCS CCSID at the current server.</p>
|
|
<p><span class="bold">Floating-point to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">floating-point expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in floating-point
|
|
data type (DOUBLE or REAL).
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a fixed-length character-string representation of the
|
|
argument in the form of a floating-point constant. The length of the result
|
|
is 24. If the argument is negative, the first character of the result is a
|
|
minus sign. Otherwise, the first character is a digit. If the argument is
|
|
zero, the result is 0E0. Otherwise, the result includes the smallest number
|
|
of characters that can be used to represent the value of the argument such
|
|
that the mantissa consists of a single digit other than zero followed by a
|
|
period and a sequence of digits.</p>
|
|
<p>If the number of characters in the result is less than 24, then the result
|
|
is padded on the right with blanks.</p>
|
|
<p>The CCSID of the string is the default SBCS CCSID at the current server.</p>
|
|
<a name="wq538"></a>
|
|
<h4 id="wq538">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the first argument is numeric,
|
|
or the first argument is a string and the length argument is specified, the
|
|
CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq539"></a>
|
|
<h4 id="wq539">Examples</h4>
|
|
<ul>
|
|
<li>Assume the column PRSTDATE has an internal value equivalent to 1988-12-25.
|
|
The date format is *MDY and the date separator is a slash (/).
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>PRSTDATE, <span class="bold">USA)</span>
|
|
<span class="bold">FROM</span> PROJECT</pre> Results in the
|
|
value '12/25/1988'.
|
|
<p></p>
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>PRSTDATE<span class="bold">)</span>
|
|
<span class="bold">FROM</span> PROJECT</pre> Results in the
|
|
value '12/25/88'.</li>
|
|
<li>Assume the column STARTING has an internal value equivalent to 17.12.30,
|
|
the host variable HOUR_DUR (DECIMAL(6,0)) is a time duration with a value
|
|
of 050000 (that is, 5 hours).
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>STARTING, <span class="bold">USA)</span>
|
|
<span class="bold">FROM</span> CL_SCHED</pre> Results in the
|
|
value '5:12 PM'.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>STARTING + :HOUR_DUR, <span class="bold">JIS)</span>
|
|
<span class="bold">FROM</span> CL_SCHED</pre> Results in the
|
|
value '10:12:00'.</li>
|
|
<li>Assume the column RECEIVED (timestamp) has an internal value equivalent
|
|
to the combination of the PRSTDATE and STARTING columns.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>RECEIVED<span class="bold">)</span>
|
|
<span class="bold">FROM</span> IN_TRAY</pre> Results in the
|
|
value '1988-12-25-17.12.30.000000'.</li>
|
|
<li>Use the CHAR function to make the type fixed-length character and reduce
|
|
the length of the displayed results to 10 characters for the LASTNAME column
|
|
(defined as VARCHAR(15)) of the EMPLOYEE table.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>LASTNAME,10<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre> For rows having
|
|
a LASTNAME with a length greater than 10 characters (excluding trailing blanks),
|
|
a warning (SQLSTATE 01004) that the value is truncated is returned.</li>
|
|
<li>Use the CHAR function to return the values for EDLEVEL (defined as SMALLINT)
|
|
as a fixed length string.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>EDLEVEL<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre>An EDLEVEL of
|
|
18 would be returned as the CHAR(6) value '18 ' (18 followed
|
|
by 4 blanks).</li>
|
|
<li>Assume that the same SALARY subtracted from 20000.25 is to
|
|
be returned with a comma as the decimal character.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>20000.25 - SALARY, ','<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre>A SALARY of 21150
|
|
returns the value '–1149,75 ' (–1149,75 followed
|
|
by 3 blanks).</li>
|
|
<li>Assume a host variable, DOUBLE_NUM, has a double precision floating-point
|
|
data type and a value of -987.654321E-35.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(</span>:DOUBLE_NUM<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results
|
|
in the character value '-9.8765432100000002E-33 '.</li></ul>
|
|
<a name="charlenf"></a>
|
|
<h3 id="charlenf"><a href="rbafzmst02.htm#ToC_375">CHARACTER_LENGTH</a></h3><a id="idx888" name="idx888"></a><a id="idx889" name="idx889"></a><a id="idx890" name="idx890"></a><a id="idx891" name="idx891"></a>
|
|
<a href="rbafzmstscale.htm#synchar_len"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq540"></a>
|
|
<div class="fignone" id="wq540">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn68.htm"
|
|
border="0" /></span><a href="#skipsyn-67"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-CHARACTER_LENGTH-+--(--<span class="italic">expression</span>--)----------------------><
|
|
'-CHAR_LENGTH------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-67" id="skipsyn-67"></a></div>
|
|
<a name="synchar_len"></a>
|
|
<p id="synchar_len">The CHARACTER_LENGTH or CHAR_LENGTH function returns the
|
|
length of a string expression. See <a href="rbafzmstscale.htm#scalength">LENGTH</a> for a similar
|
|
function.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
<p>If the
|
|
argument is a UTF-8 or UTF-16 string, the query cannot contain:</p>
|
|
<ul>
|
|
<li>EXCEPT or INTERSECT operations,</li>
|
|
<li>OLAP specifications,</li>
|
|
<li>recursive common table expressions,</li>
|
|
<li>ORDER OF, or</li>
|
|
<li>scalar fullselects (scalar subselects are supported).</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>If <var class="pv">expression</var> is a character string or graphic string, the result
|
|
is the number of characters in the argument (not the number of bytes). A single
|
|
character is either an SBCS, DBCS, or multiple-byte character. If <var class="pv">expression</var> is a binary string, the result is the number of bytes in the argument.
|
|
The length of strings includes trailing blanks or hexadecimal zeroes. The
|
|
length of a varying-length string is the actual length, not the maximum length.</p>
|
|
<a name="wq541"></a>
|
|
<h4 id="wq541">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable ADDRESS is a varying-length character string
|
|
with a value of '895 Don Mills Road'.
|
|
<pre class="xmp"> <span class="bold">SELECT CHARACTER_LENGTH(</span>:ADDRESS<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 18.</li></ul>
|
|
<a name="scaclob"></a>
|
|
<h3 id="scaclob"><a href="rbafzmst02.htm#ToC_377">CLOB</a></h3><a id="idx892" name="idx892"></a><a id="idx893" name="idx893"></a>
|
|
<a name="wq542"></a>
|
|
<div class="fignone" id="wq542">
|
|
<p><span class="bold">Character to CLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn69.htm"
|
|
border="0" /></span><a href="#skipsyn-68"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CLOB (--<span class="italic">character-expression</span>--------------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-68" id="skipsyn-68"></a>
|
|
<p><span class="bold">Graphic to CLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn70.htm"
|
|
border="0" /></span><a href="#skipsyn-69"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CLOB (--<span class="italic">graphic-expression</span>----------------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-69" id="skipsyn-69"></a>
|
|
<p><span class="bold">Integer to CLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn71.htm"
|
|
border="0" /></span><a href="#skipsyn-70"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CLOB--(--<span class="italic">integer-expression</span>--)------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-70" id="skipsyn-70"></a>
|
|
<p><span class="bold">Decimal to CLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn72.htm"
|
|
border="0" /></span><a href="#skipsyn-71"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CLOB--(--<span class="italic">decimal-expression</span>--+----------------------+--)----><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-71" id="skipsyn-71"></a>
|
|
<p><span class="bold">Floating-point to CLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn73.htm"
|
|
border="0" /></span><a href="#skipsyn-72"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CLOB--------------------------------------------------------->
|
|
|
|
>--(--<span class="italic">floating-point-expression</span>--+----------------------+--)---><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-72" id="skipsyn-72"></a></div>
|
|
<p>The CLOB function returns a character-string representation of:</p>
|
|
<ul>
|
|
<li>An integer number if the first argument is a SMALLINT, INTEGER, or BIGINT</li>
|
|
<li>A decimal number if the first argument is a packed or zoned decimal number</li>
|
|
<li>A double-precision floating-point number if the first argument is a DOUBLE
|
|
or REAL</li>
|
|
<li>A character string if the first argument is any type of character string</li>
|
|
<li>A graphic string if the first argument is a UTF-16 or UCS-2 graphic string</li></ul>
|
|
<p>The result of the function is a CLOB. If the first argument can be null,
|
|
the result can be null; if the first argument is null, the result is the null
|
|
value.</p>
|
|
<p><span class="bold">Character to CLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">character-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in character-string
|
|
data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting varying length character string. The value must be between
|
|
1 and 2 147 483 647. If the first argument is mixed data, the second argument
|
|
cannot be less than 4.
|
|
<p>If the second argument is not specified or DEFAULT
|
|
is specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">character-expression</span> is the empty string
|
|
constant, the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length
|
|
attribute of the result and the actual length of <span class="italic">character-expression</span>. If the length of the <span class="italic">character-expression</span> is
|
|
greater than the length attribute of the result, truncation is performed.
|
|
A warning (SQLSTATE 01004) is returned unless the truncated characters were
|
|
all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a valid SBCS CCSID or mixed data CCSID. If the third
|
|
argument is an SBCS CCSID, then the result is SBCS data. If the third argument
|
|
is a mixed CCSID, then the result is mixed data. If the third argument is
|
|
a SBCS CCSID, then the first argument cannot be a DBCS-either or DBCS-only
|
|
string. The third argument cannot be 65535.
|
|
<p>If the third argument is not
|
|
specified, the first argument must not have a CCSID of 65535: </p>
|
|
<ul>
|
|
<li>If the first argument is bit data, an error is returned.</li>
|
|
<li>If the first argument is SBCS data, then the result is SBCS data. The
|
|
CCSID of the result is the same as the CCSID of the first argument.</li>
|
|
<li>If the first argument is mixed data (DBCS-open, DBCS-only, or DBCS-either),
|
|
then the result is mixed data. The CCSID of the result is the same as the
|
|
CCSID of the first argument.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Graphic to CLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">graphic-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in graphic-string
|
|
data type. It must not be DBCS-graphic data.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting varying length character string. The value must be between
|
|
1 and 2 147 483 647. If the result is mixed data, the second argument cannot
|
|
be less than 4.
|
|
<p>If the second argument is not specified or DEFAULT is specified,
|
|
the length attribute of the result is determined as follows (where <span class="italic">n</span> is the length attribute of the first argument): </p>
|
|
<ul>
|
|
<li>If the <var class="pv">graphic-expression</var> is the empty graphic string constant,
|
|
the length attribute of the result is 1.</li>
|
|
<li>If the result is SBCS data, the result length is <span class="italic">n</span>.</li>
|
|
<li>If the result is mixed data, the result length is (2.5*(<span class="italic">n</span>-1)) + 4.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length attribute
|
|
of the result and the actual length of <span class="italic">graphic-expression</span>. If the length of the <span class="italic">graphic-expression</span> is
|
|
greater than the length attribute of the result, truncation is performed.
|
|
A warning (SQLSTATE 01004) is returned unless the truncated characters were
|
|
all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd>An integer constant that specifies the CCSID of the result. It must
|
|
be a valid SBCS CCSID or mixed data CCSID. If the third argument is an SBCS
|
|
CCSID, then the result is SBCS data. If the third argument is a mixed CCSID,
|
|
then the result is mixed data. The third argument cannot be 65535.
|
|
<p>If the
|
|
third argument is not specified, the CCSID of the result is the default CCSID
|
|
at the current server. If the default CCSID is mixed data, then the result
|
|
is mixed data. If the default CCSID is SBCS data, then the result is SBCS
|
|
data.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Integer to CLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">integer-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in integer data type
|
|
(either SMALLINT, INTEGER, or BIGINT).
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length character string of the argument in
|
|
the form of an SQL integer constant. The result consists of n characters that
|
|
are the significant digits that represent the value of the argument with a
|
|
preceding minus sign if the argument is negative. The result is left justified.</p>
|
|
<ul>
|
|
<li>If the argument is a small integer, the length attribute of the result
|
|
is 6.</li>
|
|
<li>If the argument is a large integer, the length attribute of the result
|
|
is 11.</li>
|
|
<li>If the argument is a big integer, the length attribute of the result is
|
|
20.</li></ul>
|
|
<p>The actual length of the result is the smallest number of characters that
|
|
can be used to represent the value of the argument. Leading zeroes are not
|
|
included. If the argument is negative, the first character of the result is
|
|
a minus sign. Otherwise, the first character is a digit.</p>
|
|
<p>The CCSID of the result is the default SBCS CCSID at the current server.</p>
|
|
<p><span class="bold">Decimal to CLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">decimal-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in decimal data type
|
|
(either DECIMAL or NUMERIC). If a different precision and scale is desired,
|
|
the DECIMAL scalar function can be used to make the change.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length character string representation of
|
|
the argument. The result includes a decimal character and up to <var class="pv">p</var>
|
|
digits, where <var class="pv">p</var> is the precision of the <var class="pv">decimal-expression</var> with
|
|
a preceding minus sign if the argument is negative. Leading zeros are not
|
|
returned. Trailing zeros are returned.</p>
|
|
<p>The length attribute of the result is 2+<var class="pv">p</var> where <var class="pv">p</var> is
|
|
the precision of the <var class="pv">decimal-expression</var>. The actual length of the
|
|
result is the smallest number of characters that can be used to represent
|
|
the result, except that trailing characters are included. Leading zeros are
|
|
not included. If the argument is negative, the result begins with a minus
|
|
sign. Otherwise, the result begins with a digit.</p>
|
|
<p> The CCSID of the result is the default SBCS CCSID at the current server.</p>
|
|
<p><span class="bold">Floating-point to CLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">floating-point expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in floating-point
|
|
data type (DOUBLE or REAL).
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length character string representation of
|
|
the argument in the form of a floating-point constant.</p>
|
|
<p>The length attribute of the result is 24. The actual length of the result
|
|
is the smallest number of characters that can represent the value of the argument
|
|
such that the mantissa consists of a single digit other than zero followed
|
|
by the <var class="pv">decimal-character</var> and a sequence of digits. If the argument
|
|
is negative, the first character of the result is a minus sign; otherwise,
|
|
the first character is a digit. If the argument is zero, the result is 0E0.</p>
|
|
<p>The CCSID of the result is the default SBCS CCSID at the current server.</p>
|
|
<a name="wq543"></a>
|
|
<h4 id="wq543">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the first argument is numeric,
|
|
or the first argument is a string and the length argument is specified, the
|
|
CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq544"></a>
|
|
<h4 id="wq544">Example</h4>
|
|
<ul>
|
|
<li>The following function returns a CLOB for the string 'This is a CLOB'.
|
|
<pre class="xmp"> <span class="bold">SELECT CLOB(</span>'This is a CLOB'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scacoales"></a>
|
|
<h3 id="scacoales"><a href="rbafzmst02.htm#ToC_380">COALESCE</a></h3><a id="idx894" name="idx894"></a><a id="idx895" name="idx895"></a>
|
|
<a href="rbafzmstscale.htm#syncoalesce"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq545"></a>
|
|
<div class="fignone" id="wq545">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn74.htm"
|
|
border="0" /></span><a href="#skipsyn-73"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-COALESCE--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)---------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-73" id="skipsyn-73"></a></div>
|
|
<a name="syncoalesce"></a>
|
|
<p id="syncoalesce">The COALESCE function returns the value of the first non-null
|
|
expression.</p>
|
|
<p>The arguments must be compatible. Character-string arguments are compatible
|
|
with datetime values. For more information about data type compatibility,
|
|
see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments can be of either a built-in data type or a distinct type.<sup class="fn"><a id="wq546" name="wq546" href="rbafzmstscale.htm#wq547">41</a></sup>
|
|
</dd>
|
|
</dl>
|
|
<p>The arguments are evaluated in the order in which they are specified, and
|
|
the result of the function is the first argument that is not null. The result
|
|
can be null only if all arguments can be null, and the result is null only
|
|
if all arguments are null.</p>
|
|
<p>The selected argument is converted, if necessary, to the attributes of
|
|
the result. The attributes of the result are determined by all the operands
|
|
as explained in <a href="rbafzmstopcomb.htm#opcomb">Rules for result data types</a>.</p>
|
|
<a name="wq548"></a>
|
|
<h4 id="wq548">Examples</h4>
|
|
<ul>
|
|
<li>When selecting all the values from all the rows in the DEPARTMENT table,
|
|
if the department manager (MGRNO) is missing (that is, null), then return
|
|
a value of 'ABSENT'.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> DEPTNO, DEPTNAME, <span class="bold">COALESCE</span>(MGRNO, 'ABSENT'), ADMRDEPT
|
|
<span class="bold">FROM</span> DEPARTMENT</pre></li>
|
|
<li>When selecting the employee number (EMPNO) and salary (SALARY) from all
|
|
the rows in the EMPLOYEE table, if the salary is missing (that is null), then
|
|
return a value of zero.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">COALESCE</span>(SALARY,0)
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scaconcat"></a>
|
|
<h3 id="scaconcat"><a href="rbafzmst02.htm#ToC_382">CONCAT</a></h3><a id="idx896" name="idx896"></a><a id="idx897" name="idx897"></a>
|
|
<a href="rbafzmstscale.htm#synconcat"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq549"></a>
|
|
<div class="fignone" id="wq549">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn75.htm"
|
|
border="0" /></span><a href="#skipsyn-74"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CONCAT--(--<span class="italic">expression</span>--,--<span class="italic">expression</span>--)---------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-74" id="skipsyn-74"></a></div>
|
|
<a name="synconcat"></a>
|
|
<p id="synconcat">The CONCAT function combines two arguments.</p>
|
|
<p>The arguments must be compatible. Character-string arguments are not compatible
|
|
with datetime values. For more information about data type compatibility,
|
|
see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a string that consists of the
|
|
first argument string followed by the second. The data type of the result
|
|
is determined by the data types of the arguments. For more information, see <a href="rbafzmstch2expr.htm#wtco">With the concatenation operator</a>. If either argument can be null, the result can
|
|
be null; if either argument is null, the result is the null value.</p>
|
|
<a name="wq550"></a>
|
|
<h4 id="wq550">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CONCAT function is identical
|
|
to the CONCAT operator. For more information, see <a href="rbafzmstch2expr.htm#wtco">With the concatenation operator</a>.</p>
|
|
<a name="wq551"></a>
|
|
<h4 id="wq551">Example</h4>
|
|
<ul>
|
|
<li>Concatenate the column FIRSTNME with the column LASTNAME.
|
|
<pre class="xmp"> <span class="bold">SELECT CONCAT</span>(FIRSTNME, LASTNAME)
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO ='000010'</pre>Returns
|
|
the value 'CHRISTINEHAAS'.</li></ul>
|
|
<a name="scacos"></a>
|
|
<h3 id="scacos"><a href="rbafzmst02.htm#ToC_385">COS</a></h3><a id="idx898" name="idx898"></a><a id="idx899" name="idx899"></a>
|
|
<a href="rbafzmstscale.htm#syncos"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq552"></a>
|
|
<div class="fignone" id="wq552">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn76.htm"
|
|
border="0" /></span><a href="#skipsyn-75"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-COS--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-75" id="skipsyn-75"></a></div>
|
|
<a name="syncos"></a>
|
|
<p id="syncos">The COS function returns the cosine of the argument, where
|
|
the argument is an angle expressed in radians. The COS and ACOS functions
|
|
are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq553"></a>
|
|
<h4 id="wq553">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable COSINE is a DECIMAL(2,1) host variable with a
|
|
value of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT COS</span>(:COSINE)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 0.07.</li></ul>
|
|
<a name="scacosh"></a>
|
|
<h3 id="scacosh"><a href="rbafzmst02.htm#ToC_387">COSH</a></h3><a id="idx900" name="idx900"></a><a id="idx901" name="idx901"></a>
|
|
<a href="rbafzmstscale.htm#syncosh"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq554"></a>
|
|
<div class="fignone" id="wq554">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn77.htm"
|
|
border="0" /></span><a href="#skipsyn-76"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-COSH--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-76" id="skipsyn-76"></a></div>
|
|
<a name="syncosh"></a>
|
|
<p id="syncosh">The COSH function returns the hyperbolic cosine of the argument,
|
|
where the argument is an angle expressed in radians.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq555"></a>
|
|
<h4 id="wq555">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HCOS is a DECIMAL(2,1) host variable with a value
|
|
of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT COSH</span>(:HCOS)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 2.35.</li></ul>
|
|
<a name="scacot"></a>
|
|
<h3 id="scacot"><a href="rbafzmst02.htm#ToC_389">COT</a></h3><a id="idx902" name="idx902"></a><a id="idx903" name="idx903"></a>
|
|
<a href="rbafzmstscale.htm#syncot"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq556"></a>
|
|
<div class="fignone" id="wq556">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn78.htm"
|
|
border="0" /></span><a href="#skipsyn-77"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-COT--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-77" id="skipsyn-77"></a></div>
|
|
<a name="syncot"></a>
|
|
<p id="syncot">The COT function returns the cotangent of the argument, where
|
|
the argument is an angle expressed in radians.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq557"></a>
|
|
<h4 id="wq557">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable COTAN is a DECIMAL(2,1) host variable with a
|
|
value of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT COT</span>(:COTAN)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 0.07.</li></ul>
|
|
<a name="scacurdate"></a>
|
|
<h3 id="scacurdate"><a href="rbafzmst02.htm#ToC_391">CURDATE</a></h3><a id="idx904" name="idx904"></a><a id="idx905" name="idx905"></a>
|
|
<a href="rbafzmstscale.htm#syncurdate"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq558"></a>
|
|
<div class="fignone" id="wq558">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn79.htm"
|
|
border="0" /></span><a href="#skipsyn-78"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CURDATE--(--)-----------------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-78" id="skipsyn-78"></a></div>
|
|
<a name="syncurdate"></a>
|
|
<p id="syncurdate">The CURDATE function returns a date based on a reading
|
|
of the time-of-day clock when the SQL statement is executed at the current
|
|
server. The value returned by the CURDATE function is the same as the value
|
|
returned by the CURRENT DATE special register.</p>
|
|
<p>The data type of the result is a date. The result cannot be null.</p>
|
|
<p>If this function is used more than once within a single SQL statement,
|
|
or used with the CURTIME or NOW scalar functions or the CURRENT_DATE, CURRENT_TIME,
|
|
or CURRENT_TIMESTAMP special registers within a single statement, all values
|
|
are based on a single clock reading.</p>
|
|
<a name="wq559"></a>
|
|
<h4 id="wq559">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CURRENT_DATE special register
|
|
should be used for maximal portability. For more information, see <a href="rbafzmstspecreg.htm#specreg">Special registers</a>.</p>
|
|
<a name="wq560"></a>
|
|
<h4 id="wq560">Example</h4>
|
|
<ul>
|
|
<li>Return the current date based on the time-of-day clock.
|
|
<pre class="xmp"> <span class="bold">SELECT CURDATE</span>()
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scacurtime"></a>
|
|
<h3 id="scacurtime"><a href="rbafzmst02.htm#ToC_394">CURTIME</a></h3><a id="idx906" name="idx906"></a><a id="idx907" name="idx907"></a>
|
|
<a href="rbafzmstscale.htm#syncurtime"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq561"></a>
|
|
<div class="fignone" id="wq561">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn80.htm"
|
|
border="0" /></span><a href="#skipsyn-79"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CURTIME--(--)-----------------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-79" id="skipsyn-79"></a></div>
|
|
<a name="syncurtime"></a>
|
|
<p id="syncurtime">The CURTIME function returns a time based on a reading
|
|
of the time-of-day clock when the SQL statement is executed at the current
|
|
server. The value returned by the CURTIME function is the same as the value
|
|
returned by the CURRENT TIME special register.</p>
|
|
<p>The data type of the result is a time. The result cannot be null.</p>
|
|
<p>If this function is used more than once within a single SQL statement,
|
|
or used with the CURDATE or NOW scalar functions or the CURRENT_DATE, CURRENT_TIME,
|
|
or CURRENT_TIMESTAMP special registers within a single statement, all values
|
|
are based on a single clock reading.</p>
|
|
<a name="wq562"></a>
|
|
<h4 id="wq562">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CURRENT_TIME special register
|
|
should be used for maximal portability. For more information, see <a href="rbafzmstspecreg.htm#specreg">Special registers</a>.</p>
|
|
<a name="wq563"></a>
|
|
<h4 id="wq563">Example</h4>
|
|
<ul>
|
|
<li>Return the current time based on the time-of-day clock.
|
|
<pre class="xmp"> <span class="bold">SELECT CURTIME</span>()
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scadatabase"></a>
|
|
<h3 id="scadatabase"><a href="rbafzmst02.htm#ToC_397">DATABASE</a></h3><a id="idx908" name="idx908"></a><a id="idx909" name="idx909"></a>
|
|
<a href="rbafzmstscale.htm#syndatabase"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq564"></a>
|
|
<div class="fignone" id="wq564">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn81.htm"
|
|
border="0" /></span><a href="#skipsyn-80"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DATABASE--(--)----------------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-80" id="skipsyn-80"></a></div>
|
|
<a name="syndatabase"></a>
|
|
<p id="syndatabase">The DATABASE function returns the current server.</p>
|
|
<p>The result of the function is a VARCHAR(18). The result cannot be null.</p>
|
|
<p>The CCSID of the string is the default SBCS CCSID at the current server.</p>
|
|
<a name="wq565"></a>
|
|
<h4 id="wq565">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The DATABASE function returns
|
|
the same result as the CURRENT SERVER special register.</p>
|
|
<a name="wq566"></a>
|
|
<h4 id="wq566">Examples</h4>
|
|
<ul>
|
|
<li>Assume that the current server is 'RCHASGMA'.
|
|
<pre class="xmp"> <span class="bold">SELECT DATABASE( )</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results
|
|
in a value of 'RCHASGMA'.</li></ul>
|
|
<a name="scadataname"></a>
|
|
<h3 id="scadataname"><a href="rbafzmst02.htm#ToC_400">DATAPARTITIONNAME</a></h3><a id="idx910" name="idx910"></a><a id="idx911" name="idx911"></a>
|
|
<a href="rbafzmstscale.htm#syndatapname"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq567"></a>
|
|
<div class="fignone" id="wq567">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn82.htm"
|
|
border="0" /></span><a href="#skipsyn-81"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DATAPARTITIONNAME--(--<span class="italic">table-designator</span>--)-------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-81" id="skipsyn-81"></a></div>
|
|
<a name="syndatapname"></a>
|
|
<p id="syndatapname">The DATAPARTITIONNAME function returns the
|
|
partition name of where a row is located. If the argument identifies a non-partitioned
|
|
table, an empty string is returned. For more information about partitions,
|
|
see the <a href="../dbmult/rzaf3kickoff.htm">DB2 Multisystem</a> book.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">table-designator</var></dt>
|
|
<dd>The argument must be a table designator of the subselect. For more information
|
|
about table designators, see <a href="rbafzmstch2col.htm#tdjm">Table designators</a>.
|
|
<p>In SQL naming,
|
|
the table name may be qualified. In system naming, the table name cannot
|
|
be qualified.</p>
|
|
<p>If the argument identifies a view, common table expression,
|
|
or derived table, the function returns the relational database name of its
|
|
base table. If the argument identifies a view, common table expression, or
|
|
derived table derived from more than one base table, the function returns
|
|
the relational database name of the first table in the outer subselect of
|
|
the view, common table expression, or derived table.</p>
|
|
<p>The
|
|
argument must not identify a view, common table expression, or derived table
|
|
whose outer subselect includes an aggregate function, a GROUP BY clause, a
|
|
HAVING clause, a UNION clause, an INTERSECT clause, or DISTINCT clause. If
|
|
the subselect contains a GROUP BY or HAVING clause, the DATAPARTITIONNAME
|
|
function can only be specified in the WHERE clause or as an operand of an
|
|
aggregate function. If the argument is a correlation name, the correlation
|
|
name must not identify a correlated reference.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is VARCHAR(18). The result can be null.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current server.</p>
|
|
<a name="wq568"></a>
|
|
<h4 id="wq568">Example</h4>
|
|
<ul>
|
|
<li>Join the EMPLOYEE and DEPARTMENT tables, select the employee number (EMPNO)
|
|
and determine the partition from which each row involved in the join originated.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">DATAPARTITIONNAME(</span>X<span class="bold">)</span>, <span class="bold">DATAPARTITIONNAME(</span>Y<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE X, DEPARTMENT Y
|
|
<span class="bold">WHERE</span> X.DEPTNO=Y.DEPTNO</pre></li></ul>
|
|
<a name="scadatanumb"></a>
|
|
<h3 id="scadatanumb"><a href="rbafzmst02.htm#ToC_402">DATAPARTITIONNUM</a></h3><a id="idx912" name="idx912"></a><a id="idx913" name="idx913"></a>
|
|
<a href="rbafzmstscale.htm#syndatapnum"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq569"></a>
|
|
<div class="fignone" id="wq569">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn83.htm"
|
|
border="0" /></span><a href="#skipsyn-82"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DATAPARTITIONNUM--(--<span class="italic">table-designator</span>--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-82" id="skipsyn-82"></a></div>
|
|
<a name="syndatapnum"></a>
|
|
<p id="syndatapnum">The DATAPARTITIONNUM function returns the data partition
|
|
number of a row. If the argument identifies a non-partitioned table, the value
|
|
0 is returned. For more information about data partitions, see the <a href="../dbmult/rzaf3kickoff.htm">DB2 Multisystem</a> book.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">table-designator</var></dt>
|
|
<dd>The argument must be a table designator of the subselect. For more information
|
|
about table designators, see <a href="rbafzmstch2col.htm#tdjm">Table designators</a>.
|
|
<p>In SQL naming,
|
|
the table name may be qualified. In system naming, the table name cannot
|
|
be qualified.</p>
|
|
<p>If the argument identifies a view, common table expression,
|
|
or derived table, the function returns the data partition number of its base
|
|
table. If the argument identifies a view, common table expression, or derived
|
|
table derived from more than one base table, the function returns the data
|
|
partition number of the first table in the outer subselect of the view, common
|
|
table expression, or derived table.</p>
|
|
<p>The argument must not
|
|
identify a view, common table expression, or derived table whose outer subselect
|
|
includes an aggregate function, a GROUP BY clause, a HAVING clause, a UNION
|
|
clause, an INTERSECT clause, or DISTINCT clause. If the subselect contains
|
|
a GROUP BY or HAVING clause, the DATAPARTITIONNUM function can only be specified
|
|
in the WHERE clause or as an operand of an aggregate function. If the argument
|
|
is a correlation name, the correlation name must not identify a correlated
|
|
reference.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is a large integer. The result can be null.</p>
|
|
<a name="wq570"></a>
|
|
<h4 id="wq570">Example</h4>
|
|
<ul>
|
|
<li>Determine the partition number and employee name for each row in the EMPLOYEE
|
|
table. If this is a partitioned table, the number of the partition where
|
|
the row exists is returned.
|
|
<pre class="xmp"> <span class="bold">SELECT DATAPARTITIONNUM(</span>EMPLOYEE<span class="bold">)</span>, LASTNAME
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scadate"></a>
|
|
<h3 id="scadate"><a href="rbafzmst02.htm#ToC_404">DATE</a></h3><a id="idx914" name="idx914"></a><a id="idx915" name="idx915"></a>
|
|
<a href="rbafzmstscale.htm#syndate"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq571"></a>
|
|
<div class="fignone" id="wq571">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn84.htm"
|
|
border="0" /></span><a href="#skipsyn-83"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DATE--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-83" id="skipsyn-83"></a></div>
|
|
<a name="syndate"></a>
|
|
<p id="syndate">The DATE function returns a date from a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, a
|
|
graphic string, or any numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be one of the following:
|
|
<ul>
|
|
<li>A valid string representation of a date or timestamp. For the valid formats
|
|
of string representations of dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>A string with an actual length of 7 that represents a valid date in the
|
|
form <var class="pv">yyyynnn</var>, where <var class="pv">yyyy</var> are digits denoting a year, and <var class="pv">nnn</var> are digits between 001 and 366 denoting a day of that year.</li></ul></li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a positive number less
|
|
than or equal to 3652059.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a date. If the argument can be null, the
|
|
result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a timestamp:
|
|
<p>The result is the date part of the
|
|
timestamp.</p></li>
|
|
<li>If the argument is a date:
|
|
<p>The result is that date.</p></li>
|
|
<li>If the argument is a number:
|
|
<p>The result is the date that is <var class="pv">n</var>-1
|
|
days after January 1, 0001, where <var class="pv">n</var> is the integral part of the number.</p></li>
|
|
<li>If the argument is a character or graphic string:
|
|
<p>The result is the
|
|
date represented by the string or the date part of the timestamp value represented
|
|
by the string.</p>
|
|
<p>When a string representation of a date is SBCS data with
|
|
a CCSID that is not the same as the default CCSID for SBCS data, that value
|
|
is converted to adhere to the default CCSID for SBCS data before it is interpreted
|
|
and converted to a date value.</p>
|
|
<p>When a string representation of a date
|
|
is mixed data with a CCSID that is not the same as the default CCSID for mixed
|
|
data, that value is converted to adhere to the default CCSID for mixed data
|
|
before it is interpreted and converted to a date value.</p>
|
|
<p>When a string
|
|
representation of a date is graphic data, that value is converted to adhere
|
|
to the default CCSID for SBCS data before it is interpreted and converted
|
|
to a date value.</p></li></ul>
|
|
<a name="wq572"></a>
|
|
<h4 id="wq572">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the argument is a date,
|
|
timestamp, or character string, the CAST specification should be used for
|
|
maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq573"></a>
|
|
<h4 id="wq573">Examples</h4>
|
|
<ul>
|
|
<li>Assume that the column RECEIVED (TIMESTAMP) has an internal value equivalent
|
|
to '1988-12-25-17.12.30.000000'.
|
|
<pre class="xmp"> <span class="bold">SELECT DATE(</span>RECEIVED<span class="bold">)</span>
|
|
<span class="bold">FROM</span> IN_TRAY
|
|
<span class="bold">WHERE</span> SOURCE = 'BADAMSON'</pre>
|
|
<p>Results
|
|
in a date data type with a value of '1988-12-25'.</p></li>
|
|
<li>The following DATE scalar function applied to an ISO string representation
|
|
of a date:
|
|
<pre class="xmp"> <span class="bold">SELECT DATE(</span>'1988-12-25'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Results in a date data type with a value of '1988-12-25'.</p></li>
|
|
<li>The following DATE scalar function applied to an EUR string representation
|
|
of a date:
|
|
<pre class="xmp"> <span class="bold">SELECT DATE(</span>'25.12.1988'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Results in a date data type with a value of '1988-12-25'.</p></li>
|
|
<li>The following DATE scalar function applied to a positive number:
|
|
<pre class="xmp"> <span class="bold">SELECT DATE(</span>35<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Results in a date data type with a value of '0001-02-04'.</p></li></ul>
|
|
<a name="dayfunc"></a>
|
|
<h3 id="dayfunc"><a href="rbafzmst02.htm#ToC_407">DAY</a></h3><a id="idx916" name="idx916"></a><a id="idx917" name="idx917"></a>
|
|
<a href="rbafzmstscale.htm#synday"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq574"></a>
|
|
<div class="fignone" id="wq574">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn85.htm"
|
|
border="0" /></span><a href="#skipsyn-84"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAY--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-84" id="skipsyn-84"></a></div>
|
|
<a name="synday"></a>
|
|
<p id="synday">The DAY function returns the day part of a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, a
|
|
graphic string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
date or timestamp. For the valid formats of string representations of dates
|
|
and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a date duration or timestamp
|
|
duration. For the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a date, timestamp, or valid character-string representation
|
|
of a date or timestamp:
|
|
<p>The result is the day part of the value, which is
|
|
an integer between 1 and 31.</p></li>
|
|
<li>If the argument is a date duration or timestamp duration:
|
|
<p>The result
|
|
is the day part of the value, which is an integer between -99 and 99.
|
|
A nonzero result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq575"></a>
|
|
<h4 id="wq575">Examples</h4>
|
|
<ul>
|
|
<li>Using the PROJECT table, set the host variable END_DAY (SMALLINT) to
|
|
the day that the WELD LINE PLANNING project (PROJNAME) is scheduled to stop
|
|
(PRENDATE).
|
|
<pre class="xmp"><span class="bold">SELECT DAY(</span>PRENDATE<span class="bold">)
|
|
INTO</span> :END_DAY
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNAME = 'WELD LINE PLANNING'</pre>Results
|
|
in END_DAY being set to 15.</li>
|
|
<li>Return the day part of the difference between two dates:
|
|
<pre class="xmp"> <span class="bold">SELECT DAY( DATE(</span>'2000-03-15'<span class="bold">)</span> - <span class="bold">DATE(</span>'1999-12-31'<span class="bold">) )</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Results
|
|
in the value 15.</li></ul>
|
|
<a name="scadayname"></a>
|
|
<h3 id="scadayname"><a href="rbafzmst02.htm#ToC_409">DAYNAME</a></h3><a id="idx918" name="idx918"></a><a id="idx919" name="idx919"></a>
|
|
<a href="rbafzmstscale.htm#syndayname"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq576"></a>
|
|
<div class="fignone" id="wq576">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn86.htm"
|
|
border="0" /></span><a href="#skipsyn-85"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAYNAME--(--<span class="italic">expression</span>--)-----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-85" id="skipsyn-85"></a></div>
|
|
<a name="syndayname"></a>
|
|
<p id="syndayname">Returns a mixed case character string containing the name
|
|
of the day (e.g. Friday) for the day portion of the argument.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is VARCHAR(100). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current server.</p>
|
|
<a name="wq577"></a>
|
|
<h4 id="wq577">Note</h4>
|
|
<p><span class="bold">National language considerations:</span> The name of the
|
|
day that is returned is based on the language used for messages in the job.
|
|
This name of the day is retrieved from message CPX9034 in message file QCPFMSG
|
|
in library *LIBL.</p>
|
|
<a name="wq578"></a>
|
|
<h4 id="wq578">Examples</h4>
|
|
<ul>
|
|
<li>Assume that the language used is US English.
|
|
<pre class="xmp"><span class="bold">SELECT DAYNAME(</span> '2003-01-02' <span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results in 'Thursday'.</li></ul>
|
|
<a name="scadofmonth"></a>
|
|
<h3 id="scadofmonth"><a href="rbafzmst02.htm#ToC_412">DAYOFMONTH</a></h3><a id="idx920" name="idx920"></a><a id="idx921" name="idx921"></a>
|
|
<a href="rbafzmstscale.htm#syndayofmonth"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq579"></a>
|
|
<div class="fignone" id="wq579">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn87.htm"
|
|
border="0" /></span><a href="#skipsyn-86"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAYOFMONTH--(--<span class="italic">expression</span>--)--------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-86" id="skipsyn-86"></a></div>
|
|
<a name="syndayofmonth"></a>
|
|
<p id="syndayofmonth">The DAYOFMONTH function returns an integer between 1
|
|
and 31 that represents the day of the month.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq580"></a>
|
|
<h4 id="wq580">Examples</h4>
|
|
<ul>
|
|
<li>Using the PROJECT table, set the host variable END_DAY (SMALLINT) to
|
|
the day that the WELD LINE PLANNING project (PROJNAME) is scheduled to stop
|
|
(PRENDATE).
|
|
<pre class="xmp"><span class="bold">SELECT DAYOFMONTH(</span>PRENDATE<span class="bold">)
|
|
INTO</span> :END_DAY
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNAME = 'WELD LINE PLANNING'</pre>Results
|
|
in END_DAY being set to 15.</li></ul>
|
|
<a name="scadofweek"></a>
|
|
<h3 id="scadofweek"><a href="rbafzmst02.htm#ToC_414">DAYOFWEEK</a></h3><a id="idx922" name="idx922"></a><a id="idx923" name="idx923"></a>
|
|
<a href="rbafzmstscale.htm#syndayofweek"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq581"></a>
|
|
<div class="fignone" id="wq581">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn88.htm"
|
|
border="0" /></span><a href="#skipsyn-87"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAYOFWEEK--(--<span class="italic">expression</span>--)---------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-87" id="skipsyn-87"></a></div>
|
|
<a name="syndayofweek"></a>
|
|
<p id="syndayofweek">The DAYOFWEEK function returns an integer between 1 and
|
|
7 that represents the day of the week, where 1 is Sunday and 7 is Saturday.
|
|
For another alternative, see <a href="rbafzmstscale.htm#scaisodweek">DAYOFWEEK_ISO</a>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq582"></a>
|
|
<h4 id="wq582">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, set the host variable DAY_OF_WEEK (INTEGER)
|
|
to the day of the week that Christine Haas (EMPNO='000010') started
|
|
(HIREDATE).
|
|
<pre class="xmp"> <span class="bold">SELECT DAYOFWEEK(</span>HIREDATE<span class="bold">)
|
|
INTO</span> :DAY_OF_WEEK
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO = '000010'</pre>Results in DAY_OF_WEEK
|
|
being set to 6, which represents Friday.</li>
|
|
<li>The following query returns four values: 1, 2, 1, and 2.
|
|
<pre class="xmp"> <span class="bold">SELECT DAYOFWEEK(CAST(</span>'10/11/1998' <span class="bold">AS DATE))</span>,
|
|
<span class="bold">DAYOFWEEK(TIMESTAMP(</span>'10/12/1998','01.02'<span class="bold">))</span>,
|
|
<span class="bold">DAYOFWEEK(CAST(CAST(</span>'10/11/1998' <span class="bold">AS DATE)) AS CHAR(</span>20<span class="bold">)))</span>,
|
|
<span class="bold">DAYOFWEEK(CAST(TIMESTAMP(</span>'10/12/1998','01.02'<span class="bold">) AS CHAR(</span>20<span class="bold">)))</span>,
|
|
<span class="bold">FROM</span> <span>SYSIBM.SYSDUMMY1</span> </pre></li></ul>
|
|
<a name="scaisodweek"></a>
|
|
<h3 id="scaisodweek"><a href="rbafzmst02.htm#ToC_416">DAYOFWEEK_ISO</a></h3><a id="idx924" name="idx924"></a><a id="idx925" name="idx925"></a>
|
|
<a href="rbafzmstscale.htm#syndayofweek_iso"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq583"></a>
|
|
<div class="fignone" id="wq583">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn89.htm"
|
|
border="0" /></span><a href="#skipsyn-88"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAYOFWEEK_ISO--(--<span class="italic">expression</span>--)-----------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-88" id="skipsyn-88"></a></div>
|
|
<a name="syndayofweek_iso"></a>
|
|
<p id="syndayofweek_iso">The DAYOFWEEK_ISO function returns an integer between
|
|
1 and 7 that represents the day of the week, where 1 is Monday and 7 is Sunday.
|
|
For another alternative, see <a href="rbafzmstscale.htm#scadofweek">DAYOFWEEK</a>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq584"></a>
|
|
<h4 id="wq584">Examples</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, set the host variable DAY_OF_WEEK (INTEGER)
|
|
to the day of the week that Christine Haas (EMPNO='000010') started
|
|
(HIREDATE).
|
|
<pre class="xmp"> <span class="bold">SELECT DAYOFWEEK_ISO(</span>HIREDATE<span class="bold">)
|
|
INTO</span> :DAY_OF_WEEK
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO = '000010'</pre>Results in DAY_OF_WEEK
|
|
being set to 5, which represents Friday.</li>
|
|
<li>The following query returns four values: 7, 1, 7, and 1.
|
|
<pre class="xmp"> <span class="bold">SELECT DAYOFWEEK_ISO(CAST(</span>'10/11/1998' <span class="bold">AS DATE))</span>,
|
|
<span class="bold">DAYOFWEEK_ISO(TIMESTAMP(</span>'10/12/1998','01.02'<span class="bold">))</span>,
|
|
<span class="bold">DAYOFWEEK_ISO(CAST(CAST(</span>'10/11/1998' <span class="bold">AS DATE)) AS CHAR(</span>20<span class="bold">)))</span>,
|
|
<span class="bold">DAYOFWEEK_ISO(CAST(TIMESTAMP(</span>'10/12/1998','01.02'<span class="bold">) AS CHAR(</span>20<span class="bold">)))</span>,
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scadofyear"></a>
|
|
<h3 id="scadofyear"><a href="rbafzmst02.htm#ToC_418">DAYOFYEAR</a></h3><a id="idx926" name="idx926"></a><a id="idx927" name="idx927"></a>
|
|
<a href="rbafzmstscale.htm#syndayofyear"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq585"></a>
|
|
<div class="fignone" id="wq585">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn90.htm"
|
|
border="0" /></span><a href="#skipsyn-89"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAYOFYEAR--(--<span class="italic">expression</span>--)---------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-89" id="skipsyn-89"></a></div>
|
|
<a name="syndayofyear"></a>
|
|
<p id="syndayofyear">The DAYOFYEAR function returns an integer between 1 and
|
|
366 that represents the day of the year where 1 is January 1.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq586"></a>
|
|
<h4 id="wq586">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, set the host variable AVG_DAY_OF_YEAR
|
|
(INTEGER) to the average of the day of the year that employees started on
|
|
(HIREDATE).
|
|
<pre class="xmp"> <span class="bold">SELECT AVG(DAYOFYEAR(</span>HIREDATE<span class="bold">))
|
|
INTO</span> :AVG_DAY_OF_YEAR
|
|
<span class="bold">FROM</span> EMPLOYEE</pre>Results in AVG_DAY_OF_YEAR
|
|
being set to 197.</li></ul>
|
|
<a name="scadays"></a>
|
|
<h3 id="scadays"><a href="rbafzmst02.htm#ToC_420">DAYS</a></h3><a id="idx928" name="idx928"></a><a id="idx929" name="idx929"></a>
|
|
<a href="rbafzmstscale.htm#syndays"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq587"></a>
|
|
<div class="fignone" id="wq587">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn91.htm"
|
|
border="0" /></span><a href="#skipsyn-90"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DAYS--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-90" id="skipsyn-90"></a></div>
|
|
<a name="syndays"></a>
|
|
<p id="syndays">The DAYS function returns an integer representation of a date.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The result is 1 more than the number of days from January 1, 0001 to <var class="pv">D</var>, where <var class="pv">D</var> is the date that would occur if the DATE function
|
|
were applied to the argument.</p>
|
|
<a name="wq588"></a>
|
|
<h4 id="wq588">Examples</h4>
|
|
<ul>
|
|
<li>Using the PROJECT table, set the host variable EDUCATION_DAYS (INTEGER)
|
|
to the number of elapsed days (PRENDATE - PRSTDATE) estimated for the project
|
|
(PROJNO) 'IF2000'.
|
|
<pre class="xmp"> <span class="bold">SELECT DAYS(</span>PRENDATE<span class="bold">) - DAYS(</span>PRSTDATE<span class="bold">)
|
|
INTO</span> :EDUCATION_DAYS
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNO = 'IF2000'</pre> Results
|
|
in EDUCATION_DAYS being set to 396.</li>
|
|
<li>Using the PROJECT table, set the host variable TOTAL_DAYS
|
|
(INTEGER) to the sum of elapsed days (PRENDATE - PRSTDATE) estimated for all
|
|
projects in department (DEPTNO) 'E21'.
|
|
<pre class="xmp"><span class="bold">SELECT SUM(DAYS(</span>PRENDATE<span class="bold">) - DAYS(</span>PRSTDATE<span class="bold">))
|
|
INTO</span> :TOTAL_DAYS
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> DEPTNO = 'E21'</pre>Results in TOTAL_DAYS
|
|
being set to 1584.</li></ul>
|
|
<a name="scadbclob"></a>
|
|
<h3 id="scadbclob"><a href="rbafzmst02.htm#ToC_422">DBCLOB</a></h3><a id="idx930" name="idx930"></a><a id="idx931" name="idx931"></a>
|
|
<a href="rbafzmstscale.htm#syndbclob"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq589"></a>
|
|
<div class="fignone" id="wq589">
|
|
<p><span class="bold">Character to DBCLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn92.htm"
|
|
border="0" /></span><a href="#skipsyn-91"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBCLOB (--<span class="italic">character-expression</span>------------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-91" id="skipsyn-91"></a>
|
|
<p><span class="bold">Graphic to DBCLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn93.htm"
|
|
border="0" /></span><a href="#skipsyn-92"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBCLOB (--<span class="italic">graphic-expression</span>--------------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-92" id="skipsyn-92"></a>
|
|
<p><span class="bold">Integer to DBCLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn94.htm"
|
|
border="0" /></span><a href="#skipsyn-93"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBCLOB--(--<span class="italic">integer-expression</span>--)----------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-93" id="skipsyn-93"></a>
|
|
<p><span class="bold">Decimal to DBCLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn95.htm"
|
|
border="0" /></span><a href="#skipsyn-94"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBCLOB--(--<span class="italic">decimal-expression</span>--+----------------------+--)--><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-94" id="skipsyn-94"></a>
|
|
<p><span class="bold">Floating-point to DBCLOB</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn96.htm"
|
|
border="0" /></span><a href="#skipsyn-95"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBCLOB------------------------------------------------------->
|
|
|
|
>--(--<span class="italic">floating-point-expression</span>--+----------------------+--)---><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-95" id="skipsyn-95"></a></div>
|
|
<a name="syndbclob"></a>
|
|
<p id="syndbclob">The DBCLOB function returns a graphic-string representation
|
|
of:</p>
|
|
<ul>
|
|
<li>An integer number if the first argument is a SMALLINT, INTEGER, or BIGINT</li>
|
|
<li>A decimal number if the first argument is a packed or zoned decimal number</li>
|
|
<li>A double-precision floating-point number if the first argument is a DOUBLE
|
|
or REAL</li>
|
|
<li>A character string if the first argument is any type of character string</li>
|
|
<li>A graphic string if the first argument is any type of graphic string</li></ul>
|
|
<p>The result of the function is a DBCLOB. If the first argument can be null,
|
|
the result can be null; if the first argument is null, the result is the null
|
|
value.</p>
|
|
<p><span class="bold">Character to DBCLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">character-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in character-string
|
|
data type. It cannot be CHAR or VARCHAR bit data. If the expression is an
|
|
empty string or the EBCDIC string <tt class="xph">X'0E0F'</tt>, the result is an empty
|
|
string.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting varying length character string. The value must be between
|
|
1 and 1 073 741 823.
|
|
<p>If the second argument is not specified or DEFAULT
|
|
is specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">character-expression</span> is the empty string
|
|
constant, the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length
|
|
attribute of the result and the actual length of <span class="italic">character-expression</span>. If the length of the <span class="italic">character-expression</span> is
|
|
greater than the length attribute of the result, truncation is performed.
|
|
A warning (SQLSTATE 01004) is returned unless the truncated characters were
|
|
all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID for
|
|
the resulting varying-length graphic string. It must be a DBCS, UTF-16, or
|
|
UCS-2 CCSID. The CCSID cannot be 65535.
|
|
<p>In the following rules, S denotes
|
|
one of the following: </p>
|
|
<ul>
|
|
<li>If the string expression is a host variable containing data in a foreign
|
|
encoding scheme, S is the result of the expression after converting the data
|
|
to a CCSID in a native encoding scheme. (See <a href="rbafzmstccseta.htm#ccseta">Character conversion</a> for more
|
|
information.)</li>
|
|
<li>If the string expression is data in a native encoding scheme, S is that
|
|
string expression.</li></ul>
|
|
<p>If the third argument is not specified and the first argument
|
|
is character, then the CCSID of the result is determined by a mixed CCSID.
|
|
Let M denote that mixed CCSID. M is determined as follows: </p>
|
|
<ul>
|
|
<li>If the CCSID of S is a mixed CCSID, M is that CCSID.</li>
|
|
<li>If the CCSID of S is an SBCS CCSID:
|
|
<ul>
|
|
<li>If the CCSID of S has an associated mixed CCSID, M is that CCSID.</li>
|
|
<li>Otherwise the operation is not allowed.</li></ul></li></ul>
|
|
<p>The following table summarizes the result CCSID based on M.</p>
|
|
<a name="wq590"></a>
|
|
<table id="wq590" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq591" width="14%" align="left" valign="bottom">M</th>
|
|
<th id="wq592" width="19%" align="left" valign="bottom">Result CCSID</th>
|
|
<th id="wq593" width="28%" align="left" valign="bottom">Description</th>
|
|
<th id="wq594" width="37%" align="left" valign="bottom">DBCS Substitution Character</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">930</td>
|
|
<td align="left" valign="top" headers="wq592">300</td>
|
|
<td align="left" valign="top" headers="wq593">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">933</td>
|
|
<td align="left" valign="top" headers="wq592">834</td>
|
|
<td align="left" valign="top" headers="wq593">Korean EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">935</td>
|
|
<td align="left" valign="top" headers="wq592">837</td>
|
|
<td align="left" valign="top" headers="wq593">S-Chinese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">937</td>
|
|
<td align="left" valign="top" headers="wq592">835</td>
|
|
<td align="left" valign="top" headers="wq593">T-Chinese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">939</td>
|
|
<td align="left" valign="top" headers="wq592">300</td>
|
|
<td align="left" valign="top" headers="wq593">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">5026</td>
|
|
<td align="left" valign="top" headers="wq592">4396</td>
|
|
<td align="left" valign="top" headers="wq593">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq591">5035</td>
|
|
<td align="left" valign="top" headers="wq592">4396</td>
|
|
<td align="left" valign="top" headers="wq593">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq594">X'FEFE'</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<p>If the result is DBCS-graphic data, the equivalence of SBCS and DBCS characters
|
|
depends on M. Regardless of the CCSID, every double-byte code point in the
|
|
argument is considered a DBCS character, and every single-byte code point
|
|
in the argument is considered an SBCS character with the exception of the
|
|
EBCDIC mixed data shift codes <tt class="xph">X'0E'</tt> and <tt class="xph">X'0F'</tt>. </p>
|
|
<ul>
|
|
<li>If the nth character of the argument is a DBCS character, the nth character
|
|
of the result is that DBCS character.</li>
|
|
<li>If the nth character of the argument is an SBCS character that has an
|
|
equivalent DBCS character, the nth character of the result is that equivalent
|
|
DBCS character.</li>
|
|
<li>If the nth character of the argument is an SBCS character that does not
|
|
have an equivalent DBCS character, the nth character of the result is the
|
|
DBCS substitution character.</li></ul>
|
|
<p>If the result is UTF-16 or UCS-2 graphic data, each character of the argument
|
|
determines a character of the result. The nth character of the result is
|
|
the UTF-16 or UCS-2 equivalent of the nth character of the argument.</p>
|
|
<p><span class="bold">Graphic to DBCLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">graphic-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in graphic-string
|
|
data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting varying length character string. The value must be between
|
|
1 and 1 073 741 823.
|
|
<p>If the second argument is not specified or DEFAULT
|
|
is specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">graphic-expression</span> is the empty string
|
|
constant, the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length
|
|
attribute of the result and the actual length of <span class="italic">graphic-expression</span>. If the length of the <span class="italic">graphic-expression</span> is
|
|
greater than the length attribute of the result, truncation is performed.
|
|
A warning (SQLSTATE 01004) is returned unless the truncated characters were
|
|
all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID for
|
|
the resulting varying-length graphic string. It must be a DBCS, UTF-16, or
|
|
UCS-2 CCSID. The CCSID cannot be 65535.
|
|
<p>In the following rules, S denotes
|
|
one of the following: </p>
|
|
<ul>
|
|
<li>If the string expression is a host variable containing data in a foreign
|
|
encoding scheme, S is the result of the expression after converting the data
|
|
to a CCSID in a native encoding scheme. (See <a href="rbafzmstccseta.htm#ccseta">Character conversion</a> for more
|
|
information.)</li>
|
|
<li>If the string expression is data in a native encoding scheme, S is that
|
|
string expression.</li></ul>
|
|
<p>If the third argument is not specified, then the CCSID of the
|
|
result is the same as the CCSID of the first argument.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Integer to DBCLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">integer-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in integer data type
|
|
(either SMALLINT, INTEGER, or BIGINT).
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length graphic string of the argument in the
|
|
form of an SQL integer constant. The result consists of n characters that
|
|
are the significant digits that represent the value of the argument with a
|
|
preceding minus sign if the argument is negative. The result is left justified.</p>
|
|
<ul>
|
|
<li>If the argument is a small integer, the length attribute of the result
|
|
is 6.</li>
|
|
<li>If the argument is a large integer, the length attribute of the result
|
|
is 11.</li>
|
|
<li>If the argument is a big integer, the length attribute of the result is
|
|
20.</li></ul>
|
|
<p>The actual length of the result is the smallest number of characters that
|
|
can be used to represent the value of the argument. Leading zeroes are not
|
|
included. If the argument is negative, the first character of the result is
|
|
a minus sign. Otherwise, the first character is a digit.</p>
|
|
<p>The CCSID of the result is 1200 (UTF-16).</p>
|
|
<p><span class="bold">Decimal to DBCLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">decimal-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in decimal data type
|
|
(either DECIMAL or NUMERIC). If a different precision and scale is desired,
|
|
the DECIMAL scalar function can be used to make the change.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length graphic string representation of the
|
|
argument. The result includes a decimal character and up to <var class="pv">p</var> digits,
|
|
where <var class="pv">p</var> is the precision of the <var class="pv">decimal-expression</var> with
|
|
a preceding minus sign if the argument is negative. Leading zeros are not
|
|
returned. Trailing zeros are returned.</p>
|
|
<p>The length attribute of the result is 2+<var class="pv">p</var> where <var class="pv">p</var> is
|
|
the precision of the <var class="pv">decimal-expression</var>. The actual length of the
|
|
result is the smallest number of characters that can be used to represent
|
|
the result, except that trailing characters are included. Leading zeros are
|
|
not included. If the argument is negative, the result begins with a minus
|
|
sign. Otherwise, the result begins with a digit.</p>
|
|
<p> The CCSID of the result is 1200 (UTF-16).</p>
|
|
<p><span class="bold">Floating-point to DBCLOB</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">floating-point expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in floating-point
|
|
data type (DOUBLE or REAL).
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length graphic string representation of the
|
|
argument in the form of a floating-point constant.</p>
|
|
<p>The length attribute of the result is 24. The actual length of the result
|
|
is the smallest number of characters that can represent the value of the argument
|
|
such that the mantissa consists of a single digit other than zero followed
|
|
by the <var class="pv">decimal-character</var> and a sequence of digits. If the argument
|
|
is negative, the first character of the result is a minus sign; otherwise,
|
|
the first character is a digit. If the argument is zero, the result is 0E0.</p>
|
|
<p>The CCSID of the result is 1200 (UTF-16).</p>
|
|
<a name="wq595"></a>
|
|
<h4 id="wq595">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the length attribute is
|
|
specified, the CAST specification should be used for maximal portability.
|
|
For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq596"></a>
|
|
<h4 id="wq596">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, set the host variable VAR_DESC (VARGRAPHIC(24))
|
|
to the DBCLOB equivalent of the first name (FIRSTNME) for employee number
|
|
(EMPNO) '000050'.
|
|
<pre class="xmp"> <span class="bold">SELECT DBCLOB(VARGRAPHIC(</span>FIRSTNME<span class="bold">))</span>
|
|
<span class="bold">INTO</span> :VAR_DESC
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO = '000050'</pre></li></ul>
|
|
<a name="scanodename"></a>
|
|
<h3 id="scanodename"><a href="rbafzmst02.htm#ToC_425">DBPARTITIONNAME</a></h3><a id="idx932" name="idx932"></a><a id="idx933" name="idx933"></a><a id="idx934" name="idx934"></a><a id="idx935" name="idx935"></a>
|
|
<a href="rbafzmstscale.htm#synnodename"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq597"></a>
|
|
<div class="fignone" id="wq597">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn97.htm"
|
|
border="0" /></span><a href="#skipsyn-96"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBPARTITIONNAME--(--<span class="italic">table-designator</span>--)---------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-96" id="skipsyn-96"></a></div>
|
|
<a name="synnodename"></a>
|
|
<p id="synnodename">The DBPARTITIONNAME function returns the relational database
|
|
name (database partition name) of where a row is located. If the argument
|
|
identifies a non-distributed table, an empty string is returned. For more
|
|
information about partitions, see the <a href="../dbmult/rzaf3kickoff.htm">DB2 Multisystem</a> book.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">table-designator</var></dt>
|
|
<dd>The argument must be a table designator of the subselect. For more information
|
|
about table designators, see <a href="rbafzmstch2col.htm#tdjm">Table designators</a>.
|
|
<p>In SQL naming,
|
|
the table name may be qualified. In system naming, the table name cannot
|
|
be qualified.</p>
|
|
<p>If the argument identifies a view, common table expression,
|
|
or derived table, the function returns the relational database name of its
|
|
base table. If the argument identifies a view, common table expression, or
|
|
derived table derived from more than one base table, the function returns
|
|
the partition name of the first table in the outer subselect of the view,
|
|
common table expression, or derived table.</p>
|
|
<p>The argument must
|
|
not identify a view, common table expression, or derived table whose outer
|
|
subselect includes an aggregate function, a GROUP BY clause, a HAVING clause,
|
|
a UNION clause, an INTERSECT clause, or DISTINCT clause. If the subselect
|
|
contains a GROUP BY or HAVING clause, the DBPARTITIONNAME function can only
|
|
be specified in the WHERE clause or as an operand of an aggregate function.
|
|
If the argument is a correlation name, the correlation name must not identify
|
|
a correlated reference.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is VARCHAR(18). The result can be null.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current server.</p>
|
|
<a name="wq598"></a>
|
|
<h4 id="wq598">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> NODENAME is a synonym for DBPARTITIONNAME.</p>
|
|
<a name="wq599"></a>
|
|
<h4 id="wq599">Example</h4>
|
|
<ul>
|
|
<li>Join the EMPLOYEE and DEPARTMENT tables, select the employee number (EMPNO)
|
|
and determine the node from which each row involved in the join originated.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">DBPARTITIONNAME(</span>X<span class="bold">)</span>, <span class="bold">DBPARTITIONNAME(</span>Y<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE X, DEPARTMENT Y
|
|
<span class="bold">WHERE</span> X.DEPTNO=Y.DEPTNO</pre></li></ul>
|
|
<a name="scandnumb"></a>
|
|
<h3 id="scandnumb"><a href="rbafzmst02.htm#ToC_428">DBPARTITIONNUM</a></h3><a id="idx936" name="idx936"></a><a id="idx937" name="idx937"></a><a id="idx938" name="idx938"></a><a id="idx939" name="idx939"></a>
|
|
<a href="rbafzmstscale.htm#synnodenum"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq600"></a>
|
|
<div class="fignone" id="wq600">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn98.htm"
|
|
border="0" /></span><a href="#skipsyn-97"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DBPARTITIONNUM--(--<span class="italic">table-designator</span>--)----------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-97" id="skipsyn-97"></a></div>
|
|
<a name="synnodenum"></a>
|
|
<p id="synnodenum">The DBPARTITIONNUM function returns the node number (database
|
|
partition number) of a row. If the argument identifies a non-distributed table,
|
|
the value 0 is returned.<sup class="fn"><a id="wq601" name="wq601" href="rbafzmstscale.htm#wq602">42</a></sup> For more information about nodes and node numbers, see the <a href="../dbmult/rzaf3kickoff.htm">DB2 Multisystem</a> book.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">table-designator</var></dt>
|
|
<dd>The argument must be a table designator of the subselect. For more information
|
|
about table designators, see <a href="rbafzmstch2col.htm#tdjm">Table designators</a>.
|
|
<p>In SQL naming,
|
|
the table name may be qualified. In system naming, the table name cannot
|
|
be qualified.</p>
|
|
<p>If the argument identifies a view, common table expression,
|
|
or derived table, the function returns the node number of its base table.
|
|
If the argument identifies a view, common table expression, or derived table
|
|
derived from more than one base table, the function returns the node number
|
|
of the first table in the outer subselect of the view, common table expression,
|
|
or derived table.</p>
|
|
<p>The argument must not identify a view,
|
|
common table expression, or derived table whose outer subselect includes an
|
|
aggregate function, a GROUP BY clause, a HAVING clause, a UNION clause, an
|
|
INTERSECT clause, or DISTINCT clause. If the subselect contains a GROUP BY
|
|
or HAVING clause, the DBPARTITIONNUM function can only be specified in the
|
|
WHERE clause or as an operand of an aggregate function. If the argument is
|
|
a correlation name, the correlation name must not identify a correlated reference.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is a large integer. The result can be null.</p>
|
|
<a name="wq603"></a>
|
|
<h4 id="wq603">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> NODENUMBER is a synonym for
|
|
DBPARTITIONNUM.</p>
|
|
<a name="wq604"></a>
|
|
<h4 id="wq604">Example</h4>
|
|
<ul>
|
|
<li>Determine the node number and employee name for each row in the EMPLOYEE
|
|
table. If this is a distributed table, the number of the node where the row
|
|
exists is returned.
|
|
<pre class="xmp"> <span class="bold">SELECT DBPARTITIONNUM(</span>EMPLOYEE<span class="bold">)</span>, LASTNAME
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scadec"></a>
|
|
<h3 id="scadec"><a href="rbafzmst02.htm#ToC_431">DECIMAL or DEC</a></h3><a id="idx940" name="idx940"></a><a id="idx941" name="idx941"></a>
|
|
<a href="rbafzmstscale.htm#syndec"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq605"></a>
|
|
<div class="fignone" id="wq605">
|
|
<p><span class="bold">Numeric to Decimal</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn99.htm"
|
|
border="0" /></span><a href="#skipsyn-98"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-DECIMAL-+-------------------------------------------------->
|
|
'-DEC-----'
|
|
|
|
>--(--<span class="italic">numeric-expression</span>--+----------------------------+--)----><
|
|
'-,--<span class="italic">precision</span>--+----------+-'
|
|
'-,--<span class="italic">scale</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-98" id="skipsyn-98"></a>
|
|
<p><span class="bold">String to Decimal</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn100.htm"
|
|
border="0" /></span><a href="#skipsyn-99"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-DECIMAL-+-------------------------------------------------->
|
|
'-DEC-----'
|
|
|
|
>--(--<span class="italic">string-expression</span>--+------------------------------------------------------+--)-><
|
|
'-,--<span class="italic">precision</span>--+------------------------------------+-'
|
|
'-,--<span class="italic">scale</span>--+----------------------+-'
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-99" id="skipsyn-99"></a></div>
|
|
<a name="syndec"></a>
|
|
<p id="syndec">The DECIMAL function returns a decimal representation of: </p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p><span class="bold">Numeric to Decimal</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">precision</var></dt>
|
|
<dd>An integer constant with a value greater than or equal to 1 and less
|
|
than or equal to 63.
|
|
<p>The default for <var class="pv">precision</var> depends on the data
|
|
type of the <var class="pv">numeric-expression</var>: </p>
|
|
<ul>
|
|
<li>15 for floating point, decimal, numeric, or nonzero scale binary</li>
|
|
<li>19 for big integer</li>
|
|
<li>11 for large integer</li>
|
|
<li>5 for small integer</li></ul>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">scale</var></dt>
|
|
<dd>An integer constant that is greater than or equal to 0 and less than
|
|
or equal to <var class="pv">precision</var>. If not specified, the default is 0.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is the same number that would occur if the first argument
|
|
were assigned to a decimal column or variable with a precision of <span class="italic">p</span> and a scale of <span class="italic">s</span>. An error is returned if the
|
|
number of significant decimal digits required to represent the whole part
|
|
of the number is greater than <span class="italic">p</span>-<span class="italic">s</span>.</p>
|
|
<p><span class="bold">String to Decimal</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a character-string or graphic-string
|
|
representation of a number. Leading and trailing blanks are eliminated and
|
|
the resulting string must conform to the rules for forming a floating-point,
|
|
integer, or decimal constant.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">precision</var></dt>
|
|
<dd>An integer constant that is greater than or equal to 1 and less than
|
|
or equal to 63. If not specified, the default is 15.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">scale</var></dt>
|
|
<dd>An integer constant that is greater than or equal to 0 and less than
|
|
or equal to <var class="pv">precision</var>. If not specified, the default is 0.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in <var class="pv">string-expression</var> from the whole part of the
|
|
number. The character must be a period or comma. If <var class="pv">decimal-character</var> is not specified, the decimal point is the default decimal separator
|
|
character. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is the same number that would result from CAST(<var class="pv">string-expression</var> AS DECIMAL(<var class="pv">p</var>,<var class="pv">s</var>)). Digits are truncated from the end
|
|
of the decimal number if the number of digits to the right of the decimal
|
|
separator character is greater than the scale <var class="pv">s</var>. An error is returned
|
|
if the number of significant digits to the left of the decimal character (the
|
|
whole part of the number) in <var class="pv">string-expression</var> is greater than <var class="pv">p-s</var>. The default decimal character is not valid in the substring if the <var class="pv">decimal-character</var> argument is specified.</p>
|
|
<p>The result of the function is a decimal number with precision of <span class="italic">p</span> and scale of <span class="italic">s</span>, where <span class="italic">p</span> and <span class="italic">s</span> are the second and third arguments. If
|
|
the first argument can be null, the result can be null; if the first argument
|
|
is null, the result is the null value.</p>
|
|
<a name="wq606"></a>
|
|
<h4 id="wq606">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the precision is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq607"></a>
|
|
<h4 id="wq607">Examples</h4>
|
|
<ul>
|
|
<li>Use the DECIMAL function in order to force a DECIMAL data type (with a
|
|
precision of 5 and a scale of 2) to be returned in a select-list for the EDLEVEL
|
|
column (data type = SMALLINT) in the EMPLOYEE table. The EMPNO column should
|
|
also appear in the select list.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">DECIMAL(</span>EDLEVEL,5,2<span class="bold">)
|
|
FROM</span> EMPLOYEE</pre></li>
|
|
<li>Using the PROJECT table, select all of the starting dates (PRSTDATE) that
|
|
have been incremented by a duration that is specified in a host variable.
|
|
Assume the host variable PERIOD is of type INTEGER. Then, in order to use
|
|
its value as a date duration it must be "cast" as DECIMAL(8,0).
|
|
<pre class="xmp"> <span class="bold">SELECT</span> PRSTDATE + <span class="bold">DECIMAL(</span>:PERIOD,8<span class="bold">)
|
|
FROM</span> PROJECT</pre></li>
|
|
<li>Assume that updates to the SALARY column are input through a window as
|
|
a character string using comma as a decimal character (for example, the user
|
|
inputs 21400,50). Once validated by the application, it is assigned to the
|
|
host variable newsalary which is defined as CHAR(10).
|
|
<pre class="xmp"> <span class="bold">UPDATE</span> STAFF
|
|
<span class="bold">SET</span> SALARY = <span class="bold">DECIMAL</span>(:newsalary, 9, 2, ',')
|
|
<span class="bold">WHERE</span> ID = :empid</pre>The value
|
|
of SALARY becomes 21400.50.</li></ul>
|
|
<a name="scadecrypt"></a>
|
|
<h3 id="scadecrypt"><a href="rbafzmst02.htm#ToC_434">DECRYPT_BIT, DECRYPT_BINARY, DECRYPT_CHAR and DECRYPT_DB</a></h3><a id="idx942" name="idx942"></a><a id="idx943" name="idx943"></a><a id="idx944" name="idx944"></a><a id="idx945" name="idx945"></a><a id="idx946" name="idx946"></a><a id="idx947" name="idx947"></a><a id="idx948" name="idx948"></a><a id="idx949" name="idx949"></a>
|
|
<a href="rbafzmstscale.htm#syndecrypt"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq608"></a>
|
|
<div class="fignone" id="wq608">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn101.htm"
|
|
border="0" /></span><a href="#skipsyn-100"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-DECRYPT_BIT----+--(--<span class="italic">encrypted-data</span>--+----------------------------------------+--)-><
|
|
+-DECRYPT_BINARY-+ '-,--+-<span class="italic">password-string</span>-+--+------------+-'
|
|
+-DECRYPT_CHAR---+ '-DEFAULT---------' '-,--<span class="italic">integer</span>-'
|
|
'-DECRYPT_DB-----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-100" id="skipsyn-100"></a></div>
|
|
<a name="syndecrypt"></a>
|
|
<p id="syndecrypt">The DECRYPT_BIT, DECRYPT_BINARY, DECRYPT_CHAR,
|
|
and DECRYPT_DB functions return a value that is the result of decrypting encrypted
|
|
data. The password used for decryption is either the <var class="pv">password-string</var> value
|
|
or the ENCRYPTION PASSWORD value assigned by the SET ENCRYPTION PASSWORD statement.</p>
|
|
<p>The decryption functions can only decrypt values that are encrypted
|
|
using the ENCRYPT_RC2 or ENCRYPT_TDES function.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">encrypted-data</var></dt>
|
|
<dd>An expression that must be a string expression that returns
|
|
a complete, encrypted data value of a CHAR FOR BIT DATA, VARCHAR FOR BIT DATA,
|
|
BINARY, VARBINARY, or BLOB built-in data type. The data string must have been
|
|
encrypted using the ENCRYPT_RC2 or ENCRYPT_TDES function.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">password-string</var></dt>
|
|
<dd>An expression that returns a character string value with at least 6
|
|
bytes and no more than 127 bytes. The expression must not be a CLOB. This
|
|
expression must be the same password used to encrypt the data or an error
|
|
is returned. If the value of the password argument is null or not provided,
|
|
the data will be decrypted using the ENCRYPTION PASSWORD value, which must
|
|
have been set using the SET ENCRYPTION PASSWORD statement.
|
|
</dd>
|
|
<dt class="bold">DEFAULT</dt>
|
|
<dd>The data will be decrypted using the ENCRYPTION PASSWORD value, which
|
|
must have been set using the SET ENCRYPTION PASSWORD statement.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd>An integer constant that specifies the CCSID of the result. If DECRYPT_BIT
|
|
or DECRYPT_BINARY is specified, the third argument must not be specified.
|
|
<p>If DECRYPT_CHAR is specified, <var class="pv">integer</var> must be a valid SBCS CCSID
|
|
or mixed data CCSID. It cannot be 65535 (bit data). If the third argument
|
|
is an SBCS CCSID, then the result is SBCS data. If the third argument is a
|
|
mixed CCSID, then the result is mixed data. If the third argument is not specified
|
|
then the CCSID of the result is the default CCSID of the current server.</p>
|
|
<p>If DECRYPT_DB is specified, <var class="pv">integer</var> must be a valid DBCS CCSID. If
|
|
the third argument is not specified then the CCSID of the result is the DBCS
|
|
CCSID associated with the default CCSID of the current server.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is determined by the function specified and
|
|
the data type of the first argument as shown in the following table. If a
|
|
cast from the actual type of the encrypted data to the function's result is
|
|
not supported a warning or error is returned.</p>
|
|
<a name="wq609"></a>
|
|
<table id="wq609" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq610" width="22%" align="left" valign="bottom">Function</th>
|
|
<th id="wq611" width="25%" align="left" valign="bottom">Data Type of First Argument</th>
|
|
<th id="wq612" width="22%" align="left" valign="bottom">Actual Data Type of Encrypted Data</th>
|
|
<th id="wq613" width="29%" align="left" valign="bottom">Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_BIT</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Character string</td>
|
|
<td align="left" valign="top" headers="wq613">VARCHAR FOR BIT DATA</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_BIT</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_BIT</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Binary string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_BIT</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Any string</td>
|
|
<td align="left" valign="top" headers="wq613">Error</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_BINARY</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Any string</td>
|
|
<td align="left" valign="top" headers="wq613">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_BINARY</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Any string</td>
|
|
<td align="left" valign="top" headers="wq613">BLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Character string</td>
|
|
<td align="left" valign="top" headers="wq613">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">UCS-2 or UTF-16 graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Non-UCS-2 or non-UTF-16 graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Binary string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Character string</td>
|
|
<td align="left" valign="top" headers="wq613">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">UCS-2 or UTF-16 graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Non-UCS-2 or non-UTF-16 graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_CHAR</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Binary string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_DB</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">UTF-8 character string or graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_DB</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Non-UTF-8 character string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_DB</td>
|
|
<td align="left" valign="top" headers="wq611">CHAR FOR BIT DATA, VARCHAR FOR
|
|
BIT DATA, BINARY, or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq612">Binary string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_DB</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">UTF-8 character string or graphic string</td>
|
|
<td align="left" valign="top" headers="wq613">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_DB</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Non-UTF-8 character string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq610">DECRYPT_DB</td>
|
|
<td align="left" valign="top" headers="wq611">BLOB</td>
|
|
<td align="left" valign="top" headers="wq612">Binary string</td>
|
|
<td align="left" valign="top" headers="wq613">Error or Warning **</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="4" headers="wq610 wq611 wq612 wq613">
|
|
<a name="wq614"></a>
|
|
<div class="notetitle" id="wq614">Note:</div>
|
|
<div class="notebody"></div>
|
|
<p>** If the decryption
|
|
function is in the select list of an outer subselect, a data mapping warning
|
|
is returned. Otherwise an error is returned. For more information on data
|
|
mapping warnings, see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.</p></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>If the <var class="pv">encrypted-data</var> included a hint, the hint is not returned
|
|
by the function. The length attribute of the result is the length attribute
|
|
of the data type of <var class="pv">encrypted-data</var> minus 8 bytes. The actual length
|
|
of the result is the length of the original string that was encrypted. If
|
|
the <var class="pv">encrypted-data</var> includes bytes beyond the encrypted string, these
|
|
bytes are not returned by the function.</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>If the data is decrypted using a different CCSID than the originally encrypted
|
|
value, expansion may occur when converting the decrypted value to this CCSID.
|
|
In such situations, the <var class="pv">encrypted-data</var> should be cast to a varying-length
|
|
string with a larger number of bytes.</p>
|
|
<a name="wq615"></a>
|
|
<h4 id="wq615">Notes</h4>
|
|
<p><span class="bold">Password protection:</span> To prevent inadvertent access
|
|
to the encryption password, do not specify <var class="pv">password-string</var> as a string
|
|
constant in the source for a program, procedure, or function. Instead, use
|
|
the ENCRYPTION PASSWORD special register or a host variable.</p>
|
|
<p>When connected to a remote relational database, the specified password
|
|
itself is sent "in the clear". That is, the password itself is not encrypted.
|
|
To protect the password in these cases, consider using a communications encryption
|
|
mechanism such as IPSEC (or SSL if connecting between iSeries™ systems).</p>
|
|
<p><span class="bold">Syntax alternatives:</span> For compatibility with previous
|
|
versions of DB2, DECRYPT_BIN can be specified in place of DECRYPT_BIT.</p>
|
|
<a name="wq616"></a>
|
|
<h4 id="wq616">Examples</h4>
|
|
<ul>
|
|
<li>Assume that table EMP1 has a social security column called SSN. This example
|
|
uses the ENCRYPTION PASSWORD value to hold the encryption password.
|
|
<pre class="xmp"> <span class="bold">SET ENCRYPTION PASSWORD</span> = :pw
|
|
|
|
<span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_RC2(</span> '289-46-8832' <span class="bold">)</span>
|
|
|
|
<span class="bold">SELECT DECRYPT_CHAR(</span> SSN<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMP1</pre>The DECRYPT_CHAR
|
|
function returns the original value '289-46-8832'.</li>
|
|
<li>This example explicitly passes the encryption password which
|
|
has been set in variable pw.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_TDES(</span> '289-46-8832', :pw<span class="bold">)</span>
|
|
|
|
<span class="bold">SELECT DECRYPT_CHAR(</span> SSN, :pw<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMP1</pre>The DECRYPT_CHAR
|
|
function returns the original value '289-46-8832'.</li></ul>
|
|
<a name="scadegree"></a>
|
|
<h3 id="scadegree"><a href="rbafzmst02.htm#ToC_437">DEGREES</a></h3><a id="idx950" name="idx950"></a><a id="idx951" name="idx951"></a>
|
|
<a href="rbafzmstscale.htm#syndegrees"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq617"></a>
|
|
<div class="fignone" id="wq617">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn102.htm"
|
|
border="0" /></span><a href="#skipsyn-101"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DEGREES--(--<span class="italic">expression</span>--)-----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-101" id="skipsyn-101"></a></div>
|
|
<a name="syndegrees"></a>
|
|
<p id="syndegrees">The DEGREES function returns the number of degrees of the
|
|
argument which is an angle expressed in radians.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq618"></a>
|
|
<h4 id="wq618">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable RAD is a DECIMAL(4,3) host variable with a value
|
|
of 3.142.
|
|
<pre class="xmp"> <span class="bold">SELECT DEGREES</span>(:RAD)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 180.0.</li></ul>
|
|
<a name="difffun"></a>
|
|
<h3 id="difffun"><a href="rbafzmst02.htm#ToC_439">DIFFERENCE</a></h3><a id="idx952" name="idx952"></a><a id="idx953" name="idx953"></a>
|
|
<a href="rbafzmstscale.htm#syndiff"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq619"></a>
|
|
<div class="fignone" id="wq619">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn103.htm"
|
|
border="0" /></span><a href="#skipsyn-102"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DIFFERENCE--(--<span class="italic">expression-1</span>--,--<span class="italic">expression-2</span>--)-------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-102" id="skipsyn-102"></a></div>
|
|
<a name="syndiff"></a>
|
|
<p id="syndiff">The DIFFERENCE function returns a value from 0 to 4 representing
|
|
the difference between the sounds of two strings based on applying the SOUNDEX
|
|
function to the strings. A value of 4 is the best possible sound match.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression-1</var> or <var class="pv">expression-2</var></dt>
|
|
<dd>The arguments must be a built-in numeric, character-string, or graphic-string
|
|
data types, but not CLOBs or DBCLOBs. The arguments cannot be binary-strings.
|
|
A numeric argument is cast to a character string before evaluating the function.
|
|
For more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is INTEGER. If any argument can be null, the
|
|
result can be null; if any argument is null, the result is the null value.</p>
|
|
<a name="wq620"></a>
|
|
<h4 id="wq620">Examples</h4>
|
|
<ul>
|
|
<li>Assume the following statement:
|
|
<pre class="xmp"> <span class="bold">SELECT DIFFERENCE</span>('CONSTRAINT','CONSTANT'),
|
|
<span class="bold">SOUNDEX</span>('CONSTRAINT'),
|
|
<span class="bold">SOUNDEX</span>('CONSTANT')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
4, C523, and C523. Since the two strings return the same SOUNDEX value, the
|
|
difference is 4 (the highest value possible).</li>
|
|
<li>Assume the following statement:
|
|
<pre class="xmp"> <span class="bold">SELECT DIFFERENCE</span>('CONSTRAINT','CONTRITE'),
|
|
<span class="bold">SOUNDEX</span>('CONSTRAINT'),
|
|
<span class="bold">SOUNDEX</span>('CONTRITE')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
2, C523, and C536. In this case, the two strings return different SOUNDEX
|
|
values, and hence, a lower difference value.</li></ul>
|
|
<a name="scadigits"></a>
|
|
<h3 id="scadigits"><a href="rbafzmst02.htm#ToC_441">DIGITS</a></h3><a id="idx954" name="idx954"></a><a id="idx955" name="idx955"></a>
|
|
<a href="rbafzmstscale.htm#syndigits"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq621"></a>
|
|
<div class="fignone" id="wq621">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn104.htm"
|
|
border="0" /></span><a href="#skipsyn-103"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DIGITS--(--<span class="italic">expression</span>--)------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-103" id="skipsyn-103"></a></div>
|
|
<a name="syndigits"></a>
|
|
<p id="syndigits">The DIGITS function returns a character-string representation
|
|
of the absolute value of a number.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of a built-in
|
|
small integer, integer, big integer, decimal, character-string, or graphic-string
|
|
data type. A string argument is cast to DECIMAL(63,31) before evaluating the
|
|
function. For more information on converting strings to decimal, see <a href="rbafzmstscale.htm#scadec">DECIMAL or DEC</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>The result of the function is a fixed-length character string representing
|
|
the absolute value of the argument without regard to its scale. The result
|
|
does not include a sign or a decimal point. Instead, it consists exclusively
|
|
of digits, including, if necessary, leading zeros to fill out the string.
|
|
The length of the string is: </p>
|
|
<ul>
|
|
<li>5, if the argument is a small zero scale integer</li>
|
|
<li>10, if the argument is a large zero scale integer</li>
|
|
<li>19, if the argument is a big integer</li>
|
|
<li><span class="italic">p</span>, if the argument is a decimal or nonzero scale
|
|
integer with a precision of <span class="italic">p</span></li></ul>
|
|
<p>The CCSID of the character string is the default SBCS CCSID at the current
|
|
server.</p>
|
|
<a name="wq622"></a>
|
|
<h4 id="wq622">Examples</h4>
|
|
<ul>
|
|
<li>Assume that a table called TABLEX contains an INTEGER column called INTCOL
|
|
containing 10-digit numbers. List all combinations of the first four digits
|
|
contained in column INTCOL.
|
|
<pre class="xmp"> <span class="bold">SELECT DISTINCT SUBSTR(DIGITS(</span>INTCOL<span class="bold">)</span>,1,4<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TABLEX</pre></li>
|
|
<li>Assume that COLUMNX has the DECIMAL(6,2) data type, and that one of its
|
|
values is -6.28.
|
|
<pre class="xmp"> <span class="bold">SELECT DIGITS(</span>COLUMNX<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TABLEX</pre> Returns the value '000628'.
|
|
<p>The result is a string of length six (the precision of the column) with leading
|
|
zeros padding the string out to this length. Neither sign nor decimal point
|
|
appear in the result.</p></li></ul>
|
|
<a name="scadlcomment"></a>
|
|
<h3 id="scadlcomment"><a href="rbafzmst02.htm#ToC_443">DLCOMMENT</a></h3><a id="idx956" name="idx956"></a><a id="idx957" name="idx957"></a>
|
|
<a href="rbafzmstscale.htm#syndlcomment"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq623"></a>
|
|
<div class="fignone" id="wq623">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn105.htm"
|
|
border="0" /></span><a href="#skipsyn-104"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLCOMMENT--(--<span class="italic">DataLink-expression</span>--)------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-104" id="skipsyn-104"></a></div>
|
|
<a name="syndlcomment"></a>
|
|
<p id="syndlcomment">The DLCOMMENT function returns the comment value, if
|
|
it exists, from a DataLink value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is VARCHAR(254). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq624"></a>
|
|
<h4 id="wq624">Examples</h4>
|
|
<ul>
|
|
<li>Prepare a statement to select the date, the description and the comment
|
|
from the link to the ARTICLES column from the HOCKEY_GOALS table. The rows
|
|
to be selected are those for goals scored by either of the Richard brothers
|
|
(Maurice or Henri).
|
|
<pre class="xmp"> stmtvar = "SELECT DATE_OF_GOAL, DESCRIPTION, DLCOMMENT(ARTICLES)
|
|
FROM HOCKEY_GOALS
|
|
WHERE BY_PLAYER = 'Maurice Richard' OR BY_PLAYER = 'Henri Richard' ";
|
|
EXEC SQL <span class="bold">PREPARE</span> HOCKEY_STMT <span class="bold">FROM</span> :stmtvar;</pre></li>
|
|
<li>Given a DataLink value that was inserted into column COLA of a row in
|
|
table TBLA using the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO TBLA
|
|
VALUES (DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">))</span>
|
|
</pre> then the following function operating on that value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLCOMMENT(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA</pre>Returns the value
|
|
'A comment'.</li></ul>
|
|
<a name="scadllktype"></a>
|
|
<h3 id="scadllktype"><a href="rbafzmst02.htm#ToC_445">DLLINKTYPE</a></h3><a id="idx958" name="idx958"></a><a id="idx959" name="idx959"></a>
|
|
<a href="rbafzmstscale.htm#syndllinktype"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq625"></a>
|
|
<div class="fignone" id="wq625">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn106.htm"
|
|
border="0" /></span><a href="#skipsyn-105"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLLINKTYPE--(--<span class="italic">DataLink-expression</span>--)-----------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-105" id="skipsyn-105"></a></div>
|
|
<a name="syndllinktype"></a>
|
|
<p id="syndllinktype">The DLLINKTYPE function returns the link type value
|
|
from a DataLink value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is VARCHAR(4). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq626"></a>
|
|
<h4 id="wq626">Examples</h4>
|
|
<ul>
|
|
<li>Given a DataLink value that was inserted into column COLA of a row in
|
|
table TBLA using the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> TABLA
|
|
<span class="bold">VALUES( DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">) )</span></pre> then the following function operating on that
|
|
value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLLINKTYPE(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA</pre>Returns the value
|
|
'URL'.</li></ul>
|
|
<a name="scadlurlcomp"></a>
|
|
<h3 id="scadlurlcomp"><a href="rbafzmst02.htm#ToC_447">DLURLCOMPLETE</a></h3><a id="idx960" name="idx960"></a><a id="idx961" name="idx961"></a>
|
|
<a href="rbafzmstscale.htm#syndlurlcomplete"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq627"></a>
|
|
<div class="fignone" id="wq627">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn107.htm"
|
|
border="0" /></span><a href="#skipsyn-106"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLURLCOMPLETE--(--<span class="italic">DataLink-expression</span>--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-106" id="skipsyn-106"></a></div>
|
|
<a name="syndlurlcomplete"></a>
|
|
<p id="syndlurlcomplete">The DLURLCOMPLETE function returns the complete URL
|
|
value from a DataLink value with a link type of URL. The value is the same
|
|
as what would be returned by the concatenation of DLURLSCHEME with '://',
|
|
then DLURLSERVER, and then DLURLPATH. If the DataLink has an attribute of
|
|
FILE LINK CONTROL and READ PERMISSION DB, the value includes a file access
|
|
token.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>The result of the function is a varying-length string. The length attribute
|
|
depends on the attributes of the DataLink:</p>
|
|
<ul>
|
|
<li>If the DataLink has an attribute of FILE LINK CONTROL and READ PERMISSION
|
|
DB, the length attribute of the result is the length attribute of the argument
|
|
plus 19.</li>
|
|
<li>Otherwise, the length attribute of the result is the length attribute
|
|
of the argument.</li></ul>
|
|
<p>If the DataLink value only includes the comment, the result returned is
|
|
a zero length string.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq628"></a>
|
|
<h4 id="wq628">Examples</h4>
|
|
<ul>
|
|
<li>Given a DataLink value that was inserted into column COLA (with the attributes
|
|
of FILE LINK CONTROL and READ PERMISSION DB) of a row in table TBLA using
|
|
the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> TABLA
|
|
<span class="bold">VALUES( DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">) )</span></pre> then the following function operating on that
|
|
value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLURLCOMPLETE(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA</pre>Returns the value
|
|
'HTTP://DLFS.ALMADEN.IBM.COM/x/y/****************;a.b', where ****************
|
|
represents the access token.</li></ul>
|
|
<a name="scadlurlpath"></a>
|
|
<h3 id="scadlurlpath"><a href="rbafzmst02.htm#ToC_449">DLURLPATH</a></h3><a id="idx962" name="idx962"></a><a id="idx963" name="idx963"></a>
|
|
<a href="rbafzmstscale.htm#syndlurlpath"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq629"></a>
|
|
<div class="fignone" id="wq629">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn108.htm"
|
|
border="0" /></span><a href="#skipsyn-107"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLURLPATH--(--<span class="italic">DataLink-expression</span>--)------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-107" id="skipsyn-107"></a></div>
|
|
<a name="syndlurlpath"></a>
|
|
<p id="syndlurlpath">The DLURLPATH function returns the path and file name
|
|
necessary to access a file within a given server from a DataLink value with
|
|
a linktype of URL. When appropriate, the value includes a file access token.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>The result of the function is a varying-length string. The length attribute
|
|
depends on the attributes of the DataLink:</p>
|
|
<ul>
|
|
<li>If the DataLink has an attribute of FILE LINK CONTROL and READ PERMISSION
|
|
DB, the length attribute of the result is the length attribute of the argument
|
|
plus 19.</li>
|
|
<li>Otherwise, the length attribute of the result is the length attribute
|
|
of the argument.</li></ul>
|
|
<p>If the DataLink value only includes the comment, the result returned is
|
|
a zero length string.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq630"></a>
|
|
<h4 id="wq630">Examples</h4>
|
|
<ul>
|
|
<li>Given a DataLink value that was inserted into column COLA (with the attributes
|
|
of FILE LINK CONTROL and READ PERMISSION DB) of a row in table TBLA using
|
|
the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> TABLA
|
|
<span class="bold">VALUES( DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">) )</span></pre> then the following function operating on that
|
|
value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLURLPATH(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA </pre>Returns
|
|
the value '/x/y/****************;a.b', where **************** represents the
|
|
access token.</li></ul>
|
|
<a name="scadlurlponly"></a>
|
|
<h3 id="scadlurlponly"><a href="rbafzmst02.htm#ToC_451">DLURLPATHONLY</a></h3><a id="idx964" name="idx964"></a><a id="idx965" name="idx965"></a>
|
|
<a href="rbafzmstscale.htm#syndlurlpathonly"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq631"></a>
|
|
<div class="fignone" id="wq631">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn109.htm"
|
|
border="0" /></span><a href="#skipsyn-108"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLURLPATHONLY--(--<span class="italic">DataLink-expression</span>--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-108" id="skipsyn-108"></a></div>
|
|
<a name="syndlurlpathonly"></a>
|
|
<p id="syndlurlpathonly">The DLURLPATHONLY function returns the path and file
|
|
name necessary to access a file within a given server from a DataLink value
|
|
with a linktype of URL. The value returned NEVER includes a file access token.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>The result of the function is a varying-length string with a length attribute
|
|
of that is equal to the length attribute of the argument.</p>
|
|
<p>If the DataLink value only includes the comment, the result returned is
|
|
a zero length string.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq632"></a>
|
|
<h4 id="wq632">Examples</h4>
|
|
<ul>
|
|
<li>Given a DataLink value that was inserted into column COLA of a row in
|
|
table TBLA using the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> TABLA
|
|
<span class="bold">VALUES( DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">) )</span></pre> then the following function operating on that
|
|
value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLURLPATHONLY(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA</pre>Returns the value
|
|
'/x/y/a.b'.</li></ul>
|
|
<a name="scadlurlschem"></a>
|
|
<h3 id="scadlurlschem"><a href="rbafzmst02.htm#ToC_453">DLURLSCHEME</a></h3><a id="idx966" name="idx966"></a><a id="idx967" name="idx967"></a>
|
|
<a href="rbafzmstscale.htm#syndlurlscheme"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq633"></a>
|
|
<div class="fignone" id="wq633">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn110.htm"
|
|
border="0" /></span><a href="#skipsyn-109"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLURLSCHEME--(--<span class="italic">DataLink-expression</span>--)----------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-109" id="skipsyn-109"></a></div>
|
|
<a name="syndlurlscheme"></a>
|
|
<p id="syndlurlscheme">The DLURLSCHEME function returns the scheme from a
|
|
DataLink value with a linktype of URL. The value will always be in upper case.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is VARCHAR(20). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>If the DataLink value only includes the comment, the result returned is
|
|
a zero length string.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq634"></a>
|
|
<h4 id="wq634">Examples</h4>
|
|
<ul>
|
|
<li>Given a DataLink value that was inserted into column COLA of a row in
|
|
table TBLA using the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> TABLA
|
|
<span class="bold">VALUES( DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">) )</span></pre> then the following function operating on that
|
|
value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLURLSCHEME(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA</pre>Returns the value
|
|
'HTTP'.</li></ul>
|
|
<a name="scadlserver"></a>
|
|
<h3 id="scadlserver"><a href="rbafzmst02.htm#ToC_455">DLURLSERVER</a></h3><a id="idx968" name="idx968"></a><a id="idx969" name="idx969"></a>
|
|
<a href="rbafzmstscale.htm#syndlurlserver"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq635"></a>
|
|
<div class="fignone" id="wq635">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn111.htm"
|
|
border="0" /></span><a href="#skipsyn-110"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLURLSERVER--(--<span class="italic">DataLink-expression</span>--)----------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-110" id="skipsyn-110"></a></div>
|
|
<a name="syndlurlserver"></a>
|
|
<p id="syndlurlserver">The DLURLSERVER function returns the file server from
|
|
a DataLink value with a linktype of URL. The value will always be in upper
|
|
case.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">DataLink-expression</var></dt>
|
|
<dd>The argument must be an expression that results in a value with a built-in
|
|
DataLink data type.
|
|
</dd>
|
|
</dl>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>The result of the function is a varying-length string with a length attribute
|
|
of that is equal to the length attribute of the argument.</p>
|
|
<p>If the DataLink value only includes the comment, the result returned is
|
|
a zero length string.</p>
|
|
<p>The CCSID of the character string is the same as that of <span class="italic">DataLink-expression</span>.</p>
|
|
<a name="wq636"></a>
|
|
<h4 id="wq636">Examples</h4>
|
|
<ul>
|
|
<li>Given a DataLink value that was inserted into column COLA of a row in
|
|
table TBLA using the scalar function:
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> TABLA
|
|
<span class="bold">VALUES( DLVALUE(</span>'http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'<span class="bold">) )</span></pre> then the following function operating on that
|
|
value:
|
|
<pre class="xmp"> <span class="bold">SELECT DLURLSERVER(</span>COLA<span class="bold">)</span>
|
|
<span class="bold">FROM</span> TBLA</pre>Returns the value
|
|
'DLFS.ALMADEN.IBM.COM'.</li></ul>
|
|
<a name="scadlvalue"></a>
|
|
<h3 id="scadlvalue"><a href="rbafzmst02.htm#ToC_457">DLVALUE</a></h3><a id="idx970" name="idx970"></a><a id="idx971" name="idx971"></a>
|
|
<a href="rbafzmstscale.htm#syndlvalue"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq637"></a>
|
|
<div class="fignone" id="wq637">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn112.htm"
|
|
border="0" /></span><a href="#skipsyn-111"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-DLVALUE--(--<span class="italic">data-location</span>--+-------------------------------------------+--)-><
|
|
'-,--<span class="italic">linktype-string</span>--+-------------------+-'
|
|
'-,--<span class="italic">comment-string</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-111" id="skipsyn-111"></a></div>
|
|
<a name="syndlvalue"></a>
|
|
<p id="syndlvalue">The DLVALUE function returns a DataLink value. When the
|
|
function is on the right hand side of a SET clause in an UPDATE statement
|
|
or is in a VALUES clause in an INSERT statement, it usually also creates a
|
|
link to a file. However, if only a comment is specified (in which case the <span class="italic">data-location</span> is a zero-length string), the DataLink value
|
|
is created with empty linkage attributes so there is no file link.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">data-location</var></dt>
|
|
<dd>If the link type is URL, then this is a character string expression
|
|
that contains a complete URL value. If the expression is not an empty string,
|
|
it must include the URL scheme and URL server. The actual length of the character
|
|
string expression must be less than or equal to 32718 characters.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">linktype-string</var></dt>
|
|
<dd>An optional character string expression that specifies the link type
|
|
of the DataLink value. The only valid value is 'URL'.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">comment-string</var></dt>
|
|
<dd>An optional character string expression that provides a comment or additional
|
|
location information. The actual length of the character string expression
|
|
must be less than or equal to 254 characters.
|
|
<p>The <span class="italic">comment-string</span> cannot be the null value. If a <span class="italic">comment-string</span> is
|
|
not specified, the <span class="italic">comment-string</span> is the empty string.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>If the first argument can be null, the result can be null; if the first
|
|
argument is null, the result is the null value.</p>
|
|
<p>The result of the function is a DataLink value.</p>
|
|
<p>The CCSID of the DataLink is the same as that of <span class="italic">data-location</span> except in the following cases:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">comment string</span> is mixed data and <span class="italic">data-location</span> is not mixed data, the CCSID of the result will be the
|
|
CCSID of the <span class="italic">comment string</span>.<sup class="fn"><a id="wq638" name="wq638" href="rbafzmstscale.htm#wq639">43</a></sup></li>
|
|
<li>If the <span class="italic">data-location</span> has a CCSID of bit data
|
|
(65535), UTF-16 graphic data (1200), UCS-2 graphic data (13488), Turkish data
|
|
(905 or 1026), or Japanese data (290, 930, or 5026); the CCSID of the result
|
|
is described in the following table:
|
|
<a name="wq640"></a>
|
|
<table id="wq640" width="90%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq641" width="25%" align="left" valign="bottom">CCSID of <span class="italic">data-location</span></th>
|
|
<th id="wq642" width="25%" align="left" valign="bottom">CCSID of <span class="italic">comment-string</span></th>
|
|
<th id="wq643" width="50%" align="left" valign="bottom">Result CCSID</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">65535</td>
|
|
<td align="left" valign="top" headers="wq642">65535</td>
|
|
<td align="left" valign="top" headers="wq643">Job Default CCSID</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">65535</td>
|
|
<td align="left" valign="top" headers="wq642">non-65535</td>
|
|
<td align="left" valign="top" headers="wq643"><span class="italic">comment-string</span> CCSID
|
|
(unless the CCSID is 290, 930, 5026, 905, 1026, or 13488 where the CCSID will
|
|
then be further modified as described in the following rows.)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">290</td>
|
|
<td align="left" valign="top" headers="wq642">any</td>
|
|
<td align="left" valign="top" headers="wq643">4396</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">930 or 5026</td>
|
|
<td align="left" valign="top" headers="wq642">any</td>
|
|
<td align="left" valign="top" headers="wq643">939</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">905 or 1026</td>
|
|
<td align="left" valign="top" headers="wq642">any</td>
|
|
<td align="left" valign="top" headers="wq643">500</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">1200</td>
|
|
<td align="left" valign="top" headers="wq642">any</td>
|
|
<td align="left" valign="top" headers="wq643">500</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq641">13488</td>
|
|
<td align="left" valign="top" headers="wq642">any</td>
|
|
<td align="left" valign="top" headers="wq643">500</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></li></ul>
|
|
<p>When defining a DataLink value using this function, consider the maximum
|
|
length of the target of the value. For example, if a column is defined as
|
|
DataLink(200), then the maximum length of the <span class="italic">data-location</span> plus the comment is 200 bytes.</p>
|
|
<a name="wq644"></a>
|
|
<h4 id="wq644">Examples</h4>
|
|
<ul>
|
|
<li>Insert a row into the table. The URL values for the first two links are
|
|
contained in the variables named url_article and url_snapshot. The variable
|
|
named url_snapshot_comment contains a comment to accompany the snapshot link.
|
|
There is, as yet, no link for the movie, only a comment in the variable named
|
|
url_movie_comment.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> HOCKEY_GOALS
|
|
<span class="bold">VALUES(</span>'Maurice Richard',
|
|
'Montreal canadian',
|
|
'?',
|
|
'Boston Bruins,
|
|
'1952-04-24',
|
|
'Winning goal in game 7 of Stanley Cup final',
|
|
<span class="bold">DLVALUE(</span>:url_article<span class="bold">)</span>,
|
|
<span class="bold">DLVALUE(</span>:url_snapshot, 'URL', :url_snapshot_comment<span class="bold">)</span>,
|
|
<span class="bold">DLVALUE(</span>'', 'URL', :url_movie_comment<span class="bold">) )</span></pre></li></ul>
|
|
<a name="dblprc"></a>
|
|
<h3 id="dblprc"><a href="rbafzmst02.htm#ToC_459">DOUBLE_PRECISION or DOUBLE</a></h3><a id="idx972" name="idx972"></a><a id="idx973" name="idx973"></a><a id="idx974" name="idx974"></a><a id="idx975" name="idx975"></a>
|
|
<a href="rbafzmstscale.htm#syndouble"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq645"></a>
|
|
<div class="fignone" id="wq645">
|
|
<p><span class="bold">Numeric to Double</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn113.htm"
|
|
border="0" /></span><a href="#skipsyn-112"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-DOUBLE_PRECISION-+--(--<span class="italic">numeric-expression</span>--)--------------><
|
|
'-DOUBLE-----------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-112" id="skipsyn-112"></a>
|
|
<p><span class="bold">String to Double</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn114.htm"
|
|
border="0" /></span><a href="#skipsyn-113"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-DOUBLE_PRECISION-+--(--<span class="italic">string-expression</span>--)---------------><
|
|
'-DOUBLE-----------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-113" id="skipsyn-113"></a></div>
|
|
<a name="syndouble"></a>
|
|
<p id="syndouble">The DOUBLE_PRECISION and DOUBLE functions return a floating-point
|
|
representation of: </p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p><span class="bold">Numeric to Double</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric data type.
|
|
<p>The result is the same number that would occur if the expression were assigned
|
|
to a double-precision floating-point column or variable.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">String to Double</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a value that is a character-string or graphic-string
|
|
representation of a number.
|
|
<p>If the argument is a <var class="pv">string-expression</var>,
|
|
the result is the same number that would result from CAST( <var class="pv">string-expression</var> AS DOUBLE PRECISION). Leading and trailing blanks are eliminated and
|
|
the resulting string must conform to the rules for forming a floating-point,
|
|
integer, or decimal constant.</p>
|
|
<p>The single-byte character constant that
|
|
must be used to delimit the decimal digits in <var class="pv">string-expression</var> from
|
|
the whole part of the number is the default decimal point. For more information,
|
|
see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a double-precision floating-point number.
|
|
If the argument can be null, the result can be null; if the argument is null,
|
|
the result is the null value.</p>
|
|
<a name="wq646"></a>
|
|
<h4 id="wq646">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> FLOAT is a synonym for DOUBLE_PRECISION
|
|
and DOUBLE.</p>
|
|
<p>The CAST specification should be used for maximal portability. For more
|
|
information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq647"></a>
|
|
<h4 id="wq647">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, find the ratio of salary to commission for employees
|
|
whose commission is not zero. The columns involved (SALARY and COMM) have
|
|
DECIMAL data types. To eliminate the possibility of out-of-range results,
|
|
DOUBLE_PRECISION is applied to SALARY so that the division is carried out
|
|
in floating point:
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">DOUBLE_PRECISION</span>(SALARY)/COMM
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> COMM > 0</pre></li></ul>
|
|
<a name="scaencrypt"></a>
|
|
<h3 id="scaencrypt"><a href="rbafzmst02.htm#ToC_462">ENCRYPT_RC2</a></h3><a id="idx976" name="idx976"></a><a id="idx977" name="idx977"></a>
|
|
<a href="rbafzmstscale.htm#synencryptrc2"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq648"></a>
|
|
<div class="fignone" id="wq648">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn115.htm"
|
|
border="0" /></span><a href="#skipsyn-114"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ENCRYPT_RC2--(--<span class="italic">data-string</span>--+----------------------------------------+--)-><
|
|
'-,--<span class="italic">password-string</span>--+----------------+-'
|
|
'-,--<span class="italic">hint-string</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-114" id="skipsyn-114"></a></div>
|
|
<a name="synencryptrc2"></a>
|
|
<p id="synencryptrc2">The ENCRYPT_RC2 function returns a value that is the
|
|
result of encrypting <var class="pv">data-string</var> using the RC2 encryption algorithm.
|
|
The password used for decryption is either the <var class="pv">password-string</var> value
|
|
or the encryption password value (assigned by the SET ENCRYPTION PASSWORD
|
|
statement).</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">data-string</var></dt>
|
|
<dd>An expression that returns the string value to be encrypted.
|
|
The string expression must be a built-in string data type.
|
|
<p>The length attribute
|
|
for the data type of <var class="pv">data-string</var> must be less than <var class="pv">m</var> - MOD(<var class="pv">m</var>,8) - <var class="pv">n</var> - 1, where <var class="pv">m</var> is the maximum length of the
|
|
result data type and <var class="pv">n</var> is the amount of overhead necessary to encrypt
|
|
the value.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">password-string</var></dt>
|
|
<dd>An expression that returns a character string value with at least 6
|
|
bytes and no more than 127 bytes. The expression must not be a CLOB. The value
|
|
represents the password used to encrypt the <var class="pv">data-string</var>. If the value
|
|
of the password argument is null or not provided, the data will be encrypted
|
|
using the ENCRYPTION PASSWORD value, which must have been set using the SET
|
|
ENCRYPTION PASSWORD statement.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">hint-string</var></dt>
|
|
<dd>An expression that returns a character string value with
|
|
up to 32 bytes that will help data owners remember passwords (For example,
|
|
'Ocean' is a hint to remember 'Pacific'). The expression must not be a CLOB.
|
|
If a hint value is specified, the hint is embedded into the result and can
|
|
be retrieved using the GETHINT function. If the <var class="pv">password-string</var> is
|
|
specified and this argument is the null value or not provided, no hint will
|
|
be embedded in the result. If the <var class="pv">password-string</var> is not specified,
|
|
the hint may be specified using the SET ENCRYPTION PASSWORD statement.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is determined by the first argument as shown
|
|
in the following table:</p>
|
|
<a name="wq649"></a>
|
|
<table id="wq649" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq650" width="50%" align="left" valign="bottom">Data Type of the First Argument</th>
|
|
<th id="wq651" width="50%" align="left" valign="bottom">Data Type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq650">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq651">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq650">CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq651">VARCHAR FOR BIT DATA</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq650">BLOB, CLOB, or DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq651">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The length attribute of the result depends on the arguments
|
|
that are specified: </p>
|
|
<ul>
|
|
<li>When a <var class="pv">password-string</var> is specified but a <var class="pv">hint-string</var> is
|
|
not specified, the length attribute of <var class="pv">data-string</var> plus 16 plus the
|
|
number of bytes to the next 8 byte boundary.</li>
|
|
<li>Otherwise, the length attribute of <var class="pv">data-string</var> plus 48 plus the
|
|
number of bytes to the next 8 byte boundary.</li></ul>
|
|
<p>The actual length of the result is the actual length of <var class="pv">data-string</var> plus the actual length of the hint plus <var class="pv">n</var>, where <var class="pv">n</var> (the amount of overhead necessary to encrypt the value) is 8 bytes
|
|
(or 16 bytes if <var class="pv">data-string</var> is a LOB or different CCSID values are
|
|
used for the <var class="pv">data-string</var>, the password, or the hint). The actual
|
|
length of the hint is zero if <var class="pv">hint-string</var> is not specified as a function
|
|
argument or on the SET ENCRYPTION PASSWORD statement.</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>Note that the encrypted result is longer than the <var class="pv">data-string</var> value.
|
|
Therefore, when assigning encrypted values, ensure that the target is declared
|
|
with sufficient size to contain the entire encrypted value.</p>
|
|
<a name="wq652"></a>
|
|
<h4 id="wq652">Notes</h4>
|
|
<p><span class="bold">Password protection:</span> To prevent inadvertent access
|
|
to the encryption password, do not specify <var class="pv">password-string</var> as a string
|
|
constant in the source for a program, procedure, or function. Instead, use
|
|
the SET ENCRYPTION PASSWORD statement or a host variable.</p>
|
|
<p>When connected to a remote relational database, the specified password
|
|
itself is sent "in the clear". That is, the password itself is not encrypted.
|
|
To protect the password in these cases, consider using a communications encryption
|
|
mechanism such as IPSEC (or SSL if connecting between iSeries systems).</p>
|
|
<p><span class="bold">Encryption algorithm:</span> The internal encryption algorithm
|
|
used is RC2 block cipher with padding, the 128 bit secret key is derived from
|
|
the password using a MD5 message digest.</p>
|
|
<p><span class="bold">Encryption passwords and data:</span> It is the user's responsibility
|
|
to perform password management. Once the data is encrypted only the password
|
|
used to encrypt it can be used to decrypt it. Be careful when using CHAR variables
|
|
to set password values as they may be padded with blanks. The encrypted result
|
|
may contain a null terminator and other non-printable characters.</p>
|
|
<p><span class="bold">Table column definition:</span> When defining columns and
|
|
distinct types to contain encrypted data:</p>
|
|
<ul>
|
|
<li>The column must be defined with a data type of CHAR FOR BIT DATA, VARCHAR
|
|
FOR BIT DATA, BINARY, VARBINARY, or BLOB.</li>
|
|
<li>The length attribute of the column must include an additional <var class="pv">n</var> bytes,
|
|
where <var class="pv">n</var> is the overhead necessary to encrypt the data as described
|
|
above.</li></ul>
|
|
<p>Any assignment or cast to a column without one of these data
|
|
types or with a length shorter than the suggested data length may result in
|
|
an assignment error or, if the assignment is successful, a failure and lost
|
|
data when the data is subsequently decrypted. Blanks are valid encrypted data
|
|
values that may be truncated when stored in a column that is too short.</p>
|
|
<p>Some sample column length calculations:</p>
|
|
<pre class="xmp">Maximum length of non-encrypted data 6 bytes
|
|
8 bytes 8 bytes (or 16 bytes)
|
|
Number of bytes to the next 8 byte boundary 2 bytes
|
|
--------
|
|
Encrypted data column length 16 bytes (or 32 bytes)
|
|
|
|
|
|
Maximum length of non-encrypted data 32 bytes
|
|
8 bytes 8 bytes (or 16 bytes)
|
|
Number of bytes to the next 8 byte boundary 8 bytes
|
|
--------
|
|
Encrypted data column length 48 bytes (or 56 bytes)</pre>
|
|
<p><span class="bold">Administration of encrypted data:</span> Encrypted data
|
|
can only be decrypted on servers that support the decryption functions that
|
|
correspond to the ENCRYPT_RC2 function. Hence, replication of columns with
|
|
encrypted data should only be done to servers that support the decryption
|
|
functions.</p>
|
|
<p><span class="bold">Syntax alternatives:</span> For compatibility with previous
|
|
versions of DB2, ENCRYPT can be specified in place of ENCRYPT_RC2.</p>
|
|
<a name="wq653"></a>
|
|
<h4 id="wq653">Example</h4>
|
|
<ul>
|
|
<li>Assume that table EMP1 has a social security column called SSN. This example
|
|
uses the ENCRYPTION PASSWORD value to hold the encryption password.
|
|
<pre class="xmp"> <span class="bold">SET ENCRYPTION PASSWORD</span> = 'Ben123'
|
|
|
|
<span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_RC2(</span> '289-46-8832' <span class="bold">)</span>
|
|
</pre></li>
|
|
<li>This example explicitly passes the encryption password.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_RC2(</span> '289-46-8832', 'Ben123' <span class="bold">)</span>
|
|
</pre></li>
|
|
<li>The hint 'Ocean' is stored to help the user remember the encryption password
|
|
'Pacific'.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_RC2(</span> '289-46-8832', 'Pacific', 'Ocean' <span class="bold">)</span>
|
|
</pre></li></ul>
|
|
<a name="scaencrypttdes"></a>
|
|
<h3 id="scaencrypttdes"><a href="rbafzmst02.htm#ToC_465">ENCRYPT_TDES</a></h3><a id="idx978" name="idx978"></a><a id="idx979" name="idx979"></a>
|
|
<a href="rbafzmstscale.htm#synencrypttdesy"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq654"></a>
|
|
<div class="fignone" id="wq654">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn116.htm"
|
|
border="0" /></span><a href="#skipsyn-115"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ENCRYPT_TDES--(--<span class="italic">data-string</span>--+----------------------------------------+--)-><
|
|
'-,--<span class="italic">password-string</span>--+----------------+-'
|
|
'-,--<span class="italic">hint-string</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-115" id="skipsyn-115"></a></div>
|
|
<a name="synencrypttdesy"></a>
|
|
<p id="synencrypttdesy">The ENCRYPT_TDES function returns a value
|
|
that is the result of encrypting <var class="pv">data-string</var> using the Triple DES
|
|
encryption algorithm. The password used for decryption is either the <var class="pv">password-string</var> value or the encryption password value (assigned by the
|
|
SET ENCRYPTION PASSWORD statement).</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">data-string</var></dt>
|
|
<dd>An expression that returns the string value to be encrypted. The string
|
|
expression must be a built-in string data type.
|
|
<p>The length attribute for
|
|
the data type of <var class="pv">data-string</var> must be less than <var class="pv">m</var> - MOD(<var class="pv">m</var>,8) - <var class="pv">n</var> - 1, where <var class="pv">m</var> is the maximum length of the
|
|
result data type and <var class="pv">n</var> is the amount of overhead necessary to encrypt
|
|
the value.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">password-string</var></dt>
|
|
<dd>An expression that returns a character string value with at least 6
|
|
bytes and no more than 127 bytes. The expression must not be a CLOB and the
|
|
CCSID of the expression must not be 65535. The value represents the password
|
|
used to encrypt the <var class="pv">data-string</var>. If the value of the password argument
|
|
is null or not provided, the data will be encrypted using the ENCRYPTION PASSWORD
|
|
value, which must have been set using the SET ENCRYPTION PASSWORD statement.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">hint-string</var></dt>
|
|
<dd>An expression that returns a character string value with
|
|
up to 32 bytes that will help data owners remember passwords (For example,
|
|
'Ocean' is a hint to remember 'Pacific'). The expression must not be a CLOB
|
|
and the CCSID of the expression must not be 65535. If a hint value is specified,
|
|
the hint is embedded into the result and can be retrieved using the GETHINT
|
|
function. If the <var class="pv">password-string</var> is specified and this argument is
|
|
the null value or not provided, no hint will be embedded in the result. If
|
|
the <var class="pv">password-string</var> is not specified, the hint may be specified using
|
|
the SET ENCRYPTION PASSWORD statement.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is determined by the first argument as shown
|
|
in the following table:</p>
|
|
<a name="wq655"></a>
|
|
<table id="wq655" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq656" width="50%" align="left" valign="bottom">Data Type of the First Argument</th>
|
|
<th id="wq657" width="50%" align="left" valign="bottom">Data Type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq656">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq657">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq656">CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq657">VARCHAR FOR BIT DATA</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq656">BLOB, CLOB, or DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq657">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The length attribute of the result depends on the arguments
|
|
that are specified: </p>
|
|
<ul>
|
|
<li>When a <var class="pv">password-string</var> is specified but a <var class="pv">hint-string</var> is
|
|
not specified, the length attribute of <var class="pv">data-string</var> plus 24 plus the
|
|
number of bytes to the next 8 byte boundary.</li>
|
|
<li>Otherwise, the length attribute of <var class="pv">data-string</var> plus 56 plus the
|
|
number of bytes to the next 8 byte boundary.</li></ul>
|
|
<p>The actual length of the result is the actual length of <var class="pv">data-string</var> plus the actual length of the hint plus <var class="pv">n</var>, where <var class="pv">n</var> (the amount of overhead necessary to encrypt the value) is 16 bytes
|
|
(or 24 bytes if <var class="pv">data-string</var> is a LOB or different CCSID values are
|
|
used for the <var class="pv">data-string</var>, the password, or the hint). The actual
|
|
length of the hint is zero if <var class="pv">hint-string</var> is not specified as a function
|
|
argument or on the SET ENCRYPTION PASSWORD statement.</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>Note that the encrypted result is longer than the <var class="pv">data-string</var> value.
|
|
Therefore, when assigning encrypted values, ensure that the target is declared
|
|
with sufficient size to contain the entire encrypted value.</p>
|
|
<a name="wq658"></a>
|
|
<h4 id="wq658">Notes</h4>
|
|
<p><span class="bold">Password protection:</span> To prevent inadvertent access
|
|
to the encryption password, do not specify <var class="pv">password-string</var> as a string
|
|
constant in the source for a program, procedure, or function. Instead, use
|
|
the SET ENCRYPTION PASSWORD statement or a host variable.</p>
|
|
<p>When connected to a remote relational database, the specified password
|
|
itself is sent "in the clear". That is, the password itself is not encrypted.
|
|
To protect the password in these cases, consider using a communications encryption
|
|
mechanism such as IPSEC (or SSL if connecting between iSeries systems).</p>
|
|
<p><span class="bold">Encryption algorithm:</span> The internal encryption algorithm
|
|
used is Triple DES block cipher with padding, the 128 bit secret key is derived
|
|
from the password using a SHA1 message digest.</p>
|
|
<p><span class="bold">Encryption passwords and data:</span> It is the user's responsibility
|
|
to perform password management. Once the data is encrypted only the password
|
|
used to encrypt it can be used to decrypt it. Be careful when using CHAR variables
|
|
to set password values as they may be padded with blanks. The encrypted result
|
|
may contain a null terminator and other non-printable characters.</p>
|
|
<p><span class="bold">Table column definition:</span> When defining columns and
|
|
distinct types to contain encrypted data:</p>
|
|
<ul>
|
|
<li>The column must be defined with a data type of CHAR FOR BIT DATA, VARCHAR
|
|
FOR BIT DATA, BINARY, VARBINARY, or BLOB.</li>
|
|
<li>The length attribute of the column must include an additional <var class="pv">n</var> bytes,
|
|
where <var class="pv">n</var> is the overhead necessary to encrypt the data as described
|
|
above.</li></ul>
|
|
<p>Any assignment or cast to a column without one of these data types or with
|
|
a length shorter than the suggested data length may result in an assignment
|
|
error or, if the assignment is successful, a failure and lost data when the
|
|
data is subsequently decrypted. Blanks are valid encrypted data values that
|
|
may be truncated when stored in a column that is too short.</p>
|
|
<p>Some sample column length calculations:</p>
|
|
<pre class="xmp">Maximum length of non-encrypted data 6 bytes
|
|
16 bytes 16 bytes (or 24 bytes)
|
|
Number of bytes to the next 8 byte boundary 2 bytes
|
|
--------
|
|
Encrypted data column length 24 bytes (or 32 bytes)
|
|
|
|
|
|
Maximum length of non-encrypted data 32 bytes
|
|
16 bytes 16 bytes (or 24 bytes)
|
|
Number of bytes to the next 8 byte boundary 8 bytes
|
|
--------
|
|
Encrypted data column length 56 bytes (or 64 bytes)</pre>
|
|
<p><span class="bold">Administration of encrypted data:</span> Encrypted data
|
|
can only be decrypted on servers that support the decryption functions that
|
|
correspond to the ENCRYPT_TDES function. Hence, replication of columns with
|
|
encrypted data should only be done to servers that support the decryption
|
|
functions.</p>
|
|
<a name="wq659"></a>
|
|
<h4 id="wq659">Example</h4>
|
|
<ul>
|
|
<li>Assume that table EMP1 has a social security column called SSN. This example
|
|
uses the ENCRYPTION PASSWORD value to hold the encryption password.
|
|
<pre class="xmp"> <span class="bold">SET ENCRYPTION PASSWORD</span> = 'Ben123'
|
|
|
|
<span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_TDES(</span> '289-46-8832' <span class="bold">)</span>
|
|
</pre></li>
|
|
<li>This example explicitly passes the encryption password.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_TDES(</span> '289-46-8832', 'Ben123' <span class="bold">)</span>
|
|
</pre></li>
|
|
<li>The hint 'Ocean' is stored to help the user remember the encryption password
|
|
'Pacific'.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_TDES(</span> '289-46-8832', 'Pacific', 'Ocean' <span class="bold">)</span>
|
|
</pre></li></ul>
|
|
<a name="scaexp"></a>
|
|
<h3 id="scaexp"><a href="rbafzmst02.htm#ToC_468">EXP</a></h3><a id="idx980" name="idx980"></a><a id="idx981" name="idx981"></a>
|
|
<a href="rbafzmstscale.htm#synexp"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq660"></a>
|
|
<div class="fignone" id="wq660">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn117.htm"
|
|
border="0" /></span><a href="#skipsyn-116"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-EXP--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-116" id="skipsyn-116"></a></div>
|
|
<a name="synexp"></a>
|
|
<p id="synexp">The EXP function returns a value that is the base of the natural
|
|
logarithm (e) raised to a power specified by the argument. The EXP and LN
|
|
functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq661"></a>
|
|
<h4 id="wq661">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable E is a DECIMAL(10,9) host variable with a value
|
|
of 3.453789832.
|
|
<pre class="xmp"> <span class="bold">SELECT EXP</span>(:E)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 31.62.</li></ul>
|
|
<a name="scaextract"></a>
|
|
<h3 id="scaextract"><a href="rbafzmst02.htm#ToC_470">EXTRACT</a></h3><a id="idx982" name="idx982"></a><a id="idx983" name="idx983"></a>
|
|
<a href="rbafzmstscale.htm#synextract"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq662"></a>
|
|
<div class="fignone" id="wq662">
|
|
<p><span class="bold">Extract Date Values</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn118.htm"
|
|
border="0" /></span><a href="#skipsyn-117"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-EXTRACT--(--+-YEAR--+--FROM--+-<span class="italic">date-expression</span>------+--)----><
|
|
+-MONTH-+ '-<span class="italic">timestamp-expression</span>-'
|
|
'-DAY---'
|
|
|
|
</pre>
|
|
<a name="skipsyn-117" id="skipsyn-117"></a>
|
|
<p><span class="bold">Extract Time Values</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn119.htm"
|
|
border="0" /></span><a href="#skipsyn-118"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-EXTRACT--(--+-HOUR---+--FROM--+-<span class="italic">time-expression</span>------+--)---><
|
|
+-MINUTE-+ '-<span class="italic">timestamp-expression</span>-'
|
|
'-SECOND-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-118" id="skipsyn-118"></a></div>
|
|
<a name="synextract"></a>
|
|
<p id="synextract">The EXTRACT function returns a specified portion of a datetime
|
|
value.</p>
|
|
<p><span class="bold">Extract Date Values</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold">YEAR</dt>
|
|
<dd>Specifies that the year portion of the date or timestamp expression
|
|
is returned. The result is identical to the YEAR scalar function. For more
|
|
information, see <a href="rbafzmstscale.htm#scayear">YEAR</a>.
|
|
</dd>
|
|
<dt class="bold">MONTH</dt>
|
|
<dd>Specifies that the month portion of the date or timestamp expression
|
|
is returned. The result is identical to the MONTH scalar function. For more
|
|
information, see <a href="rbafzmstscale.htm#scamonth">MONTH</a>.
|
|
</dd>
|
|
<dt class="bold">DAY</dt>
|
|
<dd>Specifies that the day portion of the date or timestamp expression is
|
|
returned. The result is identical to the DAY scalar function. For more information,
|
|
see <a href="rbafzmstscale.htm#dayfunc">DAY</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">date-expression</var></dt>
|
|
<dd>An expression that returns the value of either a built-in date or built-in
|
|
character string data type.
|
|
<p>If <var class="pv">expression</var> is a character or graphic
|
|
string, it must not be a CLOB or DBCLOB and its value must be a valid character-string
|
|
or graphic-string representation of a date. For the valid formats of string
|
|
representations of dates, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">timestamp-expression</var></dt>
|
|
<dd>An expression that returns the value of either a built-in timestamp
|
|
or built-in character string data type.
|
|
<p>If <var class="pv">expression</var> is a character
|
|
or graphic string, it must not be a CLOB or DBCLOB and its value must be a
|
|
valid character-string or graphic-string representation of a timestamp. For
|
|
the valid formats of string representations of timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Extract Time Values</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold">HOUR</dt>
|
|
<dd>Specifies that the hour portion of the time or timestamp expression
|
|
is returned. The result is identical to the HOUR scalar function. For more
|
|
information, see <a href="rbafzmstscale.htm#scahour">HOUR</a>.
|
|
</dd>
|
|
<dt class="bold">MINUTE</dt>
|
|
<dd>Specifies that the minute portion of the time or timestamp expression
|
|
is returned. The result is identical to the MINUTE scalar function. For more
|
|
information, see <a href="rbafzmstscale.htm#scaminute">MINUTE</a>.
|
|
</dd>
|
|
<dt class="bold">SECOND</dt>
|
|
<dd>Specifies that the second portion of the date or timestamp expression
|
|
is returned. The result is identical to the following:
|
|
<pre class="xmp">DECIMAL((DAY(expression) + DECIMAL(MICROSECOND(expression),12,6)/1000000), 8,6)</pre> For more information, see <a href="rbafzmstscale.htm#scasec">SECOND</a> and <a href="rbafzmstscale.htm#scamicro">MICROSECOND</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">time-expression</var></dt>
|
|
<dd>An expression that returns the value of either a built-in time or built-in
|
|
character string data type.
|
|
<p>If <var class="pv">expression</var> is a character string,
|
|
it must not be a CLOB and its value must be a valid character-string representation
|
|
of a time. For the valid formats of string representations of times, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">timestamp-expression</var></dt>
|
|
<dd>An expression that returns the value of either a built-in timestamp
|
|
or built-in character string data type.
|
|
<p>If <var class="pv">expression</var> is a character
|
|
string, it must not be a CLOB and its value must be a valid character-string
|
|
representation of a timestamp. For the valid formats of string representations
|
|
of timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result of the function depends on the part of the
|
|
datetime value that is specified:</p>
|
|
<ul>
|
|
<li>If YEAR, MONTH, DAY, HOUR, or MINUTE is specified, the data type of the
|
|
result is INTEGER.</li>
|
|
<li>If SECOND is specified, the data type of the result is DECIMAL(8,6). The
|
|
fractional digits contains microseconds.</li></ul><p class="indatacontent">If the argument can be null, the result can be null; if the argument
|
|
is null, the result is the null value.</p>
|
|
<a name="wq663"></a>
|
|
<h4 id="wq663">Examples</h4>
|
|
<ul>
|
|
<li>Assume the column PRSTDATE has an internal value equivalent to 1988-12-25.
|
|
<pre class="xmp"> <span class="bold">SELECT EXTRACT( MONTH FROM </span>PRSTDATE <span class="bold">)</span>
|
|
<span class="bold">FROM</span> PROJECT</pre> Results in the
|
|
value 12.</li></ul>
|
|
<a name="fltfunc"></a>
|
|
<h3 id="fltfunc"><a href="rbafzmst02.htm#ToC_472">FLOAT</a></h3><a id="idx984" name="idx984"></a><a id="idx985" name="idx985"></a>
|
|
<a href="rbafzmstscale.htm#synfloat"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq664"></a>
|
|
<div class="fignone" id="wq664">
|
|
<p><span class="bold">Numeric to Float</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn120.htm"
|
|
border="0" /></span><a href="#skipsyn-119"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-FLOAT--(--<span class="italic">numeric-expression</span>--)-----------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-119" id="skipsyn-119"></a>
|
|
<p><span class="bold">String to Float</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn121.htm"
|
|
border="0" /></span><a href="#skipsyn-120"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-FLOAT--(--<span class="italic">string-expression</span>--)------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-120" id="skipsyn-120"></a></div>
|
|
<a name="synfloat"></a>
|
|
<p id="synfloat">The FLOAT function returns a floating point representation
|
|
of a number or string.</p>
|
|
<p>FLOAT is a synonym for the DOUBLE_PRECISION and DOUBLE functions. For more
|
|
information, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.</p>
|
|
<a name="scafloor"></a>
|
|
<h3 id="scafloor"><a href="rbafzmst02.htm#ToC_473">FLOOR</a></h3><a id="idx986" name="idx986"></a><a id="idx987" name="idx987"></a>
|
|
<a href="rbafzmstscale.htm#synfloor"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq665"></a>
|
|
<div class="fignone" id="wq665">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn122.htm"
|
|
border="0" /></span><a href="#skipsyn-121"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-FLOOR--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-121" id="skipsyn-121"></a></div>
|
|
<a name="synfloor"></a>
|
|
<p id="synfloor">The FLOOR function returns the largest integer value less
|
|
than or equal to <var class="pv">expression</var>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function has the same data type and length attribute
|
|
of the argument except that the scale is 0 if the argument is a decimal number.
|
|
For example, an argument with a data type of DECIMAL(5,5) will result in DECIMAL(5,0).</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<a name="wq666"></a>
|
|
<h4 id="wq666">Example</h4>
|
|
<ul>
|
|
<li>Use the FLOOR function to truncate any digits to the right of the decimal
|
|
point.
|
|
<pre class="xmp"> <span class="bold">SELECT FLOOR(</span>SALARY<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li>
|
|
<li>Use FLOOR on both positive and negative numbers.
|
|
<pre class="xmp"> <span class="bold">SELECT FLOOR(</span> 3.5<span class="bold">)</span>,
|
|
<span class="bold">FLOOR(</span> 3.1<span class="bold">)</span>,
|
|
<span class="bold">FLOOR(</span>-3.1<span class="bold">)</span>,
|
|
<span class="bold">FLOOR(</span>-3.5<span class="bold">)</span>,
|
|
<span class="bold">FROM</span> <span>SYSIBM.SYSDUMMY1</span></pre>This
|
|
example returns:
|
|
<pre class="xmp">3. 3. -4. -4.</pre>respectively.</li></ul>
|
|
<a name="scagenerateunique"></a>
|
|
<h3 id="scagenerateunique"><a href="rbafzmst02.htm#ToC_475">GENERATE_UNIQUE</a></h3><a id="idx988" name="idx988"></a><a id="idx989" name="idx989"></a>
|
|
<a href="rbafzmstscale.htm#syngenunique"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq667"></a>
|
|
<div class="fignone" id="wq667">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn123.htm"
|
|
border="0" /></span><a href="#skipsyn-122"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GENERATE_UNIQUE--(--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-122" id="skipsyn-122"></a></div>
|
|
<a name="syngenunique"></a>
|
|
<p id="syngenunique">The GENERATE_UNIQUE function returns a bit data character
|
|
string 13 bytes long (CHAR(13) FOR BIT DATA) that is unique compared to any
|
|
other execution of the same function. The function is defined as not-deterministic.</p>
|
|
<p>The result of the function is a unique value that includes the
|
|
internal form of the Universal Time, Coordinated (UTC) and the iSeries system
|
|
serial number. The result cannot be null.</p>
|
|
<p>The result of this function can be used to provide unique values in a table.
|
|
Each successive value will be greater than the previous value, providing a
|
|
sequence that can be used within a table. The sequence is based on the time
|
|
when the function was executed. This function differs from using the special
|
|
register CURRENT TIMESTAMP in that a unique value is generated for each row
|
|
of a multiple row insert statement or an insert statement with a fullselect.</p>
|
|
<p>The timestamp value that is part of the result of this function can be
|
|
determined using the TIMESTAMP function with the result of GENERATE_UNIQUE
|
|
as an argument.</p>
|
|
<a name="wq668"></a>
|
|
<h4 id="wq668">Examples</h4>
|
|
<ul>
|
|
<li>Create a table that includes a column that is unique for each row. Populate
|
|
this column using the GENERATE_UNIQUE function. Notice that the UNIQUE_ID
|
|
column is defined as FOR BIT DATA to identify the column as a bit data character
|
|
string.
|
|
<pre class="xmp"> <span class="bold">CREATE TABLE</span> EMP_UPDATE
|
|
<span class="bold">(</span>UNIQUE_ID <span class="bold">VARCHAR(</span>13<span class="bold">) FOR BIT DATA,</span>
|
|
EMPNO <span class="bold">CHAR(</span>6<span class="bold">),</span>
|
|
TEXT <span class="bold">VARCHAR(</span>1000<span class="bold">))</span>
|
|
|
|
<span class="bold">INSERT INTO</span> EMP_UPDATE <span class="bold">VALUES (GENERATE_UNIQUE(), </span>'000020', 'Update entry 1...'<span class="bold">)</span>
|
|
|
|
<span class="bold">INSERT INTO</span> EMP_UPDATE <span class="bold">VALUES (GENERATE_UNIQUE(), </span>'000050', 'Update entry 2...'<span class="bold">)</span>
|
|
</pre>
|
|
<p>This table will have a unique identifier for each row provided that
|
|
the UNIQUE_ID column is always set using GENERATE_UNIQUE. This can be done
|
|
by introducing a trigger on the table.</p>
|
|
<pre class="xmp"> <span class="bold">CREATE TRIGGER</span> EMP_UPDATE_UNIQUE
|
|
<span class="bold">NO CASCADE BEFORE INSERT ON</span> EMP_UPDATE
|
|
<span class="bold">REFERENCING NEW AS</span> NEW_UPD
|
|
<span class="bold">FOR EACH ROW MODE DB2SQL</span>
|
|
<span class="bold">SET</span> NEW_UPD.UNIQUE_ID <span class="bold">= GENERATE_UNIQUE()</span>
|
|
</pre>
|
|
<p>With this trigger, the previous INSERT statements that were used
|
|
to populate the table can be issued without specifying a value for the UNIQUE_ID
|
|
column:</p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO (</span>EMPNO, TEXT<span class="bold">)</span> EMP_UPDATE <span class="bold">VALUES (</span>'000020', 'Update entry 1...'<span class="bold">)</span>
|
|
|
|
<span class="bold">INSERT INTO (</span>EMPNO, TEXT<span class="bold">)</span> EMP_UPDATE <span class="bold">VALUES (</span>'000050', 'Update entry 2...'<span class="bold">)</span>
|
|
</pre>
|
|
<p>The timestamp (in UTC) for when a row was added to
|
|
EMP_UPDATE can be returned using:</p>
|
|
<pre class="xmp"> <span class="bold">SELECT TIMESTAMP(</span>UNIQUE_ID<span class="bold">)</span>, EMPNO, TEXT <span class="bold">FROM</span> EMP_UPDATE
|
|
</pre>
|
|
<p>Therefore, the table does not need a timestamp column to record
|
|
when a row is inserted.</p></li></ul>
|
|
<a name="scagethint"></a>
|
|
<h3 id="scagethint"><a href="rbafzmst02.htm#ToC_477">GETHINT</a></h3><a id="idx990" name="idx990"></a><a id="idx991" name="idx991"></a>
|
|
<a href="rbafzmstscale.htm#syngethint"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq669"></a>
|
|
<div class="fignone" id="wq669">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn124.htm"
|
|
border="0" /></span><a href="#skipsyn-123"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GETHINT--(--<span class="italic">encrypted-data</span>--)-------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-123" id="skipsyn-123"></a></div>
|
|
<a name="syngethint"></a>
|
|
<p id="syngethint">The GETHINT function will return the password hint if one
|
|
is found in the <var class="pv">encrypted-data</var>. A password hint is a phrase that
|
|
will help data owners remember passwords (For example, 'Ocean' as a hint to
|
|
remember 'Pacific').</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">encrypted-data</var></dt>
|
|
<dd>An expression that must be a string expression that returns
|
|
a complete, encrypted data value of a CHAR FOR BIT DATA, VARCHAR FOR BIT DATA,
|
|
BINARY, VARBINARY, or BLOB built-in data type. The data string must have been
|
|
encrypted using the ENCRYPT_RC2 or ENCRYPT_TDES function.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is VARCHAR(32). The actual length of the result
|
|
is the actual length of the hint that was provided when the data was encrypted.</p>
|
|
<p>The result can be null. If the argument is null or if a hint
|
|
was not added to the <var class="pv">encrypted-data</var> by the ENCRYPT_RC2 or ENCRYPT_TDES
|
|
function, the result is the null value.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current
|
|
server.</p>
|
|
<a name="wq670"></a>
|
|
<h4 id="wq670">Example</h4>
|
|
<ul>
|
|
<li>The hint 'Ocean' is stored to help the user remember the encryption password
|
|
'Pacific'.
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> EMP1 <span class="bold">(</span>SSN<span class="bold">)</span> <span class="bold">VALUES ENCRYPT_RC2(</span> '289-46-8832', 'Pacific', 'Ocean' <span class="bold">)</span>
|
|
|
|
<span class="bold">SELECT GETHINT(</span> SSN <span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMP1</pre>The GETHINT function
|
|
returns the original hint value 'Ocean'.</li></ul>
|
|
<a name="scagraphic"></a>
|
|
<h3 id="scagraphic"><a href="rbafzmst02.htm#ToC_479">GRAPHIC</a></h3><a id="idx992" name="idx992"></a><a id="idx993" name="idx993"></a>
|
|
<a href="rbafzmstscale.htm#syngraphic"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq671"></a>
|
|
<div class="fignone" id="wq671">
|
|
<p><span class="bold">Character to Graphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn125.htm"
|
|
border="0" /></span><a href="#skipsyn-124"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GRAPHIC--(--<span class="italic">character-expression</span>----------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-124" id="skipsyn-124"></a>
|
|
<p><span class="bold">Graphic to Graphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn126.htm"
|
|
border="0" /></span><a href="#skipsyn-125"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GRAPHIC--(--<span class="italic">graphic-expression</span>------------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-125" id="skipsyn-125"></a>
|
|
<p><span class="bold">Integer to Graphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn127.htm"
|
|
border="0" /></span><a href="#skipsyn-126"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GRAPHIC--(--<span class="italic">integer-expression</span>--)---------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-126" id="skipsyn-126"></a>
|
|
<p><span class="bold">Decimal to GRAPHIC</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn128.htm"
|
|
border="0" /></span><a href="#skipsyn-127"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GRAPHIC------------------------------------------------------>
|
|
|
|
>--(--<span class="italic">decimal-expression</span>--+----------------------+--)----------><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-127" id="skipsyn-127"></a>
|
|
<p><span class="bold">Floating-point to GRAPHIC</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn129.htm"
|
|
border="0" /></span><a href="#skipsyn-128"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-GRAPHIC------------------------------------------------------>
|
|
|
|
>--(--<span class="italic">floating-point-expression</span>--+----------------------+--)---><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-128" id="skipsyn-128"></a></div>
|
|
<a name="syngraphic"></a>
|
|
<p id="syngraphic">The GRAPHIC function returns a fixed-length graphic-string
|
|
representation of a string expression.</p>
|
|
<p>The result of the function is a fixed-length graphic string (GRAPHIC).</p>
|
|
<p>If the expression can be null, the result can be null. If the expression
|
|
is null, the result is the null value.</p>
|
|
<p><span class="bold">Character to Graphic</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">character-expression</var></dt>
|
|
<dd>Specifies a character string expression. It cannot be a CHAR or VARCHAR
|
|
bit data. If the expression is an empty string or the EBCDIC string <tt class="xph">X'0E0F'</tt>, the result is an empty string.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
of the result and must be an integer constant between 1 and 16383 if the first
|
|
argument is not nullable or between 1 and 16382 if the first argument is nullable.
|
|
If the length of <var class="pv">character-expression</var> is less than the length specified,
|
|
the result is padded with double-byte blanks to the length of the result.
|
|
<p>If <var class="pv">length</var> is not specified, or if DEFAULT is specified, the length
|
|
attribute of the result is the same as the length attribute of the first argument.</p>
|
|
<p>Each character of the argument determines a character of the result.
|
|
If the length attribute of the resulting fixed-length string is less than
|
|
the actual length of the first argument, truncation is performed and no warning
|
|
is returned.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a DBCS, UTF-16, or UCS-2 CCSID. The CCSID cannot be
|
|
65535. If the CCSID represents UTF-16 or UCS-2 graphic data, each character
|
|
of the argument determines a character of the result. The nth character of
|
|
the result is the UTF-16 or UCS-2 equivalent of the nth character of the argument.
|
|
<p>If <var class="pv">integer</var> is not specified then the CCSID of the result is determined
|
|
by a mixed CCSID. Let M denote that mixed CCSID.</p>
|
|
<p>In the following rules,
|
|
S denotes one of the following: </p>
|
|
<ul>
|
|
<li>If the string expression is a host variable containing data in a foreign
|
|
encoding scheme, S is the result of the expression after converting the data
|
|
to a CCSID in a native encoding scheme. (See <a href="rbafzmstccseta.htm#ccseta">Character conversion</a> for more
|
|
information.)</li>
|
|
<li>If the string expression is data in a native encoding scheme, S is that
|
|
string expression.</li></ul>
|
|
<p>M is determined as follows: </p>
|
|
<ul>
|
|
<li>If the CCSID of S is a mixed CCSID, M is that CCSID.</li>
|
|
<li>If the CCSID of S is an SBCS CCSID:
|
|
<ul>
|
|
<li>If the CCSID of S has an associated mixed CCSID, M is that CCSID.</li>
|
|
<li>Otherwise the operation is not allowed.</li></ul></li></ul>
|
|
<p>The following table summarizes the result CCSID based on M.</p>
|
|
<a name="wq672"></a>
|
|
<table id="wq672" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq673" width="14%" align="left" valign="bottom">M</th>
|
|
<th id="wq674" width="19%" align="left" valign="bottom">Result CCSID</th>
|
|
<th id="wq675" width="28%" align="left" valign="bottom">Description</th>
|
|
<th id="wq676" width="37%" align="left" valign="bottom">DBCS Substitution Character</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">930</td>
|
|
<td align="left" valign="top" headers="wq674">300</td>
|
|
<td align="left" valign="top" headers="wq675">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">933</td>
|
|
<td align="left" valign="top" headers="wq674">834</td>
|
|
<td align="left" valign="top" headers="wq675">Korean EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">935</td>
|
|
<td align="left" valign="top" headers="wq674">837</td>
|
|
<td align="left" valign="top" headers="wq675">S-Chinese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">937</td>
|
|
<td align="left" valign="top" headers="wq674">835</td>
|
|
<td align="left" valign="top" headers="wq675">T-Chinese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">939</td>
|
|
<td align="left" valign="top" headers="wq674">300</td>
|
|
<td align="left" valign="top" headers="wq675">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">5026</td>
|
|
<td align="left" valign="top" headers="wq674">4396</td>
|
|
<td align="left" valign="top" headers="wq675">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq673">5035</td>
|
|
<td align="left" valign="top" headers="wq674">4396</td>
|
|
<td align="left" valign="top" headers="wq675">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq676">X'FEFE'</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The equivalence of SBCS and DBCS characters depends on M. Regardless
|
|
of the CCSID, every double-byte code point in the argument is considered a
|
|
DBCS character, and every single-byte code point in the argument is considered
|
|
an SBCS character with the exception of the EBCDIC mixed data shift codes <tt class="xph">X'0E'</tt> and <tt class="xph">X'0F'</tt>. </p>
|
|
<ul>
|
|
<li>If the nth character of the argument is a DBCS character, the nth character
|
|
of the result is that DBCS character.</li>
|
|
<li>If the nth character of the argument is an SBCS character that has an
|
|
equivalent DBCS character, the nth character of the result is that equivalent
|
|
DBCS character.</li>
|
|
<li>If the nth character of the argument is an SBCS character that does not
|
|
have an equivalent DBCS character, the nth character of the result is the
|
|
DBCS substitution character.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Graphic to Graphic</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">graphic-expression</var></dt>
|
|
<dd>Specifies a graphic string expression.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
of the result and must be an integer constant between 1 and 16383 if the first
|
|
argument is not nullable or between 1 and 16382 if the first argument is nullable.
|
|
If the length of <var class="pv">graphic-expression</var> is less than the length specified,
|
|
the result is padded with double-byte blanks to the length of the result.
|
|
<p>If the second argument is not specified, or if DEFAULT is specified, the length
|
|
attribute of the result is the same as the length attribute of the first argument.</p>
|
|
<p>If the length of the <var class="pv">graphic-expression</var> is greater than the
|
|
length attribute of the result, truncation is performed. A warning (SQLSTATE
|
|
01004) is returned unless the truncated characters were all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a DBCS, UTF-16, or UCS-2 CCSID. The CCSID cannot be
|
|
65535.
|
|
<p>If <var class="pv">integer</var> is not specified then the CCSID of the result
|
|
is the CCSID of the first argument.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Integer to Graphic</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">integer-expression</var></dt>
|
|
<dd>An expression that returns a value that is an integer data type (either
|
|
SMALLINT, INTEGER, or BIGINT).
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a fixed-length graphic string of the argument in the
|
|
form of an SQL integer constant. The result consists of n characters that
|
|
are the significant digits that represent the value of the argument with a
|
|
preceding minus sign if the argument is negative. It is left justified.</p>
|
|
<ul>
|
|
<li>If the argument is a small integer, the length attribute of the result
|
|
is 6.</li>
|
|
<li>If the argument is a large integer, the length attribute of the result
|
|
is 11.</li>
|
|
<li>If the argument is a big integer, the length attribute of the result is
|
|
20.</li></ul>
|
|
<p>The result is the smallest number of characters that can be used to represent
|
|
the value of the argument. Leading zeroes are not included. If the argument
|
|
is negative, the first character of the result is a minus sign. Otherwise,
|
|
the first character is a digit.</p>
|
|
<p>The CCSID of the result is 1200 (UTF-16).</p>
|
|
<p><span class="bold">Decimal to Graphic</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">decimal-expression</var></dt>
|
|
<dd>An expression that returns a value that is a packed or zoned decimal
|
|
data type (either DECIMAL or NUMERIC). If a different precision and scale
|
|
is desired, the DECIMAL scalar function can be used to make the change.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a fixed-length graphic string representation of the
|
|
argument. The result includes a decimal character and up to <var class="pv">p</var> digits,
|
|
where <var class="pv">p</var> is the precision of the <var class="pv">decimal-expression</var> with
|
|
a preceding minus sign if the argument is negative. Leading zeros are not
|
|
returned. Trailing zeros are returned.</p>
|
|
<p>The length attribute of the result is 2+<var class="pv">p</var> where <var class="pv">p</var> is
|
|
the precision of the <var class="pv">decimal-expression</var>. The result is the smallest
|
|
number of characters that can be used to represent the result. Leading zeros
|
|
are not included. If the argument is negative, the result begins with a minus
|
|
sign. Otherwise, the result begins with a digit.</p>
|
|
<p> The CCSID of the result is 1200 (UTF-16).</p>
|
|
<p><span class="bold">Floating-point to Graphic</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">floating-point expression</var></dt>
|
|
<dd>An expression that returns a value that is a floating-point data type
|
|
(DOUBLE or REAL).
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a fixed-length graphic string representation of the
|
|
argument in the form of a floating-point constant.</p>
|
|
<p>The length attribute of the result is 24. The result is the smallest number
|
|
of characters that can represent the value of the argument such that the mantissa
|
|
consists of a single digit other than zero followed by the <var class="pv">decimal-character</var> and a sequence of digits. If the argument is negative, the first character
|
|
of the result is a minus sign; otherwise, the first character is a digit.
|
|
If the argument is zero, the result is 0E0.</p>
|
|
<p>The CCSID of the result is 1200 (UTF-16).</p>
|
|
<a name="wq677"></a>
|
|
<h4 id="wq677">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> If the length attribute is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq678"></a>
|
|
<h4 id="wq678">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, set the host variable DESC (GRAPHIC(24)) to
|
|
the GRAPHIC equivalent of the first name (FIRSTNME) for employee number (EMPNO)
|
|
'000050'.
|
|
<pre class="xmp"> <span class="bold">SELECT GRAPHIC( VARGRAPHIC(</span>FIRSTNME<span class="bold">))</span>
|
|
<span class="bold">INTO</span> :DESC
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO = '000050'</pre></li></ul>
|
|
<a name="scahash"></a>
|
|
<h3 id="scahash"><a href="rbafzmst02.htm#ToC_482">HASH</a></h3><a id="idx994" name="idx994"></a><a id="idx995" name="idx995"></a>
|
|
<a href="rbafzmstscale.htm#synhash"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq679"></a>
|
|
<div class="fignone" id="wq679">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn130.htm"
|
|
border="0" /></span><a href="#skipsyn-129"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .-,----------.
|
|
V |
|
|
>>-HASH--(----<span class="italic">expression</span>-+--)----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-129" id="skipsyn-129"></a></div>
|
|
<a name="synhash"></a>
|
|
<p id="synhash">The HASH function returns the partition number of a set of
|
|
values. Also see the PARTITION function. For more information about partition
|
|
numbers, see the <a href="../dbmult/rzaf3kickoff.htm">DB2 Multisystem</a> book.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments can be any built-in data type except date, time, timestamp,
|
|
floating-point, or DataLink values.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer with a value between 0 and
|
|
1023.</p>
|
|
<p>If any of the arguments are null, the result is zero. The result cannot
|
|
be null.</p>
|
|
<a name="wq680"></a>
|
|
<h4 id="wq680">Example</h4>
|
|
<ul>
|
|
<li>Use the HASH function to determine what the partitions would be if the
|
|
partitioning key was composed of EMPNO and LASTNAME. This query returns the
|
|
partition number for every row in EMPLOYEE.
|
|
<pre class="xmp"> <span class="bold">SELECT HASH(</span>EMPNO, LASTNAME<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scapartition"></a>
|
|
<h3 id="scapartition"><a href="rbafzmst02.htm#ToC_484">HASHED_VALUE</a></h3><a id="idx996" name="idx996"></a><a id="idx997" name="idx997"></a><a id="idx998" name="idx998"></a><a id="idx999" name="idx999"></a>
|
|
<a href="rbafzmstscale.htm#synpartition"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq681"></a>
|
|
<div class="fignone" id="wq681">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn131.htm"
|
|
border="0" /></span><a href="#skipsyn-130"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-HASHED_VALUE--(--<span class="italic">table-designator</span>--)------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-130" id="skipsyn-130"></a></div>
|
|
<a name="synpartition"></a>
|
|
<p id="synpartition">The HASHED_VALUE function returns the partition map index
|
|
number of a row obtained by applying the hashing function on the partitioning
|
|
key value of the row. Also see the HASH function. If the argument identifies
|
|
a non-distributed table, the value 0 is returned. For more information about
|
|
partition maps and partitioning keys, see the <a href="../dbmult/rzaf3kickoff.htm">DB2 Multisystem</a> book.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">table-designator</var></dt>
|
|
<dd>The argument must be a table designator of the subselect. For more information
|
|
about table designators, see <a href="rbafzmstch2col.htm#tdjm">Table designators</a>.
|
|
<p>In SQL naming,
|
|
the table name may be qualified. In system naming, the table name cannot
|
|
be qualified.</p>
|
|
<p>If the argument identifies a view, common table expression,
|
|
or derived table, the function returns the partition map index number of its
|
|
base table. If the argument identifies a view, common table expression, or
|
|
derived table derived from more than one base table, the function returns
|
|
the partition map index number of the first table in the outer subselect of
|
|
the view, common table expression, or derived table.</p>
|
|
<p>The
|
|
argument must not identify a view, common table expression, or derived table
|
|
whose outer subselect includes an aggregate function, a GROUP BY clause, a
|
|
HAVING clause, a UNION clause, an INTERSECT clause, or DISTINCT clause. If
|
|
the subselect contains a GROUP BY or HAVING clause, the HASHED_VALUE function
|
|
can only be specified in the WHERE clause or as an operand of an aggregate
|
|
function. If the argument is a correlation name, the correlation name must
|
|
not identify a correlated reference.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is a large integer with a value between 0 and
|
|
1023. The result can be null.</p>
|
|
<a name="wq682"></a>
|
|
<h4 id="wq682">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> PARTITION is a synonym for HASHED_VALUE.</p>
|
|
<a name="wq683"></a>
|
|
<h4 id="wq683">Example</h4>
|
|
<ul>
|
|
<li>Select the employee number (EMPNO) from the EMPLOYEE table for all rows
|
|
where the partition map index number is equal to 100.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE HASHED_VALUE(</span>EMPLOYEE<span class="bold">)</span> = 100</pre></li></ul>
|
|
<a name="scahex"></a>
|
|
<h3 id="scahex"><a href="rbafzmst02.htm#ToC_487">HEX</a></h3><a id="idx1000" name="idx1000"></a><a id="idx1001" name="idx1001"></a>
|
|
<a href="rbafzmstscale.htm#synhex"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq684"></a>
|
|
<div class="fignone" id="wq684">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn132.htm"
|
|
border="0" /></span><a href="#skipsyn-131"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-HEX--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-131" id="skipsyn-131"></a></div>
|
|
<a name="synhex"></a>
|
|
<p id="synhex">The HEX function returns a hexadecimal representation of a
|
|
value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument can be of any built-in data type.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a character string. If the argument can be
|
|
null, the result can be null; if the argument is null, the result is the null
|
|
value.</p>
|
|
<p>The result is a string of hexadecimal digits, the first two digits represent
|
|
the first byte of the argument, the next two digits represent the second byte
|
|
of the argument, and so forth. If the argument is a datetime value, the result
|
|
is the hexadecimal representation of the internal form of the argument.<sup class="fn"><a id="wq685" name="wq685" href="rbafzmstscale.htm#wq686">44</a></sup></p>
|
|
<p>If the argument is not a graphic string, the actual length of
|
|
the result is twice the length of the argument. If the argument is a graphic
|
|
string, the actual length of the result is four times the length of the argument.
|
|
The length of the argument is the value that would be returned if the argument
|
|
were passed to the LENGTH scalar function. For more information, see <a href="rbafzmstscale.htm#scalength">LENGTH</a>.</p>
|
|
<p>The data type and length attribute of the result depends on
|
|
the attributes of the argument:</p>
|
|
<ul>
|
|
<li>If the argument is not a string, the result is CHAR with a length attribute
|
|
that is twice the length of the argument.</li>
|
|
<li>If the argument is a fixed-length character string with a length
|
|
attribute that is less than one half the maximum length attribute of CHAR,
|
|
the result is CHAR with a length attribute that is twice the length attribute
|
|
of the argument. If the argument is a fixed-length graphic string with a length
|
|
attribute that is less than one fourth the maximum length attribute of GRAPHIC,
|
|
the result is GRAPHIC with a length attribute that is four times the length
|
|
attribute of the argument. For more information on the product-specific maximum
|
|
length, see <a href="rbafzmstlimtabs.htm#btable2">Table 78</a>.</li>
|
|
<li>Otherwise, the result is VARCHAR whose length attribute depends on the
|
|
following:
|
|
<ul>
|
|
<li>If the argument is a character or binary string, the length attribute
|
|
of the result is twice the length attribute of the argument.</li>
|
|
<li>If the argument is a graphic string, the length attribute of the result
|
|
is four times the length attribute of the argument.</li></ul></li></ul>
|
|
<p>The length attribute of the result cannot be greater than the
|
|
product-specific length attribute of CHAR or VARCHAR. See <a href="rbafzmstlimtabs.htm#btable2">Table 78</a> for
|
|
more information.</p>
|
|
<p>The CCSID of the string is the default SBCS CCSID at the current server.</p>
|
|
<a name="wq687"></a>
|
|
<h4 id="wq687">Example</h4>
|
|
<ul>
|
|
<li>Use the HEX function to return a hexadecimal representation of the education
|
|
level for each employee.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> FIRSTNME, MIDINIT, LASTNAME, <span class="bold">HEX</span>(EDLEVEL)
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scahour"></a>
|
|
<h3 id="scahour"><a href="rbafzmst02.htm#ToC_489">HOUR</a></h3><a id="idx1002" name="idx1002"></a><a id="idx1003" name="idx1003"></a>
|
|
<a href="rbafzmstscale.htm#synhour"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq688"></a>
|
|
<div class="fignone" id="wq688">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn133.htm"
|
|
border="0" /></span><a href="#skipsyn-132"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-HOUR--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-132" id="skipsyn-132"></a></div>
|
|
<a name="synhour"></a>
|
|
<p id="synhour">The HOUR function returns the hour part of a value.</p>
|
|
<p></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a time, a timestamp, a character string, a
|
|
graphic string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
time or timestamp. For the valid formats of string representations of times
|
|
and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a time duration or timestamp
|
|
duration. For the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a time, timestamp, or valid character-string representation
|
|
of a time or timestamp:
|
|
<p>The result is the hour part of the value, which
|
|
is an integer between 0 and 24.</p></li>
|
|
<li>If the argument is a time duration or timestamp duration:
|
|
<p>The result
|
|
is the hour part of the value, which is an integer between -99 and 99.
|
|
A nonzero result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq689"></a>
|
|
<h4 id="wq689">Example</h4>
|
|
<ul>
|
|
<li>Using the CL_SCHED sample table, select all the classes that start
|
|
in the afternoon.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> CL_SCHED
|
|
<span class="bold">WHERE HOUR(</span>STARTING<span class="bold">) BETWEEN</span> 12 <span class="bold">AND</span> 17</pre></li></ul>
|
|
<a name="scaidentity"></a>
|
|
<h3 id="scaidentity"><a href="rbafzmst02.htm#ToC_491">IDENTITY_VAL_LOCAL</a></h3><a id="idx1004" name="idx1004"></a><a id="idx1005" name="idx1005"></a>
|
|
<a href="rbafzmstscale.htm#synidentity"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq690"></a>
|
|
<div class="fignone" id="wq690">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn134.htm"
|
|
border="0" /></span><a href="#skipsyn-133"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-IDENTITY_VAL_LOCAL--(--)------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-133" id="skipsyn-133"></a></div>
|
|
<a name="synidentity"></a>
|
|
<p id="synidentity">IDENTITY_VAL_LOCAL is a non-deterministic function that
|
|
returns the most recently assigned value for an identity column.</p>
|
|
<p>The function has no input parameters. The result is a DECIMAL(31,0) regardless
|
|
of the actual data type of the identity column that the result value corresponds
|
|
to.</p>
|
|
<p>The value returned is the value that was assigned to the identity column
|
|
of the table identified in the most recent INSERT statement for a table containing
|
|
an identity column. The INSERT statement has to be issued at the same level;
|
|
that is, the value has to be available locally within the level at which it
|
|
was assigned until replaced by the next assigned value. A new level is initiated
|
|
when a trigger, function, or stored procedure is invoked. A trigger condition
|
|
is at the same level as the associated triggered action.</p>
|
|
<p>The assigned value can be a value supplied by the user (if the identity
|
|
column is defined as GENERATED BY DEFAULT) or an identity value that was generated
|
|
by the database manager.</p>
|
|
<p>The result can be null. The result is null if an INSERT statement has not
|
|
been issued for a table containing an identity column at the current processing
|
|
level. This includes invoking the function in a before or after insert trigger.</p>
|
|
<p>The result of the IDENTITY_VAL_LOCAL function is not affected by the following
|
|
statements:</p>
|
|
<ul>
|
|
<li>An INSERT statement for a table which does not contain an identity column</li>
|
|
<li>An UPDATE statement</li>
|
|
<li>A COMMIT statement</li>
|
|
<li>A ROLLBACK statement</li></ul>
|
|
<a name="wq691"></a>
|
|
<h4 id="wq691">Notes</h4>
|
|
<p>The following notes explain the behavior of the function when it is invoked
|
|
in various situations:</p>
|
|
<dl>
|
|
<dt class="bold">Invoking the function within the VALUES clause of an INSERT
|
|
statement</dt>
|
|
<dd>Expressions in an INSERT statement are evaluated before values are assigned
|
|
to the target columns of the INSERT statement. Thus, when you invoke IDENTITY_VAL_LOCAL
|
|
in an INSERT statement, the value that is used is the most recently assigned
|
|
value for an identity column from a previous INSERT statement. The function
|
|
returns the null value if no such INSERT statement had been executed within
|
|
the same level as the invocation of the IDENTITY_VAL_LOCAL function.
|
|
</dd>
|
|
<dt class="bold">Invoking the function following a failed INSERT statement</dt>
|
|
<dd>The function returns an unpredictable result when it is invoked after
|
|
the unsuccessful execution of an INSERT statement for a table with an identity
|
|
column. The value might be the value that would have been returned from the
|
|
function had it been invoked before the failed INSERT or the value that would
|
|
have been assigned had the INSERT succeeded. The actual value returned depends
|
|
on the point of failure and is therefore unpredictable.
|
|
</dd>
|
|
<dt class="bold">Invoking the function within the SELECT statement of a cursor</dt>
|
|
<dd>Because the results of the IDENTITY_VAL_LOCAL function are not deterministic,
|
|
the result of an invocation of the IDENTITY_VAL_LOCAL function from within
|
|
the SELECT statement of a cursor can vary for each FETCH statement.
|
|
</dd>
|
|
<dt class="bold">Invoking the function within the trigger condition of an insert
|
|
trigger</dt>
|
|
<dd>The result of invoking the IDENTITY_VAL_LOCAL function from within the
|
|
condition of an insert trigger is the null value.
|
|
</dd>
|
|
<dt class="bold">Invoking the function within a triggered action of an insert
|
|
trigger</dt>
|
|
<dd>Multiple before or after insert triggers can exist for a table. In such
|
|
cases, each trigger is processed separately, and identity values generated
|
|
by SQL statements issued within a triggered action are not available to other
|
|
triggered actions using the IDENTITY_VAL_LOCAL function. This is the case
|
|
even though the multiple triggered actions are conceptually defined at the
|
|
same level.
|
|
<p>Do not use the IDENTITY_VAL_LOCAL function in the triggered
|
|
action of a before insert trigger. The result of invoking the IDENTITY_VAL_LOCAL
|
|
function from within the triggered action of a before insert trigger is the
|
|
null value. The value for the identity column of the table for which the trigger
|
|
is defined cannot be obtained by invoking the IDENTITY_VAL_LOCAL function
|
|
within the triggered action of a before insert trigger. However, the value
|
|
for the identity column can be obtained in the triggered action by referencing
|
|
the trigger transition variable for the identity column.</p>
|
|
<p>The result
|
|
of invoking the IDENTITY_VAL_LOCAL function in the triggered action of an
|
|
after insert trigger is the value assigned to an identity column of the table
|
|
identified in the most recent INSERT statement invoked in the same triggered
|
|
action for a table containing an identity column. If an INSERT statement for
|
|
a table containing an identity column was not executed within the same triggered
|
|
action before invoking the IDENTITY_VAL_LOCAL function, then the function
|
|
returns a null value.</p>
|
|
</dd>
|
|
<dt class="bold">Invoking the function following an INSERT with triggered actions</dt>
|
|
<dd>The result of invoking the function after an INSERT that activates triggers
|
|
is the value actually assigned to the identity column (that is, the value
|
|
that would be returned on a subsequent SELECT statement). This value is not
|
|
necessarily the value provided in the INSERT statement or a value generated
|
|
by the database manager. The assigned value could be a value that was specified in a SET
|
|
transition variable statement within the triggered action of a before insert
|
|
trigger for a trigger transition variable associated with the identity column.
|
|
</dd>
|
|
</dl>
|
|
<a name="wq692"></a>
|
|
<h4 id="wq692">Examples</h4>
|
|
<ul>
|
|
<li>Set the variable IVAR to the value assigned to the identity column in
|
|
the EMPLOYEE table. The value returned from the function in the VALUES statement
|
|
should be 1.
|
|
<pre class="xmp"> <span class="bold">CREATE TABLE</span> EMPLOYEE
|
|
<span class="bold">(</span>EMPNO <span class="bold">INTEGER GENERATED ALWAYS AS IDENTITY,</span>
|
|
NAME <span class="bold">CHAR(</span>30<span class="bold">),</span>
|
|
SALARY <span class="bold">DECIMAL(</span>5,2<span class="bold">),</span>
|
|
DEPT <span class="bold">SMALLINT)</span>
|
|
|
|
<span class="bold">INSERT INTO</span> EMPLOYEE
|
|
<span class="bold">(</span>NAME, SALARY, DEPTNO<span class="bold">)</span>
|
|
<span class="bold">VALUES(</span>'Rupert', 989.99, 50<span class="bold">)</span>
|
|
|
|
<span class="bold">VALUES IDENTITY_VAL_LOCAL() INTO </span> :IVAR
|
|
</pre></li>
|
|
<li>Assume two tables, T1 and T2, have an identity column named C1. The database manager generates
|
|
values 1, 2, 3,...for the C1 column in table T1, and values 10, 11, 12,...for
|
|
the C1 column in table T2.
|
|
<pre class="xmp"> <span class="bold">CREATE TABLE</span> T1
|
|
<span class="bold">(</span>C1 <span class="bold">SMALLINT GENERATED ALWAYS AS IDENTITY,</span>
|
|
C2 <span class="bold">SMALLINT)</span>
|
|
|
|
<span class="bold">CREATE TABLE</span> T2
|
|
<span class="bold">(</span>C1 <span class="bold">DECIMAL(</span>15,0<span class="bold">) GENERATED BY DEFAULT AS IDENTITY</span> <span class="bold">( START WITH </span>10<span class="bold"> ) ,</span>
|
|
C2 <span class="bold">SMALLINT)</span>
|
|
|
|
<span class="bold">INSERT INTO</span> T1 <span class="bold">(</span> C2 <span class="bold">)</span> <span class="bold">VALUES(</span>5<span class="bold">)</span>
|
|
|
|
<span class="bold">INSERT INTO</span> T1 <span class="bold">(</span> C2 <span class="bold">)</span> <span class="bold">VALUES(</span>5<span class="bold">)</span>
|
|
|
|
<span class="bold">SELECT </span> * <span class="bold">FROM</span> T1</pre>
|
|
<a name="wq693"></a>
|
|
<table id="wq693" width="90%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq694" width="50%" align="center" valign="bottom">C1</th>
|
|
<th id="wq695" width="50%" align="center" valign="bottom">C2</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq694">1</td>
|
|
<td align="center" valign="top" headers="wq695">5</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq694">2</td>
|
|
<td align="center" valign="top" headers="wq695">5</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<pre class="xmp"> <span class="bold">VALUES IDENTITY_VAL_LOCAL() INTO </span> :IVAR
|
|
</pre>
|
|
<p>At this point, the IDENTITY_VAL_LOCAL function would return a value
|
|
of 2 in IVAR. The following INSERT statement inserts a single row into T2
|
|
where column C2 gets a value of 2 from the IDENTITY_VAL_LOCAL function.</p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> T2 <span class="bold">(</span> C2 <span class="bold">)</span> <span class="bold">VALUES( IDENTITY_VAL_LOCAL() )</span>
|
|
|
|
<span class="bold">SELECT </span> * <span class="bold">FROM</span> T2
|
|
<span class="bold">WHERE</span> C1 <span class="bold">= DECIMAL( IDENTITY_VAL_LOCAL(),</span> 15, 0<span class="bold">)</span></pre>
|
|
<a name="wq696"></a>
|
|
<table id="wq696" width="90%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq697" width="50%" align="center" valign="bottom">C1</th>
|
|
<th id="wq698" width="50%" align="center" valign="bottom">C2</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq697">10</td>
|
|
<td align="center" valign="top" headers="wq698">2</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>Invoking the IDENTITY_VAL_LOCAL function after this INSERT would
|
|
result in a value of 10, which is the value generated by the database manager for column
|
|
C1 of T2. Assume another single row is inserted into T2. For the following
|
|
INSERT statement, the database manager assigns a value of 13 to identity column C1 and
|
|
gives C2 a value of 10 from IDENTITY_VAL_LOCAL. Thus, C2 is given the last
|
|
identity value that was inserted into T2.</p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> T2 <span class="bold">(</span> C2, C1 <span class="bold">)</span> <span class="bold">VALUES( IDENTITY_VAL_LOCAL(),</span> 13 <span class="bold">)</span>
|
|
|
|
<span class="bold">SELECT </span> * <span class="bold">FROM</span> T2
|
|
<span class="bold">WHERE</span> C1 <span class="bold">= DECIMAL( IDENTITY_VAL_LOCAL(),</span> 15, 0<span class="bold">)</span></pre>
|
|
<a name="wq699"></a>
|
|
<table id="wq699" width="90%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq700" width="50%" align="center" valign="bottom">C1</th>
|
|
<th id="wq701" width="50%" align="center" valign="bottom">C2</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq700">13</td>
|
|
<td align="center" valign="top" headers="wq701">10</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></li>
|
|
<li>The IDENTITY_VAL_LOCAL function can also be invoked in an INSERT statement
|
|
that both invokes the IDENTITY_VAL_LOCAL function and causes a new value for
|
|
an identity column to be assigned. The next value to be returned is thus established
|
|
when the IDENTITY_VAL_LOCAL function is invoked after the INSERT statement
|
|
completes. For example, consider the following table definition:
|
|
<pre class="xmp"> <span class="bold">CREATE TABLE</span> T3
|
|
<span class="bold">(</span>C1 <span class="bold">SMALLINT GENERATED BY DEFAULT AS IDENTITY,</span>
|
|
C2 <span class="bold">SMALLINT)</span>
|
|
</pre>
|
|
<p>For the following INSERT statement, specify a value of 25 for the
|
|
C2 column, and the database manager generates a value of 1 for C1, the identity column.
|
|
This establishes 1 as the value that will be returned on the next invocation
|
|
of the IDENTITY_VAL_LOCAL function.</p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> T3 <span class="bold">(</span> C2 <span class="bold">)</span> <span class="bold">VALUES(</span> 25 <span class="bold">)</span>
|
|
</pre>
|
|
<p>In the following INSERT statement, the IDENTITY_VAL_LOCAL function
|
|
is invoked to provide a value for the C2 column. A value of 1 (the identity
|
|
value assigned to the C1 column of the first row) is assigned to the C2 column,
|
|
and the database manager generates a value of 2 for C1, the identity column. This establishes
|
|
2 as the value that will be returned on the next invocation of the IDENTITY_VAL_LOCAL
|
|
function.</p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> T3 <span class="bold">(</span> C2 <span class="bold">)</span> <span class="bold">VALUES( IDENTITY_VAL_LOCAL() )</span>
|
|
</pre>
|
|
<p>In the following INSERT statement, the IDENTITY_VAL_LOCAL function
|
|
is again invoked to provide a value for the C2 column, and the user provides
|
|
a value of 11 for C1, the identity column. A value of 2 (the identity value
|
|
assigned to the C1 column of the second row) is assigned to the C2 column.
|
|
The assignment of 11 to C1 establishes 11 as the value that will be returned
|
|
on the next invocation of the IDENTITY_VAL_LOCAL function.</p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> T3 <span class="bold">(</span> C2, C1 <span class="bold">)</span> <span class="bold">VALUES( IDENTITY_VAL_LOCAL(),</span> 11 <span class="bold">)</span>
|
|
</pre>
|
|
<p>After the 3 INSERT statements have been processed, table T3 contains
|
|
the following:</p>
|
|
<a name="wq702"></a>
|
|
<table id="wq702" width="90%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq703" width="50%" align="center" valign="bottom">C1</th>
|
|
<th id="wq704" width="50%" align="center" valign="bottom">C2</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq703">1</td>
|
|
<td align="center" valign="top" headers="wq704">25</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq703">2</td>
|
|
<td align="center" valign="top" headers="wq704">1</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" valign="top" headers="wq703">11</td>
|
|
<td align="center" valign="top" headers="wq704">2</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The contents of T3 illustrate that the expressions in the VALUES
|
|
clause are evaluated before the assignments for the columns of the INSERT
|
|
statement. Thus, an invocation of an IDENTITY_VAL_LOCAL function invoked from
|
|
a VALUES clause of an INSERT statement uses the most recently assigned value
|
|
for an identity column in a previous INSERT statement.</p></li></ul>
|
|
<a name="scaifnull"></a>
|
|
<h3 id="scaifnull"><a href="rbafzmst02.htm#ToC_494">IFNULL</a></h3><a id="idx1006" name="idx1006"></a><a id="idx1007" name="idx1007"></a>
|
|
<a href="rbafzmstscale.htm#synifnull"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq705"></a>
|
|
<div class="fignone" id="wq705">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn135.htm"
|
|
border="0" /></span><a href="#skipsyn-134"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-IFNULL--(--<span class="italic">expression</span>--,--<span class="italic">expression</span>--)---------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-134" id="skipsyn-134"></a></div>
|
|
<a name="synifnull"></a>
|
|
<p id="synifnull">The IFNULL function returns the value of the first non-null
|
|
expression.</p>
|
|
<p>The IFNULL function is identical to the COALESCE scalar function with two
|
|
arguments. For more information, see <a href="rbafzmstscale.htm#scacoales">COALESCE</a>.</p>
|
|
<a name="wq706"></a>
|
|
<h4 id="wq706">Example</h4>
|
|
<ul>
|
|
<li>When selecting the employee number (EMPNO) and salary (SALARY) from all
|
|
the rows in the EMPLOYEE table, if the salary is missing (that is, null),
|
|
then return a value of zero.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">IFNULL</span>(SALARY,0)
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scainsert"></a>
|
|
<h3 id="scainsert"><a href="rbafzmst02.htm#ToC_496">INSERT</a></h3><a id="idx1008" name="idx1008"></a><a id="idx1009" name="idx1009"></a>
|
|
<a href="rbafzmstscale.htm#synscainsert"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq707"></a>
|
|
<div class="fignone" id="wq707">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn136.htm"
|
|
border="0" /></span><a href="#skipsyn-135"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-INSERT--(--<span class="italic">source-string</span>--,--<span class="italic">start</span>--,--<span class="italic">length</span>--,--<span class="italic">insert-string</span>--)-><
|
|
|
|
</pre>
|
|
<a name="skipsyn-135" id="skipsyn-135"></a></div>
|
|
<a name="synscainsert"></a>
|
|
<p id="synscainsert">Returns a string where <var class="pv">length</var> characters have
|
|
been deleted from <var class="pv">source-string</var> beginning at <var class="pv">start</var> and where <var class="pv">insert-string</var> has been inserted into <var class="pv">source-string</var> beginning
|
|
at <var class="pv">start</var>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">source-string</var></dt>
|
|
<dd>An expression that specifies the source string. The <var class="pv">source-string</var> may be any built-in numeric or string expression. It must be compatible
|
|
with the <span class="italic">insert-string</span>. For more information about
|
|
data type compatibility, see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>. A numeric argument is
|
|
cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
The actual length of the string must be greater than zero.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">start</var></dt>
|
|
<dd>An expression that returns a built-in BIGINT, INTEGER, or
|
|
SMALLINT data type. The integer specifies the starting point within <var class="pv">source-string</var> where the deletion of characters and the insertion of another string
|
|
is to begin. The value of the integer must be in the range of 1 to the length
|
|
of <var class="pv">source-string</var> plus one.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd>An expression that returns a built-in BIGINT, INTEGER, or
|
|
SMALLINT data type. The integer specifies the number of characters that are
|
|
to be deleted from <var class="pv">source-string</var>, starting at the position identified
|
|
by <var class="pv">start</var>. The value of the integer must be in the range of 0 to the
|
|
length of <var class="pv">source-string</var>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">insert-string</var></dt>
|
|
<dd>An expression that specifies the string to be inserted into <var class="pv">source-string</var>, starting at the position identified by <var class="pv">start</var>. The <var class="pv">insert-string</var> may be any built-in numeric or string expression. It must be compatible
|
|
with the <span class="italic">source-string</span>. For more information about
|
|
data type compatibility, see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>. A numeric argument is
|
|
cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
The actual length of the string must be greater than zero.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result of the function depends on the data type of
|
|
the first and fourth arguments. The result data type is the same as if the
|
|
two arguments were concatenated except that the result is always a varying-length
|
|
string. For more information see <a href="rbafzmstuuall.htm#uuall">Conversion rules for operations that combine strings</a>.</p>
|
|
<p>The length attribute of the result depends on the arguments:</p>
|
|
<ul>
|
|
<li>If <var class="pv">start</var> and <var class="pv">length</var> are constants, the length attribute
|
|
of the result is:
|
|
<pre class="xmp">L1 - MIN((L1-V2 + 1), V3) + L4
|
|
</pre> where:
|
|
<pre class="xmp">L1 is the length attribute of source-string
|
|
V2 is the value of start
|
|
V3 is the value of length
|
|
L4 is the length attribute of insert-string
|
|
|
|
</pre></li>
|
|
<li>Otherwise, the length attribute of the result is the length attribute
|
|
of <var class="pv">source-string</var> plus the length attribute of <var class="pv">insert-string</var>.</li></ul><p class="indatacontent">If the length attribute of the result exceeds the maximum for the result
|
|
data type, an error is returned.</p>
|
|
<p>The actual length of the result is:</p>
|
|
<pre class="xmp">A1 - MIN((A1 -V2 + 1), V3) + A4
|
|
|
|
</pre><p class="indatacontent">where:</p>
|
|
<pre class="xmp">A1 is the actual length of source-string
|
|
V2 is the value of start
|
|
V3 is the value of length
|
|
A4 is the actual length of insert-string
|
|
</pre>
|
|
<p>If the actual length of the result string exceeds the maximum for the result
|
|
data type, an error is returned.</p>
|
|
<p>If any argument can be null, the result can be null; if any argument is
|
|
null, the result is the null value.</p>
|
|
<p>The CCSID of the result is determined by the CCSID of <var class="pv">source-string</var> and <var class="pv">insert-string</var>. The resulting CCSID is the same as if the
|
|
two arguments were concatenated. For more information, see <a href="rbafzmstuuall.htm#uuall">Conversion rules for operations that combine strings</a>.</p>
|
|
<a name="wq708"></a>
|
|
<h4 id="wq708">Examples</h4>
|
|
<ul>
|
|
<li>The following example shows how the string 'INSERTING' can be changed
|
|
into other strings. The use of the CHAR function limits the length of the
|
|
resulting string to 10 characters.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(INSERT(</span>'INSERTING', 4, 2, 'IS'<span class="bold">)</span>, 10<span class="bold">)</span>,
|
|
<span class="bold"> CHAR(INSERT(</span>'INSERTING', 4, 0, 'IS'<span class="bold">)</span>, 10<span class="bold">)</span>,
|
|
<span class="bold"> CHAR(INSERT(</span>'INSERTING', 4, 2, ''<span class="bold">)</span>, 10<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>This example returns 'INSISTING ', 'INSISERTIN', and 'INSTING '.</li>
|
|
<li>The previous example demonstrated how to insert text into the middle of
|
|
some text. This example shows how to insert text before some text by using
|
|
1 as the starting point (<var class="pv">start</var>).
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(INSERT(</span>'INSERTING', 1, 0, 'XX'<span class="bold">)</span>, 10<span class="bold">)</span>,
|
|
<span class="bold"> CHAR(INSERT(</span>'INSERTING', 1, 1, 'XX'<span class="bold">)</span>, 10<span class="bold">)</span>,
|
|
<span class="bold"> CHAR(INSERT(</span>'INSERTING', 1, 2, 'XX'<span class="bold">)</span>, 10<span class="bold">)</span>,
|
|
<span class="bold"> CHAR(INSERT(</span>'INSERTING', 1, 3, 'XX'<span class="bold">)</span>, 10<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>This example returns 'XXINSERTIN', 'XXNSERTING', 'XXSERTING ', and 'XXERTING
|
|
'.</li>
|
|
<li>The following example shows how to insert text after some text. Add 'XX'
|
|
at the end of string 'ABCABC'. Because the source string is 6 characters long,
|
|
set the starting position to 7 (one plus the length of the source string).
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(INSERT(</span>'ABCABC', 7, 0, 'XX'<span class="bold">)</span>, 10<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>This example returns 'ABCABCXX '.</li></ul>
|
|
<a name="intfunc"></a>
|
|
<h3 id="intfunc"><a href="rbafzmst02.htm#ToC_498">INTEGER or INT</a></h3><a id="idx1010" name="idx1010"></a><a id="idx1011" name="idx1011"></a>
|
|
<a href="rbafzmstscale.htm#synint"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq709"></a>
|
|
<div class="fignone" id="wq709">
|
|
<p><span class="bold">Numeric to Integer</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn137.htm"
|
|
border="0" /></span><a href="#skipsyn-136"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-INTEGER-+--(--<span class="italic">numeric-expression</span>--)-----------------------><
|
|
'-INT-----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-136" id="skipsyn-136"></a>
|
|
<p><span class="bold">String to Integer</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn138.htm"
|
|
border="0" /></span><a href="#skipsyn-137"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-INTEGER-+--(--<span class="italic">string-expression</span>--)------------------------><
|
|
'-INT-----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-137" id="skipsyn-137"></a></div>
|
|
<a name="synint"></a>
|
|
<p id="synint">The INTEGER function returns an integer representation of:</p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p><span class="bold">Numeric to Integer</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>An expression that returns a numeric value of any built-in numeric data
|
|
type.
|
|
<p>If the argument is a <var class="pv">numeric-expression</var>, the result is the
|
|
same number that would occur if the argument were assigned to a large integer
|
|
column or variable. If the whole part of the argument is not within the range
|
|
of integers, an error is returned. The fractional part of the argument is
|
|
truncated.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">String to Integer</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a value that is a character-string or graphic-string
|
|
representation of a number.
|
|
<p>If the argument is a <var class="pv">string-expression</var>,
|
|
the result is the same number that would result from CAST( <var class="pv">string-expression</var> AS INTEGER). Leading and trailing blanks are eliminated and the resulting
|
|
string must conform to the rules for forming a floating-point, integer, or
|
|
decimal constant. If the whole part of the argument is not within the range
|
|
of integers, an error is returned. Any fractional part of the argument is
|
|
truncated.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq710"></a>
|
|
<h4 id="wq710">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq711"></a>
|
|
<h4 id="wq711">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, select a list containing salary (SALARY) divided
|
|
by education level (EDLEVEL). Truncate any decimal in the calculation. The
|
|
list should also contain the values used in the calculation and the employee
|
|
number (EMPNO).
|
|
<pre class="xmp"> <span class="bold">SELECT INTEGER</span>(SALARY / EDLEVEL), SALARY, EDLEVEL, EMPNO
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scajulian"></a>
|
|
<h3 id="scajulian"><a href="rbafzmst02.htm#ToC_501">JULIAN_DAY</a></h3><a id="idx1012" name="idx1012"></a><a id="idx1013" name="idx1013"></a>
|
|
<a href="rbafzmstscale.htm#synjulian"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq712"></a>
|
|
<div class="fignone" id="wq712">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn139.htm"
|
|
border="0" /></span><a href="#skipsyn-138"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-JULIAN_DAY--(--<span class="italic">expression</span>--)--------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-138" id="skipsyn-138"></a></div>
|
|
<a name="synjulian"></a>
|
|
<p id="synjulian">The JULIAN_DAY function returns an integer value representing
|
|
a number of days from January 1, 4713 B.C. (the start of the Julian date calendar)
|
|
to the date specified in the argument.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, a
|
|
graphic string, or a numeric data type. If <var class="pv">expression</var> is a character
|
|
or graphic string, it must not be a CLOB or DBCLOB and its value must be a
|
|
valid string representation of a date or timestamp. For the valid formats
|
|
of string representations of dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument
|
|
can be null, the result can be null; if the argument is null, the result is
|
|
the null value.</p>
|
|
<a name="wq713"></a>
|
|
<h4 id="wq713">Examples</h4>
|
|
<ul>
|
|
<li>Using sample table EMPLOYEE, set the integer host variable JDAY to the
|
|
Julian day of the day that Christine Haas (EMPNO = '000010') was employed
|
|
(HIREDATE = '1965-01-01').
|
|
<pre class="xmp"> <span class="bold">SELECT JULIAN_DAY(</span>HIREDATE<span class="bold">)</span>
|
|
<span class="bold">INTO</span> :JDAY
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO = '000010'</pre>The result is that JDAY
|
|
is set to 2438762.</li>
|
|
<li>Set integer host variable JDAY to the Julian day for January 1, 1998.
|
|
<pre class="xmp"> <span class="bold">SELECT JULIAN_DAY(</span>'1998-01-01'<span class="bold">)</span>
|
|
<span class="bold">INTO</span> :JDAY
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>The result is that JDAY
|
|
is set to 2450815.</li></ul>
|
|
<a name="scaland"></a>
|
|
<h3 id="scaland"><a href="rbafzmst02.htm#ToC_503">LAND</a></h3><a id="idx1014" name="idx1014"></a><a id="idx1015" name="idx1015"></a>
|
|
<a href="rbafzmstscale.htm#synland"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq714"></a>
|
|
<div class="fignone" id="wq714">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn140.htm"
|
|
border="0" /></span><a href="#skipsyn-139"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-LAND--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)-------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-139" id="skipsyn-139"></a></div>
|
|
<a name="synland"></a>
|
|
<p id="synland">The LAND function returns a string that is the logical 'AND'
|
|
of the argument strings. This function takes the first argument string, does
|
|
an AND operation with the next string, and then continues to do AND operations
|
|
with each successive argument using the previous result. If a character-string
|
|
or graphic-string argument is encountered that is shorter than the previous
|
|
result, it is padded with blanks. If a binary-string argument is encountered
|
|
that is shorter than the previous result, it is padded with hexadecimal zeros.</p>
|
|
<p>The arguments must be compatible.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be expressions that return a value of any built-in
|
|
numeric or string data type, but cannot be LOBs. The arguments cannot be mixed
|
|
data character strings, UTF-8 character strings, or graphic strings. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The arguments are converted, if necessary, to the attributes of the result.
|
|
The attributes of the result are determined as follows: </p>
|
|
<ul>
|
|
<li>If all the arguments are fixed-length strings, the result is a fixed-length
|
|
string of length <span class="italic">n</span>, where <span class="italic">n</span> is
|
|
the length of the longest argument.</li>
|
|
<li>If any argument is a varying-length string, the result is a varying-length
|
|
string with length attribute <span class="italic">n</span>, where <span class="italic">n</span> is the length attribute of the argument with greatest length attribute.
|
|
The actual length of the result is <span class="italic">m</span>, where <span class="italic">m</span> is the actual length of the longest argument.</li></ul>
|
|
<p>If an argument can be null, the result can be null; if an argument is null,
|
|
the result is the null value.</p>
|
|
<p>The CCSID of the result is 65535.</p>
|
|
<a name="wq715"></a>
|
|
<h4 id="wq715">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable L1 is a CHARACTER(2) host variable
|
|
with a value of X'A1B1', host variable L2 is a CHARACTER(3) host variable
|
|
with a value of X'F0F040', and host variable L3 is a CHARACTER(4) host variable
|
|
with a value of X'A1B10040'.
|
|
<pre class="xmp"> <span class="bold">SELECT LAND</span>(:L1,:L2,:L3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value X'A0B00040'.</li></ul>
|
|
<a name="scalastday"></a>
|
|
<h3 id="scalastday"><a href="rbafzmst02.htm#ToC_505">LAST_DAY</a></h3><a id="idx1016" name="idx1016"></a><a id="idx1017" name="idx1017"></a>
|
|
<a href="rbafzmstscale.htm#synlastday"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq716"></a>
|
|
<div class="fignone" id="wq716">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn141.htm"
|
|
border="0" /></span><a href="#skipsyn-140"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LAST_DAY--(--<span class="italic">expression</span>--)----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-140" id="skipsyn-140"></a></div>
|
|
<a name="synlastday"></a>
|
|
<p id="synlastday">The LAST_DAY scalar function returns a date that represents
|
|
the last day of the month indicated by <var class="pv">expression</var>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a date. If either argument can be null, the
|
|
result can be null; if either argument is null, the result is the null value.</p>
|
|
<a name="wq717"></a>
|
|
<h4 id="wq717">Example</h4>
|
|
<ul>
|
|
<li>Set the host variable END_OF_MONTH with the last day of the current month.
|
|
<pre class="xmp"><span class="bold">SET </span>:END_OF_MONTH <span class="bold">= LAST_DAY(CURRENT_DATE)</span></pre>
|
|
<p>The host variable END_OF_MONTH is set with the value representing
|
|
the end of the current month. If the current day is 2000-02-10, then END_OF_MONTH
|
|
is set to 2000-02-29.</p></li>
|
|
<li>Set the host variable END_OF_MONTH with the last day of the month in EUR
|
|
format for the given date.
|
|
<pre class="xmp"><span class="bold">SET </span>:END_OF_MONTH <span class="bold">= CHAR(LAST_DAY(</span>'1965-07-07'<span class="bold">), EUR)</span></pre>
|
|
<p>The host variable END_OF_MONTH is set with the value '31.07.1965'.</p></li>
|
|
<li>Assuming that the default date format is ISO,
|
|
<pre class="xmp"><span class="bold">SELECT LAST_DAY(</span>'2000-04-24'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Returns '2000–04–30'
|
|
which is the last day of April in 2000.</p></li></ul>
|
|
<a name="scalcase"></a>
|
|
<h3 id="scalcase"><a href="rbafzmst02.htm#ToC_507">LCASE</a></h3><a id="idx1018" name="idx1018"></a><a id="idx1019" name="idx1019"></a>
|
|
<a href="rbafzmstscale.htm#synlcase"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq718"></a>
|
|
<div class="fignone" id="wq718">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn142.htm"
|
|
border="0" /></span><a href="#skipsyn-141"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LCASE--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-141" id="skipsyn-141"></a></div>
|
|
<a name="synlcase"></a>
|
|
<p id="synlcase">The LCASE function returns a string in which all the characters
|
|
have been converted to lowercase characters, based on the CCSID of the argument.</p>
|
|
<p>The LCASE function is identical to the LOWER function. For more information,
|
|
see <a href="rbafzmstscale.htm#scalower">LOWER</a>.</p>
|
|
<a name="scaleft"></a>
|
|
<h3 id="scaleft"><a href="rbafzmst02.htm#ToC_508">LEFT</a></h3><a id="idx1020" name="idx1020"></a><a id="idx1021" name="idx1021"></a>
|
|
<a href="rbafzmstscale.htm#synleft"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq719"></a>
|
|
<div class="fignone" id="wq719">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn143.htm"
|
|
border="0" /></span><a href="#skipsyn-142"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LEFT--(--<span class="italic">expression</span>--,--<span class="italic">integer</span>--)--------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-142" id="skipsyn-142"></a></div>
|
|
<a name="synleft"></a>
|
|
<p id="synleft">The LEFT function returns the leftmost <var class="pv">integer</var> characters
|
|
of <var class="pv">expression</var>.</p>
|
|
<p>If <var class="pv">expression</var> is a character string, the result is a character
|
|
string, and each character is one byte. If <var class="pv">expression</var> is a graphic
|
|
string, the result is a graphic string, and each character is a DBCS, UTF-16,
|
|
or UCS-2 character. If <var class="pv">expression</var> is a binary string, the result
|
|
is a binary string, and each character is one byte.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string from which the result is derived.
|
|
The arguments must be expressions that return a value of any built-in numeric,
|
|
character string, graphic string, or a binary string data type. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
<p>A substring of <var class="pv">expression</var> is zero or more contiguous characters of <var class="pv">expression</var>. If <var class="pv">expression</var> is a graphic string, a character is
|
|
a DBCS, UTF–16, or UCS-2 character. If <var class="pv">expression</var> is a character
|
|
string or binary string, a character is a byte.<sup class="fn"><a id="wq720" name="wq720" href="rbafzmstscale.htm#wq721">45</a></sup></p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd>An expression that returns a built-in integer data type. The integer
|
|
specifies the length of the result. The value of <var class="pv">integer</var> must be
|
|
greater than or equal to 0 and less than or equal to <var class="pv">n</var>, where <var class="pv">n</var> is the length attribute of <var class="pv">expression</var>.
|
|
<p>The <var class="pv">expression</var> is effectively padded on the right with the necessary number of blank
|
|
characters (or hexadecimal zeroes for binary strings) so that the specified
|
|
substring of <var class="pv">expression</var> always exists.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a varying-length string with a length attribute
|
|
that is the same as the length attribute of <var class="pv">expression</var> and a data
|
|
type that depends on the data type of <var class="pv">expression</var>: </p>
|
|
<a name="wq722"></a>
|
|
<table id="wq722" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq723" width="50%" align="left" valign="bottom">Data type of <span class="italic">expression</span></th>
|
|
<th id="wq724" width="50%" align="left" valign="bottom">Data type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq723">CHAR or VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq724">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq723">CLOB</td>
|
|
<td align="left" valign="top" headers="wq724">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq723">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq724">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq723">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq724">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq723">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq724">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq723">BLOB</td>
|
|
<td align="left" valign="top" headers="wq724">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The actual length of the result is <var class="pv">integer</var>.</p>
|
|
<p>If any argument can be null, the result can be null; if any argument is
|
|
null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the same as that of <var class="pv">expression</var>.</p>
|
|
<a name="wq725"></a>
|
|
<h4 id="wq725">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable NAME (VARCHAR(50)) has a value of 'KATIE
|
|
AUSTIN' and the host variable FIRSTNAME_LEN (int) has a value of 5.
|
|
<pre class="xmp"> <span class="bold">SELECT LEFT(</span>:NAME, :FIRSTNAME_LEN<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 'KATIE'</li></ul>
|
|
<a name="scalength"></a>
|
|
<h3 id="scalength"><a href="rbafzmst02.htm#ToC_510">LENGTH</a></h3><a id="idx1022" name="idx1022"></a><a id="idx1023" name="idx1023"></a>
|
|
<a href="rbafzmstscale.htm#synlength"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq726"></a>
|
|
<div class="fignone" id="wq726">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn144.htm"
|
|
border="0" /></span><a href="#skipsyn-143"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LENGTH--(--<span class="italic">expression</span>--)------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-143" id="skipsyn-143"></a></div>
|
|
<a name="synlength"></a>
|
|
<p id="synlength">The LENGTH function returns the length of a value. See <a href="rbafzmstscale.htm#charlenf">CHARACTER_LENGTH</a>, <a href="rbafzmstscale.htm#scaoctetlen">OCTET_LENGTH</a>, and <a href="rbafzmstscale.htm#scabitlen">BIT_LENGTH</a> for
|
|
similar functions.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
data type.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The result is the length of the argument. The length of strings includes
|
|
blanks. The length of a varying-length string is the actual length, not the
|
|
length attribute.</p>
|
|
<p>The length of a graphic string is the number of double-byte characters
|
|
(the number of bytes divided by 2). The length of all other values is the
|
|
number of bytes used to represent the value:</p>
|
|
<ul>
|
|
<li>2 for small integer</li>
|
|
<li>4 for large integer</li>
|
|
<li>8 for big integer</li>
|
|
<li>The integral part of (<var class="pv">p</var>/2)+1 for packed decimal numbers with
|
|
precision <var class="pv">p</var></li>
|
|
<li><var class="pv">p</var> for zoned decimal numbers with precision <var class="pv">p</var></li>
|
|
<li>4 for single-precision float</li>
|
|
<li>8 for double-precision float</li>
|
|
<li>The length of the string for strings</li>
|
|
<li>3 for time</li>
|
|
<li>4 for date</li>
|
|
<li>10 for timestamp</li>
|
|
<li>The actual number of bytes used to store the DataLink value (plus 19 if
|
|
the DataLink is FILE LINK CONTROL and READ PERMISSION DB) for datalinks</li>
|
|
<li>26 for row ID</li></ul>
|
|
<a name="wq727"></a>
|
|
<h4 id="wq727">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable ADDRESS is a varying-length character string
|
|
with a value of '895 Don Mills Road'.
|
|
<pre class="xmp"> <span class="bold">SELECT LENGTH(</span>:ADDRESS<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 18.</li>
|
|
<li>Assume that PRSTDATE is a column of type DATE.
|
|
<pre class="xmp"> <span class="bold">SELECT LENGTH(</span>PRSTDATE<span class="bold">)</span>
|
|
<span class="bold">FROM</span> PROJECT</pre> Returns the value
|
|
4.</li>
|
|
<li>Assume that PRSTDATE is a column of type DATE.
|
|
<pre class="xmp"> <span class="bold">SELECT LENGTH(CHAR(</span>PRSTDATE, <span class="bold">EUR))</span>
|
|
<span class="bold">FROM</span> PROJECT</pre>Returns the value
|
|
10.</li></ul>
|
|
<a name="scaln"></a>
|
|
<h3 id="scaln"><a href="rbafzmst02.htm#ToC_512">LN</a></h3><a id="idx1024" name="idx1024"></a><a id="idx1025" name="idx1025"></a>
|
|
<a href="rbafzmstscale.htm#synln"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq728"></a>
|
|
<div class="fignone" id="wq728">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn145.htm"
|
|
border="0" /></span><a href="#skipsyn-144"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LN--(--<span class="italic">expression</span>--)----------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-144" id="skipsyn-144"></a></div>
|
|
<a name="synln"></a>
|
|
<p id="synln">The LN function returns the natural logarithm of a number. The
|
|
LN and EXP functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. The value of the argument must be greater than
|
|
zero.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq729"></a>
|
|
<h4 id="wq729">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable NATLOG is a DECIMAL(4,2) host variable with a
|
|
value of 31.62.
|
|
<pre class="xmp"> <span class="bold">SELECT LN</span>(:NATLOG)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 3.45.</li></ul>
|
|
<a name="scalnot"></a>
|
|
<h3 id="scalnot"><a href="rbafzmst02.htm#ToC_514">LNOT</a></h3><a id="idx1026" name="idx1026"></a><a id="idx1027" name="idx1027"></a>
|
|
<a href="rbafzmstscale.htm#synlnot"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq730"></a>
|
|
<div class="fignone" id="wq730">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn146.htm"
|
|
border="0" /></span><a href="#skipsyn-145"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LNOT--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-145" id="skipsyn-145"></a></div>
|
|
<a name="synlnot"></a>
|
|
<p id="synlnot">The LNOT function returns a string that is the logical NOT
|
|
of the argument string.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be expressions that return a value of any built-in
|
|
numeric or string data type, but cannot be LOBs. The arguments cannot be mixed
|
|
data character strings, UTF-8 character strings, or graphic strings. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type and length attribute of the result is the same as the data
|
|
type and length attribute of the argument value. If the argument is a varying-length
|
|
string, the actual length of the result is the same as the actual length of
|
|
the argument value. If the argument can be null, the result can be null; if
|
|
the argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is 65535.</p>
|
|
<a name="wq731"></a>
|
|
<h4 id="wq731">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable L1 is a CHARACTER(2) host variable with a value
|
|
of X'F0F0'.
|
|
<pre class="xmp"> <span class="bold">SELECT LNOT</span>(:L1)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value X'0F0F'.</li></ul>
|
|
<a name="locate"></a>
|
|
<h3 id="locate"><a href="rbafzmst02.htm#ToC_516">LOCATE</a></h3><a id="idx1028" name="idx1028"></a><a id="idx1029" name="idx1029"></a>
|
|
<a href="rbafzmstscale.htm#synlocate"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq732"></a>
|
|
<div class="fignone" id="wq732">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn147.htm"
|
|
border="0" /></span><a href="#skipsyn-146"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LOCATE--(--<span class="italic">search-string</span>--,--<span class="italic">source-string</span>--+----------+--)-><
|
|
'-,--<span class="italic">start</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-146" id="skipsyn-146"></a></div>
|
|
<a name="synlocate"></a>
|
|
<p id="synlocate">The LOCATE function returns the starting position of the
|
|
first occurrence of one string (called the <var class="pv">search-string</var>) within
|
|
another string (called the <var class="pv">source-string</var>). If the <span class="italic">search-string</span> is not found and neither argument is null, the result is
|
|
zero. If the <span class="italic">search-string</span> is found, the result is
|
|
a number from 1 to the actual length of the <span class="italic">source-string</span>. If the optional <var class="pv">start</var> is specified, it indicates the character
|
|
position in the <span class="italic">source-string</span> at which the search
|
|
is to begin.</p>
|
|
<p></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">search-string</var></dt>
|
|
<dd>An expression that specifies the string that is to be searched for. <var class="pv">Search-string</var> may be any built-in numeric or string expression. It must
|
|
be compatible with the <span class="italic">source-string</span>. A numeric argument
|
|
is cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">source-string</var></dt>
|
|
<dd>An expression that specifies the source string in which the search is
|
|
to take place. <var class="pv">Source-string</var> may be any built-in numeric or string
|
|
expression. A numeric argument is cast to a character string before evaluating
|
|
the function. For more information on converting numeric to a character string,
|
|
see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">start</var></dt>
|
|
<dd>An expression that specifies the position within <var class="pv">source-string</var> at
|
|
which the search is to start. It must be an integer that is greater than or
|
|
equal to zero.
|
|
<p>If <var class="pv">start</var> is specified, the function is
|
|
similar to:</p>
|
|
<pre class="xmp"> <span class="bold">POSSTR( SUBSTR(</span><var class="pv">source-string</var>,<var class="pv">start</var><span class="bold">)</span> , <var class="pv">search-string</var> <span class="bold">)</span> + <var class="pv">start</var> - 1</pre>
|
|
<p>If <var class="pv">start</var> is not specified,
|
|
the function is equivalent to:</p>
|
|
<pre class="xmp"> <span class="bold">POSSTR( </span><var class="pv">source-string</var> , <var class="pv">search-string</var> <span class="bold">)</span></pre>
|
|
<p>For more information, see <a href="rbafzmstscale.htm#posstr">POSITION or POSSTR</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If any of the arguments
|
|
can be null, the result can be null; if any of the arguments is null, the
|
|
result is the null value.</p>
|
|
<p>If the CCSID of the <var class="pv">search-string</var> is different than the CCSID
|
|
of the <var class="pv">source-string</var>, it is converted to the CCSID of the <var class="pv">source-string</var>.</p>
|
|
<p>If a sort sequence other than *HEX is in effect when the statement that
|
|
contains the LOCATE function is executed and the arguments are SBCS data,
|
|
mixed data, or Unicode data, then the result is obtained by comparing weighted
|
|
values for each value in the set. The weighted values are based on the sort
|
|
sequence. An ICU sort sequence table may not be specified with the LOCATE
|
|
function.</p>
|
|
<a name="wq733"></a>
|
|
<h4 id="wq733">Example</h4>
|
|
<ul>
|
|
<li>Select RECEIVED and SUBJECT columns as well as the starting position of
|
|
the words 'GOOD' within the NOTE_TEXT column for all entries in the IN_TRAY
|
|
table that contain these words.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> RECEIVED, SUBJECT, <span class="bold">LOCATE(</span>'GOOD', NOTE_TEXT<span class="bold">)</span>
|
|
<span class="bold">FROM</span> IN_TRAY
|
|
<span class="bold">WHERE LOCATE(</span>'GOOD', NOTE_TEXT<span class="bold">)</span> <> 0</pre></li></ul>
|
|
<a name="scalog"></a>
|
|
<h3 id="scalog"><a href="rbafzmst02.htm#ToC_518">LOG10</a></h3><a id="idx1030" name="idx1030"></a><a id="idx1031" name="idx1031"></a><a id="idx1032" name="idx1032"></a><a id="idx1033" name="idx1033"></a>
|
|
<a href="rbafzmstscale.htm#synlog10"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq734"></a>
|
|
<div class="fignone" id="wq734">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn148.htm"
|
|
border="0" /></span><a href="#skipsyn-147"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LOG10--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-147" id="skipsyn-147"></a></div>
|
|
<a name="synlog10"></a>
|
|
<p id="synlog10">The LOG10 function returns the common logarithm (base 10)
|
|
of a number. The LOG10 and ANTILOG functions are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq735"></a>
|
|
<h4 id="wq735">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> LOG is a synonym for LOG10.
|
|
It is supported only for compatibility with previous DB2 releases. LOG10 should be used instead
|
|
of LOG because some database managers and applications implement LOG as the
|
|
natural logarithm of a number instead of the common logarithm of a number.</p>
|
|
<a name="wq736"></a>
|
|
<h4 id="wq736">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable L is a DECIMAL(4,2) host variable with a value
|
|
of 31.62.
|
|
<pre class="xmp"> <span class="bold">SELECT LOG10</span>(:L)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 1.49.</li></ul>
|
|
<a name="scalor"></a>
|
|
<h3 id="scalor"><a href="rbafzmst02.htm#ToC_521">LOR</a></h3><a id="idx1034" name="idx1034"></a><a id="idx1035" name="idx1035"></a>
|
|
<a href="rbafzmstscale.htm#synlor"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq737"></a>
|
|
<div class="fignone" id="wq737">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn149.htm"
|
|
border="0" /></span><a href="#skipsyn-148"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-LOR--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-148" id="skipsyn-148"></a></div>
|
|
<a name="synlor"></a>
|
|
<p id="synlor">The LOR function returns a string that is the logical OR of
|
|
the argument strings. This function takes the first argument string, does
|
|
an OR operation with the next string, and then continues to do OR operations
|
|
for each successive argument using the previous result. If a character-string
|
|
or graphic-string argument is encountered that is shorter than the previous
|
|
result, it is padded with blanks. If a binary-string argument is encountered
|
|
that is shorter than the previous result, it is padded with hexadecimal zeros.</p>
|
|
<p>The arguments must be compatible.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be expressions that return a value of any built-in
|
|
numeric or string data type, but cannot be LOBs. The arguments cannot be mixed
|
|
data character strings, UTF-8 character strings, or graphic strings. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The arguments are converted, if necessary, to the attributes of the result.
|
|
The attributes of the result are determined as follows: </p>
|
|
<ul>
|
|
<li>If all the arguments are fixed-length strings, the result is a fixed-length
|
|
string of length <span class="italic">n</span>, where <span class="italic">n</span> is
|
|
the length of the longest argument.</li>
|
|
<li>If any argument is a varying-length string, the result is a varying-length
|
|
string with length attribute <span class="italic">n</span>, where <span class="italic">n</span> is the length attribute of the argument with greatest length attribute.
|
|
The actual length of the result is <span class="italic">m</span>, where <span class="italic">m</span> is the actual length of the longest argument.</li></ul>
|
|
<p>If an argument can be null, the result can be null; if an argument is null,
|
|
the result is the null value.</p>
|
|
<p>The CCSID of the result is 65535.</p>
|
|
<a name="wq738"></a>
|
|
<h4 id="wq738">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable L1 is a CHARACTER(2) host variable
|
|
with a value of X'0101', host variable L2 is a CHARACTER(3) host variable
|
|
with a value of X'F0F000', and host variable L3 is a CHARACTER(4) host variable
|
|
with a value of X'0000000F'.
|
|
<pre class="xmp"> <span class="bold">SELECT LOR</span>(:L1,:L2,:L3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value X'F1F1400F'.</li></ul>
|
|
<a name="scalower"></a>
|
|
<h3 id="scalower"><a href="rbafzmst02.htm#ToC_523">LOWER</a></h3><a id="idx1036" name="idx1036"></a><a id="idx1037" name="idx1037"></a>
|
|
<a href="rbafzmstscale.htm#synlower"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq739"></a>
|
|
<div class="fignone" id="wq739">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn150.htm"
|
|
border="0" /></span><a href="#skipsyn-149"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LOWER--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-149" id="skipsyn-149"></a></div>
|
|
<a name="synlower"></a>
|
|
<p id="synlower">The LOWER function returns a string in which all the characters
|
|
have been converted to lowercase characters, based on the CCSID of the argument.
|
|
Only SBCS, UTF-16, and UCS-2 graphic characters are converted. The characters
|
|
A-Z are converted to a-z, and characters with diacritical marks are converted
|
|
to their lowercase equivalent, if any. Refer to the <a href="../nls/rbagsucslevel1maptble.htm">UCS-2 level 1 mapping tables</a> section of the <a href="../nls/rbagsglobalmain.htm">Globalization</a> topic in the iSeries Information Center for a description of the monocasing tables that
|
|
are used for this translation.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string to be converted. <var class="pv">expression</var> must be any built-in numeric, character, UTF–16, or UCS-2 graphic
|
|
string. A numeric argument is cast to a character string before evaluating
|
|
the function. For more information on converting numeric to a character string,
|
|
see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function has the same data type, length attribute, actual
|
|
length, and CCSID as the argument. If the argument can be null, the result
|
|
can be null. If the argument is null, the result is the null value.</p>
|
|
<p>When LOWER is specified in a query, the query cannot contain:</p>
|
|
<ul>
|
|
<li>EXCEPT or INTERSECT operations,</li>
|
|
<li>OLAP specifications,</li>
|
|
<li>recursive common table expressions,</li>
|
|
<li>ORDER OF, or</li>
|
|
<li>scalar fullselects (scalar subselects are supported).</li></ul>
|
|
<a name="wq740"></a>
|
|
<h4 id="wq740">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> LCASE is a synonym for LOWER.</p>
|
|
<a name="wq741"></a>
|
|
<h4 id="wq741">Examples</h4>
|
|
<ul>
|
|
<li>Ensure that the characters in the value of host variable NAME are lowercase.
|
|
NAME has a data type of VARCHAR(30) and a value of 'Christine Smith'.
|
|
<pre class="xmp"><span class="bold">SELECT LOWER(</span>:NAME<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>The result
|
|
is the value 'christine smith'.</li></ul>
|
|
<a name="scaltrim"></a>
|
|
<h3 id="scaltrim"><a href="rbafzmst02.htm#ToC_526">LTRIM</a></h3><a id="idx1038" name="idx1038"></a><a id="idx1039" name="idx1039"></a>
|
|
<a href="rbafzmstscale.htm#synltrim"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq742"></a>
|
|
<div class="fignone" id="wq742">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn151.htm"
|
|
border="0" /></span><a href="#skipsyn-150"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-LTRIM--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-150" id="skipsyn-150"></a></div>
|
|
<a name="synltrim"></a>
|
|
<p id="synltrim">The LTRIM function removes blanks or hexadecimal zeros from
|
|
the beginning of an expression. <sup class="fn"><a id="wq743" name="wq743" href="rbafzmstscale.htm#wq744">46</a></sup></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be expressions that return a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
<ul>
|
|
<li>If the argument is a binary string, then the leading hexadecimal zeros
|
|
(X'00') are removed.</li>
|
|
<li>If the argument is a DBCS graphic string, then the leading DBCS blanks
|
|
are removed.</li>
|
|
<li>If the first argument is a UTF-16 or UCS-2 graphic string, then the leading
|
|
UTF-16 or UCS-2 blanks are removed.</li>
|
|
<li>If the first argument is a UTF-8 character string, then the leading UTF-8
|
|
blanks are removed.</li>
|
|
<li>Otherwise, leading SBCS blanks are removed.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result depends on the data type of <span class="italic">expression</span>:</p>
|
|
<a name="wq745"></a>
|
|
<table id="wq745" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq746" width="50%" align="left" valign="bottom">Data type of <span class="italic">expression</span></th>
|
|
<th id="wq747" width="50%" align="left" valign="bottom">Data type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq746">CHAR or VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq747">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq746">CLOB</td>
|
|
<td align="left" valign="top" headers="wq747">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq746">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq747">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq746">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq747">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq746">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq747">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq746">BLOB</td>
|
|
<td align="left" valign="top" headers="wq747">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The length attribute of the result is the same as the length attribute
|
|
of <span class="italic">expression</span>. The actual length of the result is
|
|
the length of <span class="italic">expression</span> minus the number of bytes
|
|
removed. If all characters are removed, the result is an empty string.</p>
|
|
<p>If the first argument can be null, the result can be null; if the first
|
|
argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the same as that of the string.</p>
|
|
<a name="wq748"></a>
|
|
<h4 id="wq748">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HELLO of type CHAR(9) has a value of ' Hello'.
|
|
<pre class="xmp"> <span class="bold">SELECT LTRIM(</span>:HELLO<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results
|
|
in: 'Hello'.</li></ul>
|
|
<a name="scamax"></a>
|
|
<h3 id="scamax"><a href="rbafzmst02.htm#ToC_528">MAX</a></h3><a id="idx1040" name="idx1040"></a><a id="idx1041" name="idx1041"></a>
|
|
<a href="rbafzmstscale.htm#synsmax"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq749"></a>
|
|
<div class="fignone" id="wq749">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn152.htm"
|
|
border="0" /></span><a href="#skipsyn-151"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-MAX--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-151" id="skipsyn-151"></a></div>
|
|
<a name="synsmax"></a>
|
|
<p id="synsmax">The MAX scalar function returns the maximum value in a set
|
|
of values.</p>
|
|
<p>The arguments must be compatible. Character-string arguments are compatible
|
|
with datetime values. The arguments cannot be DataLink values.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be any built-in numeric or string data types. If
|
|
one of the arguments is numeric, then character and graphic string arguments
|
|
are cast to numeric before evaluating the function.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is the largest argument value. The result can
|
|
be null if at least one argument can be null; the result is the null value
|
|
if one of the arguments is null.</p>
|
|
<p>The selected argument is converted, if necessary, to the attributes of
|
|
the result. The attributes of the result are determined by all the operands
|
|
as explained in <a href="rbafzmstopcomb.htm#opcomb">Rules for result data types</a>.</p>
|
|
<p>If a sort sequence other than *HEX is in effect when the statement is executed
|
|
and the arguments are SBCS data, mixed data, or Unicode data, the weighted
|
|
values of the strings are compared instead of the actual values. The weighted
|
|
values are based on the sort sequence.</p>
|
|
<a name="wq750"></a>
|
|
<h4 id="wq750">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable M1 is a DECIMAL(2,1) host variable with a value
|
|
of 5.5, host variable M2 is a DECIMAL(3,1) host variable with a value of 4.5,
|
|
and host variable M3 is a DECIMAL(3,2) host variable with a value of 6.25.
|
|
<pre class="xmp"> <span class="bold">SELECT MAX</span>(:M1,:M2,:M3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 6.25.</li>
|
|
<li>Assume the host variable M1 is a CHARACTER(2) host variable with a value
|
|
of 'AA', host variable M2 is a CHARACTER(3) host variable with a value of
|
|
'AA ', and host variable M3 is a CHARACTER(4) host variable with a value of
|
|
'AA A'.
|
|
<pre class="xmp"> <span class="bold">SELECT MAX</span>(:M1,:M2,:M3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 'AA A'.</li></ul>
|
|
<a name="scamicro"></a>
|
|
<h3 id="scamicro"><a href="rbafzmst02.htm#ToC_530">MICROSECOND</a></h3><a id="idx1042" name="idx1042"></a><a id="idx1043" name="idx1043"></a>
|
|
<a href="rbafzmstscale.htm#synmicro"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq751"></a>
|
|
<div class="fignone" id="wq751">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn153.htm"
|
|
border="0" /></span><a href="#skipsyn-152"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MICROSECOND--(--<span class="italic">expression</span>--)-------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-152" id="skipsyn-152"></a></div>
|
|
<a name="synmicro"></a>
|
|
<p id="synmicro">The MICROSECOND function returns the microsecond part of
|
|
a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a timestamp, a character string, a graphic
|
|
string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
timestamp. For the valid formats of string representations of timestamps,
|
|
see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a timestamp duration. For
|
|
the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a timestamp or a valid character-string representation
|
|
of a timestamp:
|
|
<p>The result is the microsecond part of the value, which is
|
|
an integer between 0 and 999999.</p></li>
|
|
<li>If the argument is a duration:
|
|
<p>The result is the microsecond part of
|
|
the value, which is an integer between -999999 and 999999. A nonzero
|
|
result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq752"></a>
|
|
<h4 id="wq752">Example</h4>
|
|
<ul>
|
|
<li>Assume a table TABLEA contains two columns, TS1 and TS2, of type TIMESTAMP.
|
|
Select all rows in which the microseconds portion of TS1 is not zero and the
|
|
seconds portion of TS1 and TS2 are identical.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> TABLEA
|
|
<span class="bold">WHERE MICROSECOND(</span>TS1<span class="bold">)</span> <> 0 <span class="bold">AND SECOND(</span>TS1<span class="bold">)</span> = <span class="bold">SECOND(</span>TS2<span class="bold">)</span></pre></li></ul>
|
|
<a name="scamidnight"></a>
|
|
<h3 id="scamidnight"><a href="rbafzmst02.htm#ToC_532">MIDNIGHT_SECONDS</a></h3><a id="idx1044" name="idx1044"></a><a id="idx1045" name="idx1045"></a>
|
|
<a href="rbafzmstscale.htm#synmidnight"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq753"></a>
|
|
<div class="fignone" id="wq753">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn154.htm"
|
|
border="0" /></span><a href="#skipsyn-153"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MIDNIGHT_SECONDS--(--<span class="italic">expression</span>--)--------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-153" id="skipsyn-153"></a></div>
|
|
<a name="synmidnight"></a>
|
|
<p id="synmidnight">The MIDNIGHT_SECONDS function returns an integer value
|
|
that is greater than or equal to 0 and less than or equal to 86 400® representing
|
|
the number of seconds between midnight and the time value specified in the
|
|
argument.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a time, a timestamp, a character string, or
|
|
a graphic string. It must not be a CLOB or DBCLOB and its value must be a
|
|
valid string representation of a time or timestamp. For the valid formats
|
|
of string representations of times and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is large integer. If the argument
|
|
can be null, the result can be null; if the argument is null, the result is
|
|
the null value.</p>
|
|
<a name="wq754"></a>
|
|
<h4 id="wq754">Examples</h4>
|
|
<ul>
|
|
<li>Find the number of seconds between midnight and 00:01:00, and midnight
|
|
and 13:10:10. Assume that host variable XTIME1 has a value of '00:01:00',
|
|
and that XTIME2 has a value of '13:10:10'.
|
|
<pre class="xmp"> <span class="bold">SELECT MIDNIGHT_SECONDS(</span>:XTIME1<span class="bold">)</span>, <span class="bold">MIDNIGHT_SECONDS(</span>:XTIME2<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>This example returns
|
|
60 and 47410. Because there are 60 seconds in a minute and 3600 seconds in
|
|
an hour, 00:01:00 is 60 seconds after midnight ((60 * 1) + 0), and 13:10:10
|
|
is 47410 seconds ((3600 * 13) + (60 * 10) + 10).</li>
|
|
<li>Find the number of seconds between midnight and 24:00:00, and midnight
|
|
and 00:00:00.
|
|
<pre class="xmp"> <span class="bold">SELECT MIDNIGHT_SECONDS(</span>'24:00:00'<span class="bold">)</span>, <span class="bold">MIDNIGHT_SECONDS(</span>'00:00:00'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>This example returns
|
|
86400 and 0. Although these two values represent the same point in time, different
|
|
values are returned.</li></ul>
|
|
<a name="scamin"></a>
|
|
<h3 id="scamin"><a href="rbafzmst02.htm#ToC_534">MIN</a></h3><a id="idx1046" name="idx1046"></a><a id="idx1047" name="idx1047"></a>
|
|
<a href="rbafzmstscale.htm#synsmin"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq755"></a>
|
|
<div class="fignone" id="wq755">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn155.htm"
|
|
border="0" /></span><a href="#skipsyn-154"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-MIN--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-154" id="skipsyn-154"></a></div>
|
|
<a name="synsmin"></a>
|
|
<p id="synsmin">The MIN scalar function returns the minimum value in a set
|
|
of values.</p>
|
|
<p>The arguments must be compatible. Character-string arguments are compatible
|
|
with datetime values. The arguments cannot be DataLink values.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be any built-in numeric or string data types. If
|
|
one of the arguments is numeric, then character and graphic string arguments
|
|
are cast to numeric before evaluating the function.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is the smallest argument value. The result can
|
|
be null if at least one argument can be null; the result is the null value
|
|
if one of the arguments is null.</p>
|
|
<p>The selected argument is converted, if necessary, to the attributes of
|
|
the result. The attributes of the result are determined by all the operands
|
|
as explained in <a href="rbafzmstopcomb.htm#opcomb">Rules for result data types</a>.</p>
|
|
<p>If a sort sequence other than *HEX is in effect when the statement is executed
|
|
and the arguments are SBCS data, mixed data, or Unicode data, the weighted
|
|
values of the strings are compared instead of the actual values. The weighted
|
|
values are based on the sort sequence.</p>
|
|
<a name="wq756"></a>
|
|
<h4 id="wq756">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable M1 is a DECIMAL(2,1) host variable with a value
|
|
of 5.5, host variable M2 is a DECIMAL(3,1) host variable with a value of 4.5,
|
|
and host variable M3 is a DECIMAL(3,2) host variable with a value of 6.25.
|
|
<pre class="xmp"> <span class="bold">SELECT MIN</span>(:M1,:M2,:M3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 4.50.</li>
|
|
<li>Assume the host variable M1 is a CHARACTER(2) host variable with a value
|
|
of 'AA', host variable M2 is a CHARACTER(3) host variable with a value of
|
|
'AAA', and host variable M3 is a CHARACTER(4) host variable with a value of
|
|
'AAAA'.
|
|
<pre class="xmp"> <span class="bold">SELECT MIN</span>(:M1,:M2,:M3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 'AA '.</li></ul>
|
|
<a name="scaminute"></a>
|
|
<h3 id="scaminute"><a href="rbafzmst02.htm#ToC_536">MINUTE</a></h3><a id="idx1048" name="idx1048"></a><a id="idx1049" name="idx1049"></a>
|
|
<a href="rbafzmstscale.htm#synminute"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq757"></a>
|
|
<div class="fignone" id="wq757">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn156.htm"
|
|
border="0" /></span><a href="#skipsyn-155"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MINUTE--(--<span class="italic">expression</span>--)------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-155" id="skipsyn-155"></a></div>
|
|
<a name="synminute"></a>
|
|
<p id="synminute">The MINUTE function returns the minute part of a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a time, a timestamp, a character string, a
|
|
graphic string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
time or timestamp. For the valid formats of string representations of times
|
|
and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a time duration or timestamp
|
|
duration. For the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a time, a timestamp, or a valid character-string representation
|
|
of a time or timestamp:
|
|
<p>The result is the minute part of the value, which
|
|
is an integer between 0 and 59.</p></li>
|
|
<li>If the argument is a time duration or timestamp duration:
|
|
<p>The result
|
|
is the minute part of the value, which is an integer between -99 and
|
|
99. A nonzero result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq758"></a>
|
|
<h4 id="wq758">Example</h4>
|
|
<ul>
|
|
<li>Using the CL_SCHED sample table, select all classes with a duration
|
|
less than 50 minutes.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> CL_SCHED
|
|
<span class="bold">WHERE HOUR(</span>ENDING - STARTING<span class="bold">)</span> = 0 <span class="bold">AND
|
|
MINUTE(</span>ENDING - STARTING<span class="bold">)</span> < 50</pre></li></ul>
|
|
<a name="scamod"></a>
|
|
<h3 id="scamod"><a href="rbafzmst02.htm#ToC_538">MOD</a></h3><a id="idx1050" name="idx1050"></a><a id="idx1051" name="idx1051"></a>
|
|
<a href="rbafzmstscale.htm#synmod"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq759"></a>
|
|
<div class="fignone" id="wq759">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn157.htm"
|
|
border="0" /></span><a href="#skipsyn-156"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MOD--(--<span class="italic">expression-1</span>--,--<span class="italic">expression-2</span>--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-156" id="skipsyn-156"></a></div>
|
|
<a name="synmod"></a>
|
|
<p id="synmod">The MOD function divides the first argument by the second argument
|
|
and returns the remainder.</p>
|
|
<p>The formula used to calculate the remainder is: </p>
|
|
<pre class="xmp"> <span class="bold">MOD</span>(x,y) = x - (x/y) * y</pre><p class="indatacontent"> where x/y is the truncated integer result
|
|
of the division. The result is negative only if first argument is negative.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression-1</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression-2</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. <var class="pv">expression-2</var> cannot be zero.
|
|
</dd>
|
|
</dl>
|
|
<p>If an argument can be null, the result can be null; if an argument is null,
|
|
the result is the null value.</p>
|
|
<p>The attributes of the result are determined as follows: </p>
|
|
<ul>
|
|
<li>If both arguments are large or small integers with zero scale, the data
|
|
type of the result is large integer.</li>
|
|
<li>If both arguments are integers with zero scale and at least one of the
|
|
arguments is a big integer, the data type of the result is big integer.</li>
|
|
<li>If one argument is an integer with zero scale and the other is decimal,
|
|
the result is decimal with the same precision and scale as the decimal argument.</li>
|
|
<li>If both arguments are decimal or integer with scale numbers, the result
|
|
is decimal. The precision of the result is min (p-s,p'-s') + max (s,s'), and
|
|
the scale of the result is max (s,s'), where the symbols p and s denote the
|
|
precision and scale of the first operand, and the symbols p' and s' denote
|
|
the precision and scale of the second operand.</li>
|
|
<li>If either argument is floating point, the data type of the result is double-precision
|
|
floating point.
|
|
<p>The operation is performed in floating point; the operands
|
|
having been first converted to double-precision floating-point numbers, if
|
|
necessary.</p>
|
|
<p>An operation involving a floating-point number and an integer
|
|
is performed with a temporary copy of the integer that has been 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></li></ul>
|
|
<a name="wq760"></a>
|
|
<h4 id="wq760">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable M1 is an integer host variable with a value of
|
|
5, and host variable M2 is an integer host variable with a value of 2.
|
|
<pre class="xmp"> <span class="bold">SELECT MOD</span>(:M1,:M2)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 1.</li>
|
|
<li>Assume the host variable M1 is an integer host variable with a value of
|
|
5, and host variable M2 is a DECIMAL(3,2) host variable with a value of 2.20.
|
|
<pre class="xmp"> <span class="bold">SELECT MOD</span>(:M1,:M2)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 0.60.</li>
|
|
<li>Assume the host variable M1 is a DECIMAL(4,2) host variable with a value
|
|
of 5.50, and host variable M2 is a DECIMAL(4,1) host variable with a value
|
|
of 2.0.
|
|
<pre class="xmp"> <span class="bold">SELECT MOD</span>(:M1,:M2)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 1.50.</li></ul>
|
|
<a name="scamonth"></a>
|
|
<h3 id="scamonth"><a href="rbafzmst02.htm#ToC_540">MONTH</a></h3><a id="idx1052" name="idx1052"></a><a id="idx1053" name="idx1053"></a>
|
|
<a href="rbafzmstscale.htm#synmonth"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq761"></a>
|
|
<div class="fignone" id="wq761">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn158.htm"
|
|
border="0" /></span><a href="#skipsyn-157"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MONTH--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-157" id="skipsyn-157"></a></div>
|
|
<a name="synmonth"></a>
|
|
<p id="synmonth">The MONTH function returns the month part of a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, a
|
|
graphic string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
date or timestamp. For the valid formats of string representations of dates
|
|
and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a date duration or timestamp
|
|
duration. For the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a date, a timestamp, or a valid character-string representation
|
|
of a date or timestamp:
|
|
<p>The result is the month part of the value, which
|
|
is an integer between 1 and 12.</p></li>
|
|
<li>If the argument is a date duration or timestamp duration:
|
|
<p>The result
|
|
is the month part of the value, which is an integer between -99 and
|
|
99. A nonzero result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq762"></a>
|
|
<h4 id="wq762">Example</h4>
|
|
<ul>
|
|
<li>Select all rows from the EMPLOYEE table for people who were born (BIRTHDATE)
|
|
in DECEMBER.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE MONTH(</span>BIRTHDATE<span class="bold">)</span> = 12</pre></li></ul>
|
|
<a name="scamname"></a>
|
|
<h3 id="scamname"><a href="rbafzmst02.htm#ToC_542">MONTHNAME</a></h3><a id="idx1054" name="idx1054"></a><a id="idx1055" name="idx1055"></a>
|
|
<a href="rbafzmstscale.htm#synmname"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq763"></a>
|
|
<div class="fignone" id="wq763">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn159.htm"
|
|
border="0" /></span><a href="#skipsyn-158"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MONTHNAME--(--<span class="italic">expression</span>--)---------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-158" id="skipsyn-158"></a></div>
|
|
<a name="synmname"></a>
|
|
<p id="synmname">Returns a mixed case character string containing the name
|
|
of the month (e.g. January) for the month portion of the argument.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is VARCHAR(100). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current server.</p>
|
|
<a name="wq764"></a>
|
|
<h4 id="wq764">Note</h4>
|
|
<p><span class="bold">National language considerations:</span> The name of the
|
|
month that is returned is based on the language used for messages in the job.
|
|
This name of the month is retrieved from message CPX3BC0 in message file QCPFMSG
|
|
in library *LIBL.</p>
|
|
<a name="wq765"></a>
|
|
<h4 id="wq765">Examples</h4>
|
|
<ul>
|
|
<li>Assume that the language used is US English.
|
|
<pre class="xmp"><span class="bold">SELECT MONTHNAME(</span> '2003-01-02' <span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results in 'January'.</li></ul>
|
|
<a name="scamultalt"></a>
|
|
<h3 id="scamultalt"><a href="rbafzmst02.htm#ToC_545">MULTIPLY_ALT</a></h3><a id="idx1056" name="idx1056"></a><a id="idx1057" name="idx1057"></a>
|
|
<a href="rbafzmstscale.htm#synsmultalt"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq766"></a>
|
|
<div class="fignone" id="wq766">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn160.htm"
|
|
border="0" /></span><a href="#skipsyn-159"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-MULTIPLY_ALT--(--<span class="italic">expression-1</span>--,--<span class="italic">expression-2</span>--)-----------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-159" id="skipsyn-159"></a></div>
|
|
<a name="synsmultalt"></a>
|
|
<p id="synsmultalt">The MULTIPLY_ALT scalar function returns the product of
|
|
the two arguments as a decimal value. It is provided as an alternative to
|
|
the multiplication operator, especially when the sum of the precisions of
|
|
the arguments exceeds 63.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression-1</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression-2</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. <var class="pv">expression-2</var> cannot be zero.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a DECIMAL. The precision and scale of the
|
|
result are determined as follows, using the symbols <var class="pv">p</var> and <var class="pv">s</var> to
|
|
denote the precision and scale of the first argument, and the symbols <var class="pv">p</var>' and <var class="pv">s</var>' to denote the precision and scale of the second
|
|
argument.</p>
|
|
<ul>
|
|
<li>The precision is MIN(<var class="pv">mp</var>, p+p')</li>
|
|
<li>The scale is:
|
|
<ul>
|
|
<li>0 if the scale of both arguments is 0</li>
|
|
<li>MIN(<var class="pv">ms</var>, s+s') if p+p' is less than or equal to <var class="pv">mp</var></li>
|
|
<li>MIN(<var class="pv">ms</var>, MAX( MIN(3, s+s'), <var class="pv">mp</var>-(p-s+p'-s')
|
|
) ) if p+p' is greater than <var class="pv">mp</var>.</li></ul></li></ul><p class="indatacontent">For information on the values of <span class="italic">p</span>, <span class="italic">s</span>, <span class="italic">ms</span>, and <span class="italic">mp</span>, see <a href="rbafzmstch2expr.htm#decarithmetic">Decimal arithmetic in SQL</a>.</p>
|
|
<p>The result can be null if at least one argument can be null; the result
|
|
is the null value if one of the arguments is null.</p>
|
|
<p>The MULTIPLY_ALT function is a better choice than the multiplication operator
|
|
when performing decimal arithmetic where a scale of at least 3 is desired
|
|
and the sum of the precisions exceeds 63. In these cases, the internal computation
|
|
is performed so that overflows are avoided and then assigned to the result
|
|
type value using truncation for any loss of scale in the final result. Note
|
|
that the possibility of overflow of the final result is still possible when
|
|
the scale is 3.</p>
|
|
<p>The following table compares the result types using MULTIPLY_ALT and the
|
|
multiplication operator when the maximum precision is 31 and the maximum scale
|
|
is 31:</p>
|
|
<a name="wq767"></a>
|
|
<table id="wq767" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq768" width="25%" align="left" valign="bottom">Type of Argument 1</th>
|
|
<th id="wq769" width="25%" align="left" valign="bottom">Type of Argument 2</th>
|
|
<th id="wq770" width="25%" align="left" valign="bottom">Result using MULTIPLY_ALT</th>
|
|
<th id="wq771" width="25%" align="left" valign="bottom">Result using multiplication operator</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq768">DECIMAL(31,3)</td>
|
|
<td align="left" valign="top" headers="wq769"> DECIMAL(15,8)</td>
|
|
<td align="left" valign="top" headers="wq770"> DECIMAL(31,3)</td>
|
|
<td align="left" valign="top" headers="wq771"> DECIMAL(31,11)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq768">DECIMAL(26,23)</td>
|
|
<td align="left" valign="top" headers="wq769"> DECIMAL(10,1)</td>
|
|
<td align="left" valign="top" headers="wq770"> DECIMAL(31,19)</td>
|
|
<td align="left" valign="top" headers="wq771"> DECIMAL(31,24)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq768">DECIMAL(18,17)</td>
|
|
<td align="left" valign="top" headers="wq769"> DECIMAL(20,19)</td>
|
|
<td align="left" valign="top" headers="wq770"> DECIMAL(31,29)</td>
|
|
<td align="left" valign="top" headers="wq771"> DECIMAL(31,31)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq768">DECIMAL(16,3)</td>
|
|
<td align="left" valign="top" headers="wq769"> DECIMAL(17,8)</td>
|
|
<td align="left" valign="top" headers="wq770"> DECIMAL(31,9)</td>
|
|
<td align="left" valign="top" headers="wq771"> DECIMAL(31,11)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq768">DECIMAL(26,5)</td>
|
|
<td align="left" valign="top" headers="wq769"> DECIMAL(11,0)</td>
|
|
<td align="left" valign="top" headers="wq770"> DECIMAL(31,3)</td>
|
|
<td align="left" valign="top" headers="wq771"> DECIMAL(31,5)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq768">DECIMAL(21,1)</td>
|
|
<td align="left" valign="top" headers="wq769"> DECIMAL(15,1)</td>
|
|
<td align="left" valign="top" headers="wq770"> DECIMAL(31,2)</td>
|
|
<td align="left" valign="top" headers="wq771"> DECIMAL(31,2)</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<a name="wq772"></a>
|
|
<h4 id="wq772">Examples</h4>
|
|
<ul>
|
|
<li>Multiply two values where the data type of the first argument is DECIMAL(26,3)
|
|
and the data type of the second argument is DECIMAL(9,8). The data type of
|
|
the result is DECIMAL(31,7).
|
|
<pre class="xmp"> <span class="bold">SELECT MULTIPLY_ALT</span>(98765432109876543210987.654,5.43210987)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 536504678578875294857887.5277415.
|
|
<p>Note that the complete product
|
|
of these two numbers is 536504678578875294857887.52774154498, but the last
|
|
4 digits are truncated to match the scale of the result data type. Using the
|
|
multiplication operator with the same values will cause an arithmetic overflow,
|
|
since the result data type is DECIMAL(31,11) and the result value has 24 digits
|
|
left of the decimal, but the result data type only supports 20 digits.</p></li></ul>
|
|
<a name="scanextday"></a>
|
|
<h3 id="scanextday"><a href="rbafzmst02.htm#ToC_547">NEXT_DAY</a></h3><a id="idx1058" name="idx1058"></a><a id="idx1059" name="idx1059"></a>
|
|
<a href="rbafzmstscale.htm#synnextday"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq773"></a>
|
|
<div class="fignone" id="wq773">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn161.htm"
|
|
border="0" /></span><a href="#skipsyn-160"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-NEXT_DAY--(--<span class="italic">expression</span>--,--<span class="italic">string-expression</span>--)------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-160" id="skipsyn-160"></a></div>
|
|
<a name="synnextday"></a>
|
|
<p id="synnextday">The NEXT_DAY function returns a timestamp that represents
|
|
the first weekday, named by <var class="pv">string-expression</var>, that is later than
|
|
the date <var class="pv">expression</var>. If <var class="pv">expression</var> is a timestamp or valid
|
|
string representation of a timestamp, the timestamp value has the same hours,
|
|
minutes, seconds, and microseconds as <var class="pv">expression</var>. If <var class="pv">expression</var> is a date, or a valid string representation of a date, then the hours,
|
|
minutes, seconds, and microseconds value of the result is 0.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a built-in character string data
|
|
type or graphic string data type. The value must compare equal to the full
|
|
name of a day of the week or compare equal to the abbreviation of a day of
|
|
the week. For example, in the English language:
|
|
<a name="wq774"></a>
|
|
<table id="wq774" width="100%" summary="" border="0" frame="void" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq775" width="50%" align="left" valign="bottom">Day of Week</th>
|
|
<th id="wq776" width="50%" align="left" valign="bottom">Abbreviation</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq775">MONDAY</td>
|
|
<td align="left" valign="top" headers="wq776">MON</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq775">TUESDAY</td>
|
|
<td align="left" valign="top" headers="wq776">TUE</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq775">WEDNESDAY</td>
|
|
<td align="left" valign="top" headers="wq776">WED</td>
|
|
</tr>
|
|
<tr>
|
|
<td headers="wq775">THURSDAY</td>
|
|
<td headers="wq776">THU</td>
|
|
</tr>
|
|
<tr>
|
|
<td headers="wq775">FRIDAY</td>
|
|
<td headers="wq776">FRI</td>
|
|
</tr>
|
|
<tr>
|
|
<td headers="wq775">SATURDAY</td>
|
|
<td headers="wq776">SAT</td>
|
|
</tr>
|
|
<tr>
|
|
<td headers="wq775">SUNDAY</td>
|
|
<td headers="wq776">SUN</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>The minimum length of the input value is the length of the abbreviation.
|
|
Leading and trailing blanks are trimmed from <var class="pv">string-expression</var>. The
|
|
resulting value is then folded to uppercase, so the characters in the value
|
|
may be in any case.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a timestamp. If either argument can be null,
|
|
the result can be null; if either argument is null, the result is the null
|
|
value.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current
|
|
server.</p>
|
|
<a name="wq777"></a>
|
|
<h4 id="wq777">Note</h4>
|
|
<p><span class="bold">National language considerations:</span> The
|
|
values of the days of the week (or abbreviations) in <var class="pv">string-expression</var> may either be the US English values listed in the table above or the
|
|
values based on the language used for messages in the job. The non-abbreviated
|
|
name of the day is retrieved from message CPX9034 in message file QCPFMSG
|
|
in library *LIBL. The abbreviated name of the day is retrieved from message
|
|
CPX9039 in message file QCPFMSG in library *LIBL.</p>
|
|
<p>Applications that need to run in many different language environments
|
|
may want to consider using US English values since they will always be accepted
|
|
in the NEXT_DAY function.</p>
|
|
<a name="wq778"></a>
|
|
<h4 id="wq778">Example</h4>
|
|
<ul>
|
|
<li>Assuming that the default language for the job is US English,
|
|
set the host variable NEXTDAY with the date of the Tuesday following April
|
|
24, 2000.
|
|
<pre class="xmp"><span class="bold">SET </span>:NEXTDAY <span class="bold">= NEXT_DAY(CURRENT_DATE,</span> 'TUESDAY'<span class="bold">)</span> </pre>
|
|
<p>The host variable NEXTDAY
|
|
is set with the value of '2000–04–25–00.00.00.000000', assuming
|
|
that the value of the CURRENT_DATE special register is '2000–04–24'.</p></li>
|
|
<li>Assuming that the default language for the job is US English, set the
|
|
host variable NEXTDAY with the date of the first Monday in May, 2000. Assume
|
|
the host variable DAYHV = 'MON'.
|
|
<pre class="xmp"><span class="bold">SET </span>:NEXTDAY <span class="bold">= NEXT_DAY(LAST_DAY(CURRENT_TIMESTAMP),</span> :DAYHV<span class="bold">)</span></pre>
|
|
<p>The host variable NEXTDAY is set with the value of '2000-05-01-12.01.01.123456',
|
|
assuming that the value of the CURRENT_TIMESTAMP special register is '2000-04-24-12.01.01.123456'.</p></li>
|
|
<li>Assuming that the default language for the job is US English,
|
|
<pre class="xmp"><span class="bold">SELECT NEXT_DAY(</span>'2000-04-24', 'TUESDAY'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Returns '2000-04-25-00.00.00.000000',
|
|
which is the Tuesday following '2000-04-24'.</p></li></ul>
|
|
<a name="scanow"></a>
|
|
<h3 id="scanow"><a href="rbafzmst02.htm#ToC_550">NOW</a></h3><a id="idx1060" name="idx1060"></a><a id="idx1061" name="idx1061"></a>
|
|
<a href="rbafzmstscale.htm#synnow"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq779"></a>
|
|
<div class="fignone" id="wq779">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn162.htm"
|
|
border="0" /></span><a href="#skipsyn-161"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-NOW--(--)---------------------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-161" id="skipsyn-161"></a></div>
|
|
<a name="synnow"></a>
|
|
<p id="synnow">The NOW function returns a timestamp based on a reading of
|
|
the time-of-day clock when the SQL statement is executed at the current server.
|
|
The value returned by the NOW function is the same as the value returned by
|
|
the CURRENT_TIMESTAMP special register. If this function is used more than
|
|
once within a single SQL statement, or used with the CURDATE or CURTIME scalar
|
|
functions or the CURRENT_DATE, CURRENT_TIME, or CURRENT_TIMESTAMP special
|
|
registers within a single statement, all values are based on a single clock
|
|
reading.</p>
|
|
<p>The data type of the result is a timestamp. The result cannot be null.</p>
|
|
<a name="wq780"></a>
|
|
<h4 id="wq780">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CURRENT_TIMESTAMP special
|
|
register should be used for maximal portability. For more information, see <a href="rbafzmstspecreg.htm#specreg">Special registers</a>.</p>
|
|
<a name="wq781"></a>
|
|
<h4 id="wq781">Example</h4>
|
|
<ul>
|
|
<li>Return the current timestamp based on the time-of-day clock.
|
|
<pre class="xmp"> <span class="bold">SELECT NOW</span>()
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="nullif"></a>
|
|
<h3 id="nullif"><a href="rbafzmst02.htm#ToC_553">NULLIF</a></h3><a id="idx1062" name="idx1062"></a><a id="idx1063" name="idx1063"></a>
|
|
<a href="rbafzmstscale.htm#synnullif"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq782"></a>
|
|
<div class="fignone" id="wq782">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn163.htm"
|
|
border="0" /></span><a href="#skipsyn-162"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-NULLIF--(--<span class="italic">expression</span>--,--<span class="italic">expression</span>--)---------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-162" id="skipsyn-162"></a></div>
|
|
<a name="synnullif"></a>
|
|
<p id="synnullif">The NULLIF function returns a null value if the arguments
|
|
compare equal, otherwise it returns the value of the first argument.</p>
|
|
<p></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be compatible and comparable data types. Character-string
|
|
arguments are compatible with datetime values. If one operand is a distinct type,
|
|
the other operand must be the same distinct type. The arguments cannot be DataLink
|
|
values.
|
|
</dd>
|
|
</dl>
|
|
<p>The attributes of the result are the attributes of the first argument.
|
|
The result can be null. The result is null if the first argument is null or
|
|
if both arguments are equal.</p>
|
|
<p>The result of using NULLIF(e1,e2) is the same as using the expression</p>
|
|
<pre class="xmp"> <span class="bold">CASE WHEN</span> e1=e2 <span class="bold">THEN NULL ELSE</span> e1 <span class="bold">END</span></pre>
|
|
<p>Note that when e1=e2 evaluates to unknown (because one or both arguments
|
|
is NULL), CASE expressions consider this not true. Therefore, in this situation,
|
|
NULLIF returns the value of the first operand, e1.</p>
|
|
<a name="wq783"></a>
|
|
<h4 id="wq783">Example</h4>
|
|
<ul>
|
|
<li>Assume host variables PROFIT, CASH, and LOSSES have DECIMAL data types
|
|
with the values 4500.00, 500.00, and 5000.00 respectively:
|
|
<pre class="xmp"> <span class="bold">SELECT NULLIF</span> (:PROFIT + :CASH, :LOSSES )
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the null value.</li></ul>
|
|
<a name="scaoctetlen"></a>
|
|
<h3 id="scaoctetlen"><a href="rbafzmst02.htm#ToC_555">OCTET_LENGTH</a></h3><a id="idx1064" name="idx1064"></a><a id="idx1065" name="idx1065"></a>
|
|
<a href="rbafzmstscale.htm#synoctetlen"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq784"></a>
|
|
<div class="fignone" id="wq784">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn164.htm"
|
|
border="0" /></span><a href="#skipsyn-163"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>---OCTET_LENGTH----(--<span class="italic">expression</span>--)--------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-163" id="skipsyn-163"></a></div>
|
|
<a name="synoctetlen"></a>
|
|
<p id="synoctetlen">The OCTET_LENGTH function returns the length of a string
|
|
expression in octets (bytes). See <a href="rbafzmstscale.htm#scalength">LENGTH</a> and <a href="rbafzmstscale.htm#charlenf">CHARACTER_LENGTH</a> for
|
|
similar functions.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is DECIMAL(31). If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The result is the number of octets (bytes) in the argument. The length
|
|
of a string includes trailing blanks. The length of a varying-length string
|
|
is the actual length in octets (bytes), not the maximum length.</p>
|
|
<a name="wq785"></a>
|
|
<h4 id="wq785">Example</h4>
|
|
<ul>
|
|
<li>Assume table T1 has a GRAPHIC(10) column called C1.
|
|
<pre class="xmp"> <span class="bold">SELECT OCTET_LENGTH(</span> C1 <span class="bold">)</span>
|
|
<span class="bold">FROM</span> T1</pre> Returns the value
|
|
20.</li></ul>
|
|
<a name="scapi"></a>
|
|
<h3 id="scapi"><a href="rbafzmst02.htm#ToC_557">PI</a></h3><a id="idx1066" name="idx1066"></a><a id="idx1067" name="idx1067"></a>
|
|
<a href="rbafzmstscale.htm#synpi"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq786"></a>
|
|
<div class="fignone" id="wq786">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn165.htm"
|
|
border="0" /></span><a href="#skipsyn-164"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-PI--(--)----------------------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-164" id="skipsyn-164"></a></div>
|
|
<a name="synpi"></a>
|
|
<p id="synpi">Returns the value of π 3.141592653589793. There are no arguments.</p>
|
|
<p>The result of the function is double-precision floating-point. The result
|
|
cannot be null.</p>
|
|
<a name="wq787"></a>
|
|
<h4 id="wq787">Example</h4>
|
|
<ul>
|
|
<li>The following returns the circumference of a circle with diameter 10:
|
|
<pre class="xmp"> <span class="bold">SELECT PI()</span>*10
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="posstr"></a>
|
|
<h3 id="posstr"><a href="rbafzmst02.htm#ToC_559">POSITION or POSSTR</a></h3><a id="idx1068" name="idx1068"></a><a id="idx1069" name="idx1069"></a><a id="idx1070" name="idx1070"></a><a id="idx1071" name="idx1071"></a>
|
|
<a href="rbafzmstscale.htm#synposition"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq788"></a>
|
|
<div class="fignone" id="wq788">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn166.htm"
|
|
border="0" /></span><a href="#skipsyn-165"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-POSITION--(--<span class="italic">search-string</span>--IN--<span class="italic">source-string</span>--)-+--------><
|
|
'-POSSTR--(--<span class="italic">source-string</span>--,--<span class="italic">search-string</span>--)----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-165" id="skipsyn-165"></a></div>
|
|
<a name="synposition"></a>
|
|
<p id="synposition">The POSITION and POSSTR functions return the starting
|
|
position of the first occurrence of one string (called the <var class="pv">search-string</var>) within another string (called the <var class="pv">source-string</var>). If the <span class="italic">search-string</span> is not
|
|
found and neither argument is null, the result is zero. If the <span class="italic">search-string</span> is found, the result is a number from 1 to the actual length
|
|
of the <span class="italic">source-string</span>. See the related function, <a href="rbafzmstscale.htm#locate">LOCATE</a>.</p>
|
|
<p></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">source-string</var></dt>
|
|
<dd>An expression that specifies the source string in which the search is
|
|
to take place. <var class="pv">Source-string</var> may be any built-in numeric or string
|
|
expression. A numeric argument is cast to a character string before evaluating
|
|
the function. For more information on converting numeric to a character string,
|
|
see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">search-string</var></dt>
|
|
<dd>An expression that specifies the string that is to be searched for. <var class="pv">Search-string</var> may be any built-in numeric or string expression. It must
|
|
be compatible with the <span class="italic">source-string</span>. A numeric argument
|
|
is cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>If either argument is a UTF-8 or UTF-16 string, the query cannot
|
|
contain:</p>
|
|
<ul>
|
|
<li>EXCEPT or INTERSECT operations,</li>
|
|
<li>OLAP specifications,</li>
|
|
<li>recursive common table expressions,</li>
|
|
<li>ORDER OF, or</li>
|
|
<li>scalar fullselects (scalar subselects are supported).</li></ul>
|
|
<p>The result of the function is a large integer. If either of the arguments
|
|
can be null, the result can be null. If either of the arguments is null, the
|
|
result is the null value.</p>
|
|
<p>The POSITION function operates on a character basis. The POSSTR function
|
|
operates on a strict byte-count basis. It is recommended that if either the <var class="pv">search-string</var> or <var class="pv">source-string</var> contains mixed data, POSITION
|
|
should be used instead of POSSTR. Because POSSTR operates on a strict byte-count
|
|
basis, if the <var class="pv">search-string</var> or <var class="pv">source-string</var> contains mixed
|
|
data, the <var class="pv">search-string</var> will only be found if any shift-in and shift-out
|
|
characters are also found in the <var class="pv">source-string</var> in exactly the same
|
|
positions. Because POSITION operates on a character-string basis, any shift-in
|
|
and shift-out characters are not required to be in exactly the same position
|
|
and their only significance is to indicate which characters are SBCS and which
|
|
characters are DBCS.</p>
|
|
<p>If the CCSID of the <var class="pv">search-string</var> is different than the CCSID
|
|
of the <var class="pv">source-string</var>, it is converted to the CCSID of the <var class="pv">source-string</var>.</p>
|
|
<p>If a sort sequence other than *HEX is in effect when the statement that
|
|
contains the POSSTR or POSITION function is executed and the arguments are
|
|
SBCS data, mixed data, or Unicode data, then the result is obtained by comparing
|
|
weighted values for each value in the set. The weighted values are based on
|
|
the sort sequence. An ICU sort sequence table may not be specified with the
|
|
POSSTR or POSITION function.</p>
|
|
<p>If the <var class="pv">search-string</var> has a length of zero, the result returned
|
|
by the function is 1. Otherwise:</p>
|
|
<ul>
|
|
<li>if the <var class="pv">source-string</var> has a length of zero, the result returned
|
|
by the function is 0.</li>
|
|
<li>Otherwise,
|
|
<ul>
|
|
<li>If the value of <var class="pv">search-string</var> is equal to an identical length
|
|
of substring of contiguous positions within the value of <var class="pv">source-string</var>, then the result returned by the function is the starting position of
|
|
the first such substring within the <var class="pv">source-string</var> value.</li>
|
|
<li>Otherwise, the result returned by the function is 0.<sup class="fn"><a id="wq789" name="wq789" href="rbafzmstscale.htm#wq790">47</a></sup></li></ul></li></ul>
|
|
<a name="wq791"></a>
|
|
<h4 id="wq791">Example</h4>
|
|
<ul>
|
|
<li>Select RECEIVED and SUBJECT columns as well as the starting position of
|
|
the words 'GOOD' within the NOTE_TEXT column for all entries in the IN_TRAY
|
|
table that contain these words.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> RECEIVED, SUBJECT, <span class="bold">POSSTR(</span>NOTE_TEXT, 'GOOD')
|
|
<span class="bold">FROM</span> IN_TRAY
|
|
<span class="bold">WHERE POSSTR(</span>NOTE_TEXT, 'GOOD') <> 0</pre></li></ul>
|
|
<a name="scapower"></a>
|
|
<h3 id="scapower"><a href="rbafzmst02.htm#ToC_561">POWER</a></h3><a id="idx1072" name="idx1072"></a><a id="idx1073" name="idx1073"></a>
|
|
<a href="rbafzmstscale.htm#synpower"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq792"></a>
|
|
<div class="fignone" id="wq792">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn167.htm"
|
|
border="0" /></span><a href="#skipsyn-166"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-POWER--(--<span class="italic">expression-1</span>--,--<span class="italic">expression-2</span>--)------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-166" id="skipsyn-166"></a></div>
|
|
<a name="synpower"></a>
|
|
<p id="synpower">The POWER function returns the result of raising the first
|
|
argument to the power of the second argument. <sup class="fn"><a id="wq793" name="wq793" href="rbafzmstscale.htm#wq794">48</a></sup></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression-1</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression-2</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric data type. If the value of <var class="pv">expression-1</var> is equal to zero,
|
|
then <var class="pv">expression-2</var> must be greater than or equal to zero. If the value
|
|
of <var class="pv">expression-1</var> is less than zero, then <var class="pv">expression-2</var> must
|
|
be an integer value.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a double-precision floating-point number.
|
|
If both arguments are 0, the result is 1. If an argument can be null, the
|
|
result can be null; if an argument is null, the result is the null value.</p>
|
|
<a name="wq795"></a>
|
|
<h4 id="wq795">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HPOWER is an integer with value 3.
|
|
<pre class="xmp"> <span class="bold">SELECT POWER(</span>2,:HPOWER<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 8.</li></ul>
|
|
<a name="scaquarter"></a>
|
|
<h3 id="scaquarter"><a href="rbafzmst02.htm#ToC_563">QUARTER</a></h3><a id="idx1074" name="idx1074"></a><a id="idx1075" name="idx1075"></a>
|
|
<a href="rbafzmstscale.htm#synquarter"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq796"></a>
|
|
<div class="fignone" id="wq796">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn168.htm"
|
|
border="0" /></span><a href="#skipsyn-167"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-QUARTER--(--<span class="italic">expression</span>--)-----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-167" id="skipsyn-167"></a></div>
|
|
<a name="synquarter"></a>
|
|
<p id="synquarter">The QUARTER function returns an integer between 1 and 4
|
|
that represents the quarter of the year in which the date resides. For example,
|
|
any dates in January, February, or March will return the integer 1.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq797"></a>
|
|
<h4 id="wq797">Example</h4>
|
|
<ul>
|
|
<li>Using the PROJECT table, set the host variable QUART (INTEGER) to the
|
|
quarter in which project 'PL2100' ended (PRENDATE).
|
|
<pre class="xmp"> <span class="bold">SELECT QUARTER(</span>PRENDATE<span class="bold">)
|
|
INTO</span> :QUART
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNO = 'PL2100'</pre>Results in QUART being
|
|
set to 3.</li></ul>
|
|
<a name="scaradians"></a>
|
|
<h3 id="scaradians"><a href="rbafzmst02.htm#ToC_565">RADIANS</a></h3><a id="idx1076" name="idx1076"></a><a id="idx1077" name="idx1077"></a>
|
|
<a href="rbafzmstscale.htm#synradians"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq798"></a>
|
|
<div class="fignone" id="wq798">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn169.htm"
|
|
border="0" /></span><a href="#skipsyn-168"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-RADIANS--(--<span class="italic">expression</span>--)-----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-168" id="skipsyn-168"></a></div>
|
|
<a name="synradians"></a>
|
|
<p id="synradians">The RADIANS function returns the number of radians for
|
|
an argument that is expressed in degrees.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric, character-string, or graphic-string data type. A string argument
|
|
is cast to double-precision floating point before evaluating the function.
|
|
For more information on converting strings to double-precision floating point,
|
|
see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq799"></a>
|
|
<h4 id="wq799">Example</h4>
|
|
<ul>
|
|
<li>Assume that host variable HDEG is an INTEGER with a value of 180. The
|
|
following statement:
|
|
<pre class="xmp"> <span class="bold">SELECT RADIANS</span>(:HDEG)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
a double precision floating-point number with an approximate value of 3.1415926536.</li></ul>
|
|
<a name="scaraiseerror"></a>
|
|
<h3 id="scaraiseerror"><a href="rbafzmst02.htm#ToC_567">RAISE_ERROR</a></h3><a id="idx1078" name="idx1078"></a><a id="idx1079" name="idx1079"></a>
|
|
<a href="rbafzmstscale.htm#synraiseerror"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq800"></a>
|
|
<div class="fignone" id="wq800">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn170.htm"
|
|
border="0" /></span><a href="#skipsyn-169"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-RAISE_ERROR--(--<span class="italic">sqlstate</span>--,--<span class="italic">diagnostic-string</span>--)-----------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-169" id="skipsyn-169"></a></div>
|
|
<a name="synraiseerror"></a>
|
|
<p id="synraiseerror">The RAISE_ERROR function causes the statement that invokes
|
|
the function to return an error with the specified SQLSTATE (along with SQLCODE
|
|
-438) and error condition. The RAISE_ERROR function always returns NULL with
|
|
an undefined data type.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><span class="italic">sqlstate</span></dt>
|
|
<dd>An expression that returns a character or UCS-2 or UTF-16
|
|
graphic string constant with exactly 5 characters that follow the rules for
|
|
SQLSTATEs:
|
|
<ul>
|
|
<li>Each character must be from the set of digits ('0' through '9') or non-accented
|
|
upper case letters ('A' through 'Z').</li>
|
|
<li>The SQLSTATE class (first two characters) cannot be '00', '01', or '02'
|
|
because these are not error classes.</li></ul>
|
|
<p>If the SQLSTATE does not conform to these rules, an error is returned.</p>
|
|
</dd>
|
|
<dt class="bold"><span class="italic">diagnostic-string</span></dt>
|
|
<dd>Specifies a string that describes the error or warning.
|
|
<p>If an SQLCA
|
|
is used, </p>
|
|
<ul>
|
|
<li>the string is returned in the SQLERRMC field of the SQLCA</li>
|
|
<li>if the actual length of the string is longer than 70 bytes, it is truncated
|
|
without a warning.</li></ul>
|
|
<p>Since the data type of the result of RAISE_ERROR is
|
|
undefined, it may only be used where parameter markers are allowed. To use
|
|
this function in a context where parameter markers are not allowed (such as
|
|
alone in a select list), you must use a cast specification to give a data
|
|
type to the null value that is returned. The RAISE_ERROR function cannot be
|
|
used with CASE expressions.</p>
|
|
</dd>
|
|
</dl>
|
|
<a name="wq801"></a>
|
|
<h4 id="wq801">Example</h4>
|
|
<ul>
|
|
<li>Create an after trigger EMPISRT1 that invokes RAISE_ERROR if the BONUS
|
|
is not valid.
|
|
<pre class="xmp"> <span class="bold">CREATE TRIGGER</span> EMPISRT1
|
|
<span class="bold">AFTER INSERT ON</span> EMPLOYEE
|
|
<span class="bold">REFERENCING NEW AS</span> N
|
|
<span class="bold">FOR EACH ROW</span>
|
|
<span class="bold">MODE DB2SQL</span>
|
|
<span class="bold">BEGIN ATOMIC</span>
|
|
<span class="bold">IF</span> N.BONUS > 20000 <span class="bold">THEN</span>
|
|
<span class="bold">VALUES( RAISE_ERROR(</span> 'ZZZZZ', 'Incorrect bonus' <span class="bold">) );</span>
|
|
<span class="bold">END IF;</span>
|
|
<span class="bold">END</span> </pre></li></ul>
|
|
<a name="scarand"></a>
|
|
<h3 id="scarand"><a href="rbafzmst02.htm#ToC_569">RAND</a></h3><a id="idx1080" name="idx1080"></a><a id="idx1081" name="idx1081"></a>
|
|
<a href="rbafzmstscale.htm#synrand"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq802"></a>
|
|
<div class="fignone" id="wq802">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn171.htm"
|
|
border="0" /></span><a href="#skipsyn-170"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-RAND--(--+------------+--)----------------------------------><
|
|
'-<span class="italic">expression</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-170" id="skipsyn-170"></a></div>
|
|
<a name="synrand"></a>
|
|
<p id="synrand">The RAND function returns a floating point value between 0
|
|
and 1.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>If an expression is specified, it is used as the seed value. The argument
|
|
must be an expression that returns a value of a built-in small integer, large
|
|
integer, character-string, or graphic-string data type. A string argument
|
|
is cast to integer before evaluating the function. For more information on
|
|
converting strings to integer, see <a href="rbafzmstscale.htm#intfunc">INTEGER or INT</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<p>A specific seed value will produce the same sequence of random
|
|
numbers for a specific instance of a RAND function in a query each time the
|
|
query is executed. If a seed value is not specified, a different sequence
|
|
of random numbers is produced each time the query is executed.</p>
|
|
<p>RAND is a non-deterministic function.</p>
|
|
<a name="wq803"></a>
|
|
<h4 id="wq803">Example</h4>
|
|
<ul>
|
|
<li>Assume that host variable HRAND is an INTEGER with a value of 100. The
|
|
following statement:
|
|
<pre class="xmp"> <span class="bold">SELECT RAND</span>(:HRAND)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
a random floating-point number between 0 and 1, such as the approximate value
|
|
.0121398.</li>
|
|
<li>To generate values in a numeric interval other than 0 to 1, multiply the
|
|
RAND function by the size of the desired interval. For example, to get a random
|
|
number between 0 and 10, such as the approximate value 5.8731398, multiply
|
|
the function by 10:
|
|
<pre class="xmp"> <span class="bold">SELECT RAND</span>(:HRAND) * 10
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="realfun"></a>
|
|
<h3 id="realfun"><a href="rbafzmst02.htm#ToC_571">REAL</a></h3><a id="idx1082" name="idx1082"></a><a id="idx1083" name="idx1083"></a>
|
|
<a href="rbafzmstscale.htm#synreal"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq804"></a>
|
|
<div class="fignone" id="wq804">
|
|
<p><span class="bold">Numeric to Real</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn172.htm"
|
|
border="0" /></span><a href="#skipsyn-171"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-REAL--(--<span class="italic">numeric-expression</span>--)------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-171" id="skipsyn-171"></a>
|
|
<p><span class="bold">String to Real</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn173.htm"
|
|
border="0" /></span><a href="#skipsyn-172"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-REAL--(--<span class="italic">string-expression</span>--)-------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-172" id="skipsyn-172"></a></div>
|
|
<a name="synreal"></a>
|
|
<p id="synreal">The REAL function returns a single-precision floating-point
|
|
representation of: </p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p><span class="bold">Numeric to Real</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>The argument is an expression that returns a value of any built-in numeric
|
|
data type.
|
|
<p>The result is the same number that would occur if the argument
|
|
were assigned to a single-precision floating-point column or variable. If
|
|
the numeric value of the argument is not within the range of single-precision
|
|
floating-point, an error is returned.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">String to Real</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a value that is a character-string or graphic-string
|
|
representation of a number.
|
|
<p>If the argument is a <var class="pv">string-expression</var>,
|
|
the result is the same number that would result from CAST( <var class="pv">string-expression</var> AS REAL). Leading and trailing blanks are eliminated and the resulting
|
|
string must conform to the rules for forming a floating-point, integer, or
|
|
decimal constant. If the numeric value of the argument is not within the range
|
|
of single-precision floating-point, an error is returned.</p>
|
|
<p>The single-byte
|
|
character constant that must be used to delimit the decimal digits in <var class="pv">string-expression</var> from the whole part of the number is the default decimal
|
|
point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a single-precision floating-point number.
|
|
If the argument can be null, the result can be null; if the argument is null,
|
|
the result is the null value.</p>
|
|
<a name="wq805"></a>
|
|
<h4 id="wq805">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq806"></a>
|
|
<h4 id="wq806">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, find the ratio of salary to commission for employees
|
|
whose commission is not zero. The columns involved (SALARY and COMM) have
|
|
DECIMAL data types. To eliminate the possibility of out-of-range results,
|
|
REAL is applied to SALARY so that the division is carried out in floating
|
|
point:
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, <span class="bold">REAL</span>(SALARY)/COMM
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> COMM > 0</pre></li></ul>
|
|
<a name="scarepeat"></a>
|
|
<h3 id="scarepeat"><a href="rbafzmst02.htm#ToC_574">REPEAT</a></h3><a id="idx1084" name="idx1084"></a><a id="idx1085" name="idx1085"></a>
|
|
<a href="rbafzmstscale.htm#synscarepeat"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq807"></a>
|
|
<div class="fignone" id="wq807">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn174.htm"
|
|
border="0" /></span><a href="#skipsyn-173"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-REPEAT--(--<span class="italic">expression</span>--,--<span class="italic">integer</span>--)------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-173" id="skipsyn-173"></a></div>
|
|
<a name="synscarepeat"></a>
|
|
<p id="synscarepeat">The REPEAT function returns a string composed of <var class="pv">expression</var> repeated <var class="pv">integer</var> times.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string to be repeated. The string must
|
|
be a built-in numeric or string expression. A numeric argument is cast to
|
|
a character string before evaluating the function. For more information on
|
|
converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd>An expression that returns a built-in BIGINT, INTEGER, or
|
|
SMALLINT data type whose value is a positive integer or zero. The integer
|
|
specifies the number of times to repeat the string.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result of the function depends on the data type of
|
|
the first argument:</p>
|
|
<a name="wq808"></a>
|
|
<table id="wq808" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq809" width="50%" align="left" valign="bottom">Data type of <span class="italic">string-expression</span></th>
|
|
<th id="wq810" width="50%" align="left" valign="bottom">Data type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq809">CHAR or VARCHAR or any numeric type</td>
|
|
<td align="left" valign="top" headers="wq810">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq809">CLOB</td>
|
|
<td align="left" valign="top" headers="wq810">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq809">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq810">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq809">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq810">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq809">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq810">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq809">BLOB</td>
|
|
<td align="left" valign="top" headers="wq810">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>If <var class="pv">integer</var> is a constant, the length attribute of the result is
|
|
the length attribute of <var class="pv">string-expression</var> times <var class="pv">integer</var>.
|
|
Otherwise, the length attribute depends on the data type of the result:</p>
|
|
<ul>
|
|
<li>1,048,576 for BLOB, CLOB, or DBCLOB</li>
|
|
<li>4000 for VARCHAR or VARBINARY</li>
|
|
<li>2000 for VARGRAPHIC</li></ul><p class="indatacontent">If the length attribute of the result exceeds the maximum for the result
|
|
data type, an error is returned.</p>
|
|
<p>The actual length of the result is the actual length of <var class="pv">string-expression</var> times <var class="pv">integer</var>. If the actual length of the result string exceeds
|
|
the maximum for the return type, an error is returned.</p>
|
|
<p>If either argument can be null, the result can be null; if either argument
|
|
is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the CCSID of <var class="pv">string-expression</var>.<sup class="fn"><a id="wq811" name="wq811" href="rbafzmstscale.htm#wq812">49</a></sup></p>
|
|
<a name="wq813"></a>
|
|
<h4 id="wq813">Examples</h4>
|
|
<ul>
|
|
<li>Repeat 'abc' two times to create 'abcabc'.
|
|
<pre class="xmp"> <span class="bold">SELECT REPEAT(</span>'abc', 2<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
|
|
</pre></li>
|
|
<li>List the phrase 'REPEAT THIS' five times. Use the CHAR function to limit
|
|
the output to 60 bytes.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR( REPEAT(</span>'REPEAT THIS', 5<span class="bold">)</span>, 60<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>This example results in 'REPEAT THISREPEAT THISREPEAT THISREPEAT THISREPEAT
|
|
THIS '.
|
|
<pre class="xmp"></pre></li>
|
|
<li>For the following query, the LENGTH function returns a value of 0 because
|
|
the result of repeating a string zero times is an empty string, which is a
|
|
zero-length string.
|
|
<pre class="xmp"> <span class="bold">SELECT LENGTH( REPEAT(</span>'REPEAT THIS', 0<span class="bold">) )</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
|
|
</pre></li>
|
|
<li>For the following query, the LENGTH function returns a value of 0 because
|
|
the result of repeating an empty string any number of times is an empty string,
|
|
which is a zero-length string.
|
|
<pre class="xmp"> <span class="bold">SELECT LENGTH( REPEAT(</span>'', 5<span class="bold">) )</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre></li></ul>
|
|
<a name="scareplace"></a>
|
|
<h3 id="scareplace"><a href="rbafzmst02.htm#ToC_576">REPLACE</a></h3><a id="idx1086" name="idx1086"></a><a id="idx1087" name="idx1087"></a>
|
|
<a href="rbafzmstscale.htm#synscareplace"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq814"></a>
|
|
<div class="fignone" id="wq814">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn175.htm"
|
|
border="0" /></span><a href="#skipsyn-174"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-REPLACE--(--<span class="italic">source-string</span>--,--<span class="italic">search-string</span>--,--<span class="italic">replace-string</span>--)-><
|
|
|
|
</pre>
|
|
<a name="skipsyn-174" id="skipsyn-174"></a></div>
|
|
<a name="synscareplace"></a>
|
|
<p id="synscareplace">The REPLACE function replaces all occurrences of <var class="pv">search-string</var> in <var class="pv">source-string</var> with <var class="pv">replace-string</var>.
|
|
If <var class="pv">search-string</var> is not found in <var class="pv">source-string</var>, <var class="pv">source-string</var> is returned unchanged.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">source-string</var></dt>
|
|
<dd>An expression that specifies the source string. The <var class="pv">source-string</var> must be a built-in numeric or string expression. A numeric argument
|
|
is cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">search-string</var></dt>
|
|
<dd>An expression that specifies the string to be removed from the source
|
|
string. The <var class="pv">search-string</var> must be a built-in numeric or string expression.
|
|
A numeric argument is cast to a character string before evaluating the function.
|
|
For more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">replace-string</var></dt>
|
|
<dd>An expression that specifies the replacement string. The <var class="pv">replace-string</var> must be a built-in numeric or string expression. A numeric argument
|
|
is cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p><var class="pv">source-string</var>, <var class="pv">search-string</var>, and <var class="pv">replace-string</var> must be compatible. For more information about data type compatibility,
|
|
see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.</p>
|
|
<p>The data type of the result of the function depends on the data type of
|
|
the arguments. The result data type is the same as if the three arguments
|
|
were concatenated except that the result is always a varying-length string.
|
|
For more information see <a href="rbafzmstuuall.htm#uuall">Conversion rules for operations that combine strings</a>.</p>
|
|
<p>The length attribute of the result depends on the arguments:</p>
|
|
<ul>
|
|
<li>If <var class="pv">search-string</var> is variable length, the length attribute of
|
|
the result is:
|
|
<pre class="xmp"> (L3 * L1)</pre></li>
|
|
<li>If the length attribute of <var class="pv">replace-string</var> is less
|
|
than or equal to the length attribute of <var class="pv">search-string</var>, the length
|
|
attribute of the result is the length attribute of <var class="pv">source-string</var></li>
|
|
<li>Otherwise, the length attribute of the result is:
|
|
<pre class="xmp"> (L3 * (L1/L2)) + MOD(L1,L2)
|
|
</pre></li></ul><p class="indatacontent">where: </p>
|
|
<pre class="xmp">L1 is the length attribute of source-string
|
|
L2 is the length attribute of search-string
|
|
L3 is the length attribute of replace-string
|
|
</pre><p class="indatacontent">If the length attribute of the result exceeds the maximum for the result
|
|
data type, an error is returned.</p>
|
|
<p>The actual length of the result is the actual length of <var class="pv">source-string</var> plus the number of occurrences of <var class="pv">search-string</var> that exist
|
|
in <var class="pv">source-string</var> multiplied by the actual length of <var class="pv">replace-string</var> minus the actual length of <var class="pv">search-string</var>. If the actual length
|
|
of the result string exceeds the maximum for the result data type, an error
|
|
is returned.</p>
|
|
<p>If any argument can be null, the result can be null; if any argument is
|
|
null, the result is the null value.</p>
|
|
<p>The CCSID of the result is determined by the CCSID of <var class="pv">source-string</var>, <var class="pv">search-string</var>, and <var class="pv">replace-string</var>. The resulting
|
|
CCSID is the same as if the three arguments were concatenated. For more information,
|
|
see <a href="rbafzmstuuall.htm#uuall">Conversion rules for operations that combine strings</a>.</p>
|
|
<a name="wq815"></a>
|
|
<h4 id="wq815">Examples</h4>
|
|
<ul>
|
|
<li>Replace all occurrences of the character 'N' in the string 'DINING' with
|
|
'VID'. Use the CHAR function to limit the output to 10 bytes.
|
|
<pre class="xmp"> <span class="bold">SELECT CHAR(REPLACE(</span> 'DINING', 'N', 'VID' <span class="bold">)</span>, 10<span class="bold">)</span>,
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>The result is the string 'DIVIDIVIDG'.
|
|
<div class="lines"> <br />
|
|
</div></li>
|
|
<li>Replace string 'ABC' in the string 'ABCXYZ' with nothing, which is the
|
|
same as removing 'ABC' from the string.
|
|
<pre class="xmp"> <span class="bold">SELECT REPLACE(</span> 'ABCXYZ', 'ABC', '' <span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>The result is the string 'XYZ'.
|
|
<div class="lines"> <br />
|
|
</div></li>
|
|
<li>Replace string 'ABC' in the string 'ABCCABCC' with 'AB'. This example
|
|
illustrates that the result can still contain the string that is to be replaced
|
|
(in this case, 'ABC') because all occurrences of the string to be replaced
|
|
are identified prior to any replacement.
|
|
<pre class="xmp"> <span class="bold">SELECT REPLACE(</span> 'ABCCABCC', 'ABC', 'AB') <span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1
|
|
</pre>The result is the string 'ABCABC'.</li></ul>
|
|
<a name="scaright"></a>
|
|
<h3 id="scaright"><a href="rbafzmst02.htm#ToC_578">RIGHT</a></h3><a id="idx1088" name="idx1088"></a><a id="idx1089" name="idx1089"></a>
|
|
<a href="rbafzmstscale.htm#synright"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq816"></a>
|
|
<div class="fignone" id="wq816">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn176.htm"
|
|
border="0" /></span><a href="#skipsyn-175"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-RIGHT--(--<span class="italic">expression</span>--,--<span class="italic">integer</span>--)-------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-175" id="skipsyn-175"></a></div>
|
|
<a name="synright"></a>
|
|
<p id="synright">The RIGHT function returns the rightmost <var class="pv">integer</var> characters
|
|
of <var class="pv">expression</var>.</p>
|
|
<p>If <var class="pv">expression</var> is a character string, the result is a character
|
|
string, and each character is one byte. If <var class="pv">expression</var> is a graphic
|
|
string, the result is a graphic string, and each character is a DBCS, UTF-16,
|
|
or UCS-2 character. If <var class="pv">expression</var> is a binary string, the result
|
|
is a binary string, and each character is one byte.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string from which the result is derived.
|
|
The string must be a built-in numeric or string expression. A numeric argument
|
|
is cast to a character string before evaluating the function. For more information
|
|
on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
<p>A substring of <var class="pv">expression</var> is zero or more contiguous characters of <var class="pv">expression</var>. If <var class="pv">expression</var> is a graphic string, a character is
|
|
a DBCS, UTF-16, or UCS-2 character. If <var class="pv">expression</var> is a character
|
|
string or binary string, a character is a byte.<sup class="fn"><a id="wq817" name="wq817" href="rbafzmstscale.htm#wq818">50</a></sup></p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd>An expression that returns a built-in integer data type. The integer
|
|
specifies the length of the result. <var class="pv">integer</var> must be greater than
|
|
or equal to 0 and less than or equal to <var class="pv">n</var>, where <var class="pv">n</var> is the
|
|
length attribute of <var class="pv">expression</var>.
|
|
<p>The <var class="pv">expression</var> is effectively
|
|
padded on the right with the necessary number of blank characters (or hexadecimal
|
|
zeroes for binary strings) so that the specified substring of <var class="pv">expression</var> always exists.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a varying-length string with a length attribute
|
|
that is the same as the length attribute of <var class="pv">expression</var> and a data
|
|
type that depends on the data type of <var class="pv">expression</var>: </p>
|
|
<a name="wq819"></a>
|
|
<table id="wq819" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq820" width="50%" align="left" valign="bottom">Data type of <span class="italic">expression</span></th>
|
|
<th id="wq821" width="50%" align="left" valign="bottom">Data type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq820">CHAR or VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq821">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq820">CLOB</td>
|
|
<td align="left" valign="top" headers="wq821">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq820">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq821">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq820">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq821">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq820">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq821">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq820">BLOB</td>
|
|
<td align="left" valign="top" headers="wq821">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The actual length of the result is <var class="pv">integer</var>.</p>
|
|
<p>If any argument can be null, the result can be null; if any argument is
|
|
null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the same as that of <var class="pv">expression</var>.</p>
|
|
<a name="wq822"></a>
|
|
<h4 id="wq822">Example</h4>
|
|
<ul>
|
|
<li>Assume that host variable ALPHA has a value of 'ABCDEF'. The following
|
|
statement:
|
|
<pre class="xmp"> <span class="bold">SELECT RIGHT(</span> :ALPHA, 3<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 'DEF', which are the three rightmost characters in ALPHA.
|
|
<div class="lines"> <br />
|
|
</div></li>
|
|
<li>The following statement returns a zero length string.
|
|
<pre class="xmp"> <span class="bold">SELECT RIGHT(</span> 'ABCABC', 0<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scaround"></a>
|
|
<h3 id="scaround"><a href="rbafzmst02.htm#ToC_580">ROUND</a></h3><a id="idx1090" name="idx1090"></a><a id="idx1091" name="idx1091"></a>
|
|
<a href="rbafzmstscale.htm#synround"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq823"></a>
|
|
<div class="fignone" id="wq823">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn177.htm"
|
|
border="0" /></span><a href="#skipsyn-176"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ROUND--(--<span class="italic">expression-1</span>--,--<span class="italic">expression-2</span>--)------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-176" id="skipsyn-176"></a></div>
|
|
<a name="synround"></a>
|
|
<p id="synround">The ROUND function returns <var class="pv">expression–1</var> rounded
|
|
to some number of places to the right or left of the decimal point.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression–1</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression–2</var></dt>
|
|
<dd>The argument must be an expression that returns a value of
|
|
a built-in BIGINT, INTEGER, or SMALLINT data type.
|
|
<p>If <var class="pv">expression–2</var> is positive, <var class="pv">expression–1</var> is rounded to the <var class="pv">expression–2</var> number of places to the right of the decimal point.</p>
|
|
<p>If <var class="pv">expression–2</var> is negative, <var class="pv">expression–1</var> is rounded to 1 + (the absolute
|
|
value of <var class="pv">expression–2</var>) number of places to the left of the
|
|
decimal point. If the absolute value of <var class="pv">expression–2</var> is greater
|
|
than the number of digits to the left of the decimal point, the result is
|
|
0. (For example, ROUND(748.58,-4) returns 0.)</p>
|
|
<p>If <var class="pv">expression–1</var> is positive, a digit value of 5 is rounded to the next higher positive
|
|
number. If <var class="pv">expression–1</var> is negative, a digit value of 5 is
|
|
rounded to the next lower negative number.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type and length attribute of the result are the same as the data
|
|
type and length attribute of the first argument, except that precision is
|
|
increased by one if <var class="pv">expression–1</var> is DECIMAL or NUMERIC and
|
|
the precision is less than the maximum precision (<var class="pv">mp</var>). For example,
|
|
an argument with a data type of DECIMAL(5,2) will result in DECIMAL(6,2).
|
|
An argument with a data type of DECIMAL(63,2) will result in DECIMAL(63,2).</p>
|
|
<p>If either argument can be null, the result can be null. If either argument
|
|
is null, the result is the null value.</p>
|
|
<a name="wq824"></a>
|
|
<h4 id="wq824">Examples</h4>
|
|
<ul>
|
|
<li>Calculate the number 873.726 rounded to 2, 1, 0, -1, -2, -3, and -4 decimal
|
|
places respectively.
|
|
<pre class="xmp"> <span class="bold">SELECT ROUND(</span>873.726, 2<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>873.726, 1<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>873.726, 0<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>873.726, -1<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>873.726, -2<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>873.726, -3<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>873.726, -4<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the following values, respectively:
|
|
<pre class="xmp">0873.730 0873.700 0874.000 0870.000 0900.000 1000.000 0000.000</pre></li>
|
|
<li>Calculate both positive and negative numbers.
|
|
<pre class="xmp"> <span class="bold">SELECT ROUND(</span> 3.5, 0<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span> 3.1, 0<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>-3.1, 0<span class="bold">),</span>
|
|
<span class="bold">ROUND(</span>-3.5, 0<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Returns
|
|
the following examples, respectively:</p>
|
|
<pre class="xmp">04.0 03.0 -03.0 -04.0</pre></li></ul>
|
|
<a name="scarowid"></a>
|
|
<h3 id="scarowid"><a href="rbafzmst02.htm#ToC_582">ROWID</a></h3><a id="idx1092" name="idx1092"></a><a id="idx1093" name="idx1093"></a>
|
|
<a href="rbafzmstscale.htm#synrowid"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq825"></a>
|
|
<div class="fignone" id="wq825">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn178.htm"
|
|
border="0" /></span><a href="#skipsyn-177"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ROWID--(--<span class="italic">string-expression</span>--)------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-177" id="skipsyn-177"></a></div>
|
|
<a name="synrowid"></a>
|
|
<p id="synrowid">The ROWID function casts a character string to a row ID.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a character string value. Although the string
|
|
can contain any value, it is recommended that it contain a ROWID value that
|
|
was previously generated by DB2 UDB for z/OS or DB2 UDB for iSeries to ensure a valid ROWID value
|
|
is returned. For example, the function can be used to convert a ROWID value
|
|
that was cast to a CHAR value back to a ROWID value.
|
|
</dd>
|
|
</dl>
|
|
<p>If the actual length of <var class="pv">string-expression</var> is less than 40, the
|
|
result is not padded. If the actual length of <var class="pv">string-expression</var> is
|
|
greater than 40, the result is truncated. If non-blank characters are truncated,
|
|
a warning is returned.</p>
|
|
<p>The length attribute of the result is 40. The actual length of the result
|
|
is the length of <var class="pv">string-expression</var>.</p>
|
|
<p>The result of the function is a row ID. If the argument can be null, the
|
|
result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq826"></a>
|
|
<h4 id="wq826">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq827"></a>
|
|
<h4 id="wq827">Example</h4>
|
|
<ul>
|
|
<li>Assume that table EMPLOYEE contains a ROWID column EMP_ROWID. Also assume
|
|
that the table contains a row that is identified by a row ID value that is
|
|
equivalent to X'F0DFD230E3C0D80D81C201AA0A280100000000000203'. Using direct
|
|
row access, select the employee number for that row.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMP_ROWID<span class="bold"> = ROWID(</span>X'F0DFD230E3C0D80D81C201AA0A280100000000000203'<span class="bold">)</span></pre></li></ul>
|
|
<a name="scarrn"></a>
|
|
<h3 id="scarrn"><a href="rbafzmst02.htm#ToC_585">RRN</a></h3><a id="idx1094" name="idx1094"></a><a id="idx1095" name="idx1095"></a>
|
|
<a href="rbafzmstscale.htm#synrrn"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq828"></a>
|
|
<div class="fignone" id="wq828">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn179.htm"
|
|
border="0" /></span><a href="#skipsyn-178"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-RRN--(--<span class="italic">table-designator</span>--)---------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-178" id="skipsyn-178"></a></div>
|
|
<a name="synrrn"></a>
|
|
<p id="synrrn">The RRN function returns the relative record number of a row.</p><a id="idx1096" name="idx1096"></a><a id="idx1097" name="idx1097"></a>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">table-designator</var></dt>
|
|
<dd>The argument must be a table designator of the subselect. For more
|
|
information about table designators, see <a href="rbafzmstch2col.htm#tdjm">Table designators</a>.
|
|
<p>In SQL naming, the table name may be qualified. In system naming, the table
|
|
name cannot be qualified.</p>
|
|
<p>If the argument identifies a view, common
|
|
table expression, or derived table, the function returns the relative record
|
|
number of its base table. If the argument identifies a view, common table
|
|
expression, or derived table derived from more than one base table, the function
|
|
returns the relative record number of the first table in the outer subselect
|
|
of the view, common table expression, or derived table.</p>
|
|
<p>If the argument
|
|
identifies a distributed table, the function returns the relative record number
|
|
of the row on the node where the row is located. If the argument identifies
|
|
a partitioned table, the function returns the relative record number of the
|
|
row in the partition where the row is located. This means that RRN will not
|
|
be unique for each row of a partitioned or distributed table.</p>
|
|
<p>The argument must not identify a view, common table expression, or derived
|
|
table whose outer subselect includes an aggregate function, a GROUP BY clause,
|
|
a HAVING clause, a UNION clause, an INTERSECT clause, or DISTINCT clause.
|
|
The RRN function cannot be specified in a SELECT clause if the subselect contains
|
|
an aggregate function, a GROUP BY clause, or a HAVING clause. If the argument
|
|
is a correlation name, the correlation name must not identify a correlated
|
|
reference.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is a decimal with precision 15 and scale 0.
|
|
The result can be null.</p>
|
|
<a name="wq829"></a>
|
|
<h4 id="wq829">Example</h4>
|
|
<ul>
|
|
<li>Return the relative record number and employee name from table EMPLOYEE
|
|
for those employees in department 20.
|
|
<pre class="xmp"> <span class="bold">SELECT RRN</span>(EMPLOYEE), LASTNAME
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> DEPTNO = 20</pre></li></ul>
|
|
<a name="scartrim"></a>
|
|
<h3 id="scartrim"><a href="rbafzmst02.htm#ToC_587">RTRIM</a></h3><a id="idx1098" name="idx1098"></a><a id="idx1099" name="idx1099"></a>
|
|
<a href="rbafzmstscale.htm#synrtrim"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq830"></a>
|
|
<div class="fignone" id="wq830">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn180.htm"
|
|
border="0" /></span><a href="#skipsyn-179"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-RTRIM--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-179" id="skipsyn-179"></a></div>
|
|
<a name="synrtrim"></a>
|
|
<p id="synrtrim">The RTRIM function removes blanks or hexadecimal zeroes from
|
|
the end of a string expression. <sup class="fn"><a id="wq831" name="wq831" href="rbafzmstscale.htm#wq832">51</a></sup></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be expressions that return a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
<ul>
|
|
<li>If the argument is a binary string, then the trailing hexadecimal zeros
|
|
(X'00') are removed.</li>
|
|
<li>If the argument is a DBCS graphic string, then the trailing DBCS blanks
|
|
are removed.</li>
|
|
<li>If the first argument is a UTF-16 or UCS-2 graphic string, then the trailing
|
|
UTF-16 or UCS-2 blanks are removed.</li>
|
|
<li>If the first argument is a UTF-8 character string, then the trailing UTF-8
|
|
blanks are removed.</li>
|
|
<li>Otherwise, trailing SBCS blanks are removed.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result depends on the data type of <span class="italic">string-expression</span>:</p>
|
|
<a name="wq833"></a>
|
|
<table id="wq833" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq834" width="50%" align="left" valign="bottom">Data type of <span class="italic">string-expression</span></th>
|
|
<th id="wq835" width="50%" align="left" valign="bottom">Data type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq834">CHAR or VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq835">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq834">CLOB</td>
|
|
<td align="left" valign="top" headers="wq835">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq834">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq835">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq834">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq835">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq834">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq835">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq834">BLOB</td>
|
|
<td align="left" valign="top" headers="wq835">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The length attribute of the result is the same as the length attribute
|
|
of <span class="italic">string-expression</span>. The actual length of the result
|
|
is the length of the expression minus the number of bytes removed. If all
|
|
characters are removed, the result is an empty string.</p>
|
|
<p>If the first argument can be null, the result can be null; if the first
|
|
argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the same as that of the string.</p>
|
|
<a name="wq836"></a>
|
|
<h4 id="wq836">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HELLO of type CHAR(9) has a value of 'Hello
|
|
'.
|
|
<pre class="xmp"><span class="bold">SELECT RTRIM(</span>:HELLO<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results
|
|
in: 'Hello'.</li></ul>
|
|
<a name="scasec"></a>
|
|
<h3 id="scasec"><a href="rbafzmst02.htm#ToC_589">SECOND</a></h3><a id="idx1100" name="idx1100"></a><a id="idx1101" name="idx1101"></a>
|
|
<a href="rbafzmstscale.htm#synsecond"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq837"></a>
|
|
<div class="fignone" id="wq837">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn181.htm"
|
|
border="0" /></span><a href="#skipsyn-180"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SECOND--(--<span class="italic">expression</span>--)------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-180" id="skipsyn-180"></a></div>
|
|
<a name="synsecond"></a>
|
|
<p id="synsecond">The SECOND function returns the seconds part of a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a time, a timestamp, a character string, a
|
|
graphic string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
time or timestamp. For the valid formats of string representations of times
|
|
and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a time duration or timestamp
|
|
duration. For the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a time, a timestamp, or a valid character-string representation
|
|
of a time or timestamp:
|
|
<p>The result is the seconds part of the value, which
|
|
is an integer between 0 and 59.</p></li>
|
|
<li>If the argument is a time duration or timestamp duration:
|
|
<p>The result
|
|
is the seconds part of the value, which is an integer between -99 and
|
|
99. A nonzero result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq838"></a>
|
|
<h4 id="wq838">Examples</h4>
|
|
<ul>
|
|
<li>Assume that the host variable TIME_DUR (DECIMAL(6,0)) has the value
|
|
153045.
|
|
<pre class="xmp"> <span class="bold">SELECT SECOND(</span>:TIME_DUR<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 45.</li>
|
|
<li>Assume that the column RECEIVED (TIMESTAMP) has an internal value equivalent
|
|
to 1988-12-25-17.12.30.000000.
|
|
<pre class="xmp"> <span class="bold">SELECT SECOND(</span>RECEIVED<span class="bold">)</span>
|
|
<span class="bold">FROM</span> IN_TRAY</pre>Returns the value
|
|
30.</li></ul>
|
|
<a name="scasign"></a>
|
|
<h3 id="scasign"><a href="rbafzmst02.htm#ToC_591">SIGN</a></h3><a id="idx1102" name="idx1102"></a><a id="idx1103" name="idx1103"></a>
|
|
<a href="rbafzmstscale.htm#synsign"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq839"></a>
|
|
<div class="fignone" id="wq839">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn182.htm"
|
|
border="0" /></span><a href="#skipsyn-181"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SIGN--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-181" id="skipsyn-181"></a></div>
|
|
<a name="synsign"></a>
|
|
<p id="synsign">The SIGN function returns an indicator of the sign of expression.
|
|
The returned value is: </p>
|
|
<dl>
|
|
<dt class="bold">–1</dt>
|
|
<dd>if the argument is less than zero
|
|
</dd>
|
|
<dt class="bold">0</dt>
|
|
<dd>if the argument is zero
|
|
</dd>
|
|
<dt class="bold">1</dt>
|
|
<dd>if the argument is greater than zero
|
|
</dd>
|
|
</dl>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result has the same data type and length attribute as the argument,
|
|
except that precision is increased by one if the argument is DECIMAL or NUMERIC
|
|
and the scale of the argument is equal to its precision. For example, an argument
|
|
with a data type of DECIMAL(5,5) will result in DECIMAL(6,5). If the precision
|
|
is already the maximum precision (<var class="pv">mp</var>), the scale will be decreased
|
|
by one. For example, DECIMAL(63,63) will result in DECIMAL(63,62).</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<a name="wq840"></a>
|
|
<h4 id="wq840">Example</h4>
|
|
<ul>
|
|
<li>Assume that host variable PROFIT is a large integer with a value of 50000.
|
|
|
|
<pre class="xmp"> <span class="bold">SELECT SIGN(</span>:PROFIT<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre>Returns the value
|
|
1.</li></ul>
|
|
<a name="scasin"></a>
|
|
<h3 id="scasin"><a href="rbafzmst02.htm#ToC_593">SIN</a></h3><a id="idx1104" name="idx1104"></a><a id="idx1105" name="idx1105"></a>
|
|
<a href="rbafzmstscale.htm#synsin"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq841"></a>
|
|
<div class="fignone" id="wq841">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn183.htm"
|
|
border="0" /></span><a href="#skipsyn-182"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SIN--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-182" id="skipsyn-182"></a></div>
|
|
<a name="synsin"></a>
|
|
<p id="synsin">The SIN function returns the sine of the argument, where the
|
|
argument is an angle expressed in radians. The SIN and ASIN functions are
|
|
inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq842"></a>
|
|
<h4 id="wq842">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable SINE is a decimal (2,1) host variable with a
|
|
value of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT SIN</span>(:SINE)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 0.99.</li></ul>
|
|
<a name="scasinh"></a>
|
|
<h3 id="scasinh"><a href="rbafzmst02.htm#ToC_595">SINH</a></h3><a id="idx1106" name="idx1106"></a><a id="idx1107" name="idx1107"></a>
|
|
<a href="rbafzmstscale.htm#synsinh"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq843"></a>
|
|
<div class="fignone" id="wq843">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn184.htm"
|
|
border="0" /></span><a href="#skipsyn-183"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SINH--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-183" id="skipsyn-183"></a></div>
|
|
<a name="synsinh"></a>
|
|
<p id="synsinh">The SINH function returns the hyperbolic sine of the argument,
|
|
where the argument is an angle expressed in radians.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq844"></a>
|
|
<h4 id="wq844">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HSINE is a decimal (2,1) host variable with a
|
|
value of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT SINH</span>(:HSINE)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 2.12.</li></ul>
|
|
<a name="smifunc"></a>
|
|
<h3 id="smifunc"><a href="rbafzmst02.htm#ToC_597">SMALLINT</a></h3><a id="idx1108" name="idx1108"></a><a id="idx1109" name="idx1109"></a>
|
|
<a href="rbafzmstscale.htm#synsmallint"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq845"></a>
|
|
<div class="fignone" id="wq845">
|
|
<p><span class="bold">Numeric to Smallint</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn185.htm"
|
|
border="0" /></span><a href="#skipsyn-184"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SMALLINT--(--<span class="italic">numeric-expression</span>--)--------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-184" id="skipsyn-184"></a>
|
|
<p><span class="bold">String to Smallint</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn186.htm"
|
|
border="0" /></span><a href="#skipsyn-185"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SMALLINT--(--<span class="italic">string-expression</span>--)---------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-185" id="skipsyn-185"></a></div>
|
|
<a name="synsmallint"></a>
|
|
<p id="synsmallint">The SMALLINT function returns a small integer representation
|
|
of </p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p><span class="bold">Numeric to Smallint</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>An expression that returns a numeric value of any built-in numeric data
|
|
type.
|
|
<p>The result is the same number that would occur if the argument were
|
|
assigned to a small integer column or variable. If the whole part of the argument
|
|
is not within the range of small integers, an error is returned. The fractional
|
|
part of the argument is truncated.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">String to Smallint</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a value that is a character-string or graphic-string
|
|
representation of a number.
|
|
<p>If the argument is a <var class="pv">string-expression</var>,
|
|
the result is the same number that would result from CAST( <var class="pv">string-expression</var> AS SMALLINT). Leading and trailing blanks are eliminated and the resulting
|
|
string must conform to the rules for forming a floating-point, integer, or
|
|
decimal constant. If the whole part of the argument is not within the range
|
|
of small integers, an error is returned. Any fractional part of the argument
|
|
is truncated.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a small integer. If the argument can be null,
|
|
the result can be null. If the argument is null, the result is the null value.</p>
|
|
<a name="wq846"></a>
|
|
<h4 id="wq846">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq847"></a>
|
|
<h4 id="wq847">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, select a list containing salary (SALARY) divided
|
|
by education level (EDLEVEL). Truncate any decimal in the calculation. The
|
|
list should also contain the values used in the calculation and the employee
|
|
number (EMPNO).
|
|
<pre class="xmp"> <span class="bold">SELECT SMALLINT</span>(SALARY / EDLEVEL), SALARY, EDLEVEL, EMPNO
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scasound"></a>
|
|
<h3 id="scasound"><a href="rbafzmst02.htm#ToC_600">SOUNDEX</a></h3><a id="idx1110" name="idx1110"></a><a id="idx1111" name="idx1111"></a>
|
|
<a href="rbafzmstscale.htm#synsoundex"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq848"></a>
|
|
<div class="fignone" id="wq848">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn187.htm"
|
|
border="0" /></span><a href="#skipsyn-186"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SOUNDEX--(--<span class="italic">expression</span>--)-----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-186" id="skipsyn-186"></a></div>
|
|
<a name="synsoundex"></a>
|
|
<p id="synsoundex">The SOUNDEX function returns a 4 character code representing
|
|
the sound of the words in the argument. The result can be used to compare
|
|
with the sound of other strings.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric or string data type, other than a CLOB or DBCLOB. The argument cannot
|
|
be a binary-string. A numeric argument is cast to a character string before
|
|
evaluating the function. For more information on converting numeric to a character
|
|
string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is CHAR(4). If the argument can be null, the
|
|
result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the default CCSID of the current server.</p>
|
|
<p>The SOUNDEX function is useful for finding strings for which the sound
|
|
is known but the precise spelling is not. It makes assumptions about the way
|
|
that letters and combinations of letters sound that can help to search out
|
|
words with similar sounds. The comparison can be done directly or by passing
|
|
the strings as arguments to the DIFFERENCE function. For more information,
|
|
see <a href="rbafzmstscale.htm#difffun">DIFFERENCE</a>.</p>
|
|
<a name="wq849"></a>
|
|
<h4 id="wq849">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, find the EMPNO and LASTNAME of the employee
|
|
with a surname that sounds like 'Loucesy'.
|
|
<pre class="xmp"> <span class="bold">SELECT</span> EMPNO, LASTNAME
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE SOUNDEX</span>(LASTNAME) = <span class="bold">SOUNDEX</span>('Loucesy')
|
|
</pre>Returns the row:
|
|
<pre class="xmp">000110 LUCCHESSI</pre></li></ul>
|
|
<a name="scaspace"></a>
|
|
<h3 id="scaspace"><a href="rbafzmst02.htm#ToC_602">SPACE</a></h3><a id="idx1112" name="idx1112"></a><a id="idx1113" name="idx1113"></a>
|
|
<a href="rbafzmstscale.htm#synspace"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq850"></a>
|
|
<div class="fignone" id="wq850">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn188.htm"
|
|
border="0" /></span><a href="#skipsyn-187"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SPACE--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-187" id="skipsyn-187"></a></div>
|
|
<a name="synspace"></a>
|
|
<p id="synspace">The SPACE function returns a character string that consists
|
|
of the number of SBCS blanks that the argument specifies.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric,
|
|
character-string, or graphic-string data type. A string argument is converted
|
|
to integer before evaluating the function. For more information on converting
|
|
strings to integer, see <a href="rbafzmstscale.htm#intfunc">INTEGER or INT</a>.
|
|
<p>The <var class="pv">expression</var> specifies
|
|
the number of SBCS blanks for the result, and it must be between 0 and 32740.
|
|
If <var class="pv">expression</var> is a constant, it must not be the constant 0.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a varying-length character string
|
|
(VARCHAR) that contains SBCS data.</p>
|
|
<p>If <var class="pv">expression</var> is a constant, the length attribute of the result
|
|
is the constant. Otherwise, the length attribute of the result is 4000. The
|
|
actual length of the result is the value of <var class="pv">expression</var>. The actual
|
|
length of the result must not be greater than the length attribute of the
|
|
result.</p>
|
|
<p>If the argument can be null, the result can be null; if the argument is
|
|
null, the result is the null value.</p>
|
|
<p>The CCSID is the default CCSID for SBCS data of the job.</p>
|
|
<a name="wq851"></a>
|
|
<h4 id="wq851">Example</h4>
|
|
<ul>
|
|
<li>The following statement returns a character string that consists of 5
|
|
blanks.
|
|
<pre class="xmp"> <span class="bold">SELECT SPACE(</span>5<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1 </pre></li></ul>
|
|
<a name="scasqrt"></a>
|
|
<h3 id="scasqrt"><a href="rbafzmst02.htm#ToC_604">SQRT</a></h3><a id="idx1114" name="idx1114"></a><a id="idx1115" name="idx1115"></a>
|
|
<a href="rbafzmstscale.htm#synsqrt"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq852"></a>
|
|
<div class="fignone" id="wq852">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn189.htm"
|
|
border="0" /></span><a href="#skipsyn-188"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-SQRT--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-188" id="skipsyn-188"></a></div>
|
|
<a name="synsqrt"></a>
|
|
<p id="synsqrt">The SQRT function returns the square root of a number.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>. The
|
|
value of <var class="pv">expression</var> must be greater than or equal to zero.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq853"></a>
|
|
<h4 id="wq853">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable SQUARE is a DECIMAL(2,1) host variable with a
|
|
value of 9.0.
|
|
<pre class="xmp"> <span class="bold">SELECT SQRT</span>(:SQUARE)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 3.00.</li></ul>
|
|
<a name="strpfun"></a>
|
|
<h3 id="strpfun"><a href="rbafzmst02.htm#ToC_606">STRIP</a></h3><a id="idx1116" name="idx1116"></a><a id="idx1117" name="idx1117"></a>
|
|
<a href="rbafzmstscale.htm#synstrip"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq854"></a>
|
|
<div class="fignone" id="wq854">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn190.htm"
|
|
border="0" /></span><a href="#skipsyn-189"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-STRIP--(--<span class="italic">expression</span>--+-----------------------------------------+--)-><
|
|
'-+-,--BOTH-----+--+--------------------+-'
|
|
+-,--B--------+ '-,--<span class="italic">strip-character</span>-'
|
|
+-,--LEADING--+
|
|
+-,--L--------+
|
|
+-,--TRAILING-+
|
|
'-,--T--------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-189" id="skipsyn-189"></a></div>
|
|
<a name="synstrip"></a>
|
|
<p id="synstrip">The STRIP function removes blanks or another specified character
|
|
from the end and/or beginning of a string expression.</p>
|
|
<p>The STRIP function is identical to the TRIM scalar function. For more information,
|
|
see <a href="rbafzmstscale.htm#trimfun">TRIM</a>.</p>
|
|
<a name="scasubstr"></a>
|
|
<h3 id="scasubstr"><a href="rbafzmst02.htm#ToC_607">SUBSTRING or SUBSTR</a></h3><a id="idx1118" name="idx1118"></a><a id="idx1119" name="idx1119"></a><a id="idx1120" name="idx1120"></a>
|
|
<a href="rbafzmstscale.htm#synsubstr"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq855"></a>
|
|
<div class="fignone" id="wq855">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn191.htm"
|
|
border="0" /></span><a href="#skipsyn-190"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-+-SUBSTR----+--(--<span class="italic">expression</span>--,--<span class="italic">start</span>--+-----------+--)---+-><
|
|
| '-SUBSTRING-' '-,--<span class="italic">length</span>-' |
|
|
'-SUBSTRING--(--<span class="italic">expression</span>--FROM--<span class="italic">start</span>--+--------------+--)-'
|
|
'- FOR--<span class="italic">length</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-190" id="skipsyn-190"></a></div>
|
|
<a name="synsubstr"></a>
|
|
<p id="synsubstr">The SUBSTR and SUBSTRING functions return a substring of
|
|
a string.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string from which the result is derived.
|
|
<p><var class="pv">Expression</var> must be any built-in numeric or string data type. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
If <var class="pv">expression</var> is a character string, the result of the function is
|
|
a character string. If it is a graphic string, the result of the function
|
|
is a graphic string. If it is a binary string, the result of the function
|
|
is a binary string.</p>
|
|
<p>A substring of <var class="pv">expression</var> is zero or more
|
|
contiguous characters of <var class="pv">expression</var>. If <var class="pv">expression</var> is a
|
|
graphic string, a character is a DBCS, UTF-16, or UCS-2 character. If <var class="pv">expression</var> is a character string and the function is SUBSTRING, a character
|
|
is a character that may consist of one or more bytes. If <var class="pv">expression</var> is
|
|
a character string and the function is SUBSTR, a character is a byte.<sup class="fn"><a id="wq856" name="wq856" href="rbafzmstscale.htm#wq857">52</a></sup> If <var class="pv">expression</var> is a binary string,
|
|
a character is a byte.</p>
|
|
<p>If the function is SUBSTRING and the
|
|
argument is a UTF-8 or UTF-16 string, the query cannot contain:</p>
|
|
<ul>
|
|
<li>EXCEPT or INTERSECT operations,</li>
|
|
<li>OLAP specifications,</li>
|
|
<li>recursive common table expressions,</li>
|
|
<li>ORDER OF, or</li>
|
|
<li>scalar fullselects (scalar subselects are supported).</li></ul>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">start</var></dt>
|
|
<dd>An expression that specifies the position within <var class="pv">expression</var> of the first character (or byte) of the result. The expression
|
|
must return a value that is a built-in BIGINT, INTEGER, or SMALLINT data type. <var class="pv">start</var> may be negative or zero. It may also be greater than the length
|
|
attribute of <var class="pv">expression</var>. (The length attribute of a varying-length
|
|
string is its maximum length.)
|
|
</dd>
|
|
</dl>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd>An expression that specifies the length of the result. If
|
|
specified, <var class="pv">length</var> must be an expression that returns a value that
|
|
is a built-in BIGINT, INTEGER, or SMALLINT data type. The value must be greater
|
|
than or equal to 0 and less than or equal to <var class="pv">n</var>, where <var class="pv">n</var> is
|
|
the length attribute of <var class="pv">expression</var> - <var class="pv">start</var> + 1.
|
|
<p>If SUBSTR
|
|
is specified and <var class="pv">length</var> is explicitly specified, <var class="pv">expression</var> is
|
|
effectively padded on the right with the necessary number of blank characters
|
|
so that the specified substring of <var class="pv">expression</var> always exists. Hexadecimal
|
|
zeroes are used as the padding character when <var class="pv">expression</var> is a binary
|
|
string.</p>
|
|
<p>If SUBSTRING is specified and <var class="pv">length</var> is explicitly
|
|
specified, padding is not performed.</p>
|
|
<p>If <var class="pv">expression</var> is a fixed-length
|
|
string, omission of <var class="pv">length</var> is an implicit specification of LENGTH(<var class="pv">expression</var>) - <var class="pv">start</var> + 1, which is the number of characters (or
|
|
bytes) from the <var class="pv">start</var> character (or byte) to the last character (or
|
|
byte) of <var class="pv">expression</var>. If <var class="pv">expression</var> is a varying-length string,
|
|
omission of <var class="pv">length</var> is an implicit specification of zero or LENGTH(<var class="pv">expression</var>) - <var class="pv">start</var> + 1, whichever is greater. If the resulting
|
|
length is zero, the result is the empty string.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result depends on the data type of <var class="pv">expression</var> and whether the function is a SUBSTR or SUBSTRING:</p>
|
|
<a name="wq858"></a>
|
|
<table id="wq858" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq859" width="25%" align="left" valign="bottom">Data type of <span class="italic">expression</span></th>
|
|
<th id="wq860" width="25%" align="left" valign="bottom">Data Type of the Result for SUBSTRING</th>
|
|
<th id="wq861" width="49%" align="left" valign="bottom">Data Type of the Result for SUBSTR</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq859">CHAR or VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq860">VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq861">CHAR, if:
|
|
<ul>
|
|
<li> <var class="pv">length</var> is explicitly specified by an integer constant.</li>
|
|
<li><var class="pv">length</var> is not explicitly specified, but <var class="pv">expression</var> is
|
|
a fixed-length string and <var class="pv">start</var> is an integer constant.</li></ul> VARCHAR, in all other cases</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq859">CLOB</td>
|
|
<td align="left" valign="top" headers="wq860">CLOB</td>
|
|
<td align="left" valign="top" headers="wq861">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq859">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq860">VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq861">GRAPHIC, if:
|
|
<ul>
|
|
<li><var class="pv">length</var> is explicitly specified by an integer constant
|
|
that is greater than zero.</li>
|
|
<li><var class="pv">length</var> is not explicitly specified, but <var class="pv">expression</var> is a fixed-length string and <var class="pv">start</var> is an integer constant that
|
|
is greater than zero.</li></ul>VARGRAPHIC, in all other cases.</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq859">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq860">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq861">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq859">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq860">VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq861">BINARY, if:
|
|
<ul>
|
|
<li><var class="pv">length</var> is explicitly specified by an integer constant
|
|
that is greater than zero.</li>
|
|
<li><var class="pv">length</var> is not explicitly specified, but <var class="pv">expression</var> is a fixed-length string and <var class="pv">start</var> is an integer constant that
|
|
is greater than zero.</li></ul>VARBINARY, in all other cases.</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq859">BLOB</td>
|
|
<td align="left" valign="top" headers="wq860">BLOB</td>
|
|
<td align="left" valign="top" headers="wq861">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p> If the SUBSTRING function is specified, the length attribute of the result
|
|
is equal to the length attribute of <var class="pv">expression</var>.</p>
|
|
<p>If the SUBSTR function is specified and <var class="pv">expression</var> is not a LOB,
|
|
the length attribute of the result depends on <var class="pv">length</var>, <var class="pv">start</var>,
|
|
and the attributes of <var class="pv">expression</var>. </p>
|
|
<ul>
|
|
<li>If <var class="pv">length</var> is explicitly specified by an integer constant, the
|
|
length attribute of the result is <var class="pv">length</var>.</li>
|
|
<li>If <var class="pv">length</var> is not explicitly specified, but <var class="pv">expression</var> is
|
|
a fixed-length string and <var class="pv">start</var> is an integer constant, the length
|
|
attribute of the result is LENGTH(<var class="pv">expression</var>) - <var class="pv">start</var> +
|
|
1.</li></ul>
|
|
<p>In all other cases, the length attribute of the result is the same as the
|
|
length attribute of <var class="pv">expression</var>. (Remember that if the actual length
|
|
of <var class="pv">expression</var> is less than the value for <var class="pv">start</var>, the actual
|
|
length of the substring is zero.)</p>
|
|
<p>If any argument of the SUBSTR function can be null, the result can be null;
|
|
if any argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the same as that of <var class="pv">expression</var>.</p>
|
|
<a name="wq862"></a>
|
|
<h4 id="wq862">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable NAME (VARCHAR(50)) has a value of 'KATIE
|
|
AUSTIN' and the host variable SURNAME_POS (INTEGER) has a value of
|
|
7.
|
|
<pre class="xmp"> <span class="bold">SELECT SUBSTR(</span>:NAME, :SURNAME_POS<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 'AUSTIN'.</li>
|
|
<li>Likewise,
|
|
<pre class="xmp"> <span class="bold">SELECT SUBSTR(</span>:NAME, :SURNAME_POS, 1<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 'A'.</li>
|
|
<li>Select all rows from the PROJECT table for which the project name (PROJNAME)
|
|
starts with the word 'OPERATION '.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> PROJECT
|
|
<span class="bold">WHERE SUBSTR(</span>PROJNAME,1,10<span class="bold">)</span> = 'OPERATION '</pre> The space at the end of the constant is necessary
|
|
to preclude initial words such as 'OPERATIONS'.</li></ul>
|
|
<a name="scatan"></a>
|
|
<h3 id="scatan"><a href="rbafzmst02.htm#ToC_609">TAN</a></h3><a id="idx1121" name="idx1121"></a><a id="idx1122" name="idx1122"></a>
|
|
<a href="rbafzmstscale.htm#syntan"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq863"></a>
|
|
<div class="fignone" id="wq863">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn192.htm"
|
|
border="0" /></span><a href="#skipsyn-191"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TAN--(--<span class="italic">expression</span>--)---------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-191" id="skipsyn-191"></a></div>
|
|
<a name="syntan"></a>
|
|
<p id="syntan">The TAN function returns the tangent of the argument, where
|
|
the argument is an angle expressed in radians. The TAN and ATAN functions
|
|
are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq864"></a>
|
|
<h4 id="wq864">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable TANGENT is a DECIMAL(2,1) host variable with
|
|
a value of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT TAN</span>(:TANGENT)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 14.10.</li></ul>
|
|
<a name="scatanh"></a>
|
|
<h3 id="scatanh"><a href="rbafzmst02.htm#ToC_611">TANH</a></h3><a id="idx1123" name="idx1123"></a><a id="idx1124" name="idx1124"></a>
|
|
<a href="rbafzmstscale.htm#syntanh"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq865"></a>
|
|
<div class="fignone" id="wq865">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn193.htm"
|
|
border="0" /></span><a href="#skipsyn-192"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TANH--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-192" id="skipsyn-192"></a></div>
|
|
<a name="syntanh"></a>
|
|
<p id="syntanh">The TANH function returns the hyperbolic tangent of the argument,
|
|
where the argument is an angle expressed in radians. The TANH and ATANH functions
|
|
are inverse operations.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result is double-precision floating point. If the
|
|
argument can be null, the result can be null; if the argument is null, the
|
|
result is the null value.</p>
|
|
<a name="wq866"></a>
|
|
<h4 id="wq866">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable HTANGENT is a DECIMAL(2,1) host variable with
|
|
a value of 1.5.
|
|
<pre class="xmp"> <span class="bold">SELECT TANH</span>(:HTANGENT)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the approximate value 0.90.</li></ul>
|
|
<a name="scatime"></a>
|
|
<h3 id="scatime"><a href="rbafzmst02.htm#ToC_613">TIME</a></h3><a id="idx1125" name="idx1125"></a><a id="idx1126" name="idx1126"></a>
|
|
<a href="rbafzmstscale.htm#syntime"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq867"></a>
|
|
<div class="fignone" id="wq867">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn194.htm"
|
|
border="0" /></span><a href="#skipsyn-193"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TIME--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-193" id="skipsyn-193"></a></div>
|
|
<a name="syntime"></a>
|
|
<p id="syntime">The TIME function returns a time from a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a time, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a time or timestamp. For the valid formats of string representations of
|
|
times and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a time. If the argument can be null, the
|
|
result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a time:
|
|
<p>The result is that time.</p></li>
|
|
<li>If the argument is a timestamp:
|
|
<p>The result is the time part of the
|
|
timestamp.</p></li>
|
|
<li>If the argument is a character string:
|
|
<p>The result is the time or time
|
|
part of the timestamp represented by the character string. When a string representation
|
|
of a time is SBCS with a CCSID that is not the same as the default CCSID for
|
|
SBCS data, that value is converted to adhere to the default CCSID for SBCS
|
|
data before it is interpreted and converted to a time value.</p>
|
|
<p>When a
|
|
string representation of a time is mixed data with a CCSID that is not the
|
|
same as the default CCSID for mixed data, that value is converted to adhere
|
|
to the default CCSID for mixed data before it is interpreted and converted
|
|
to a time value.</p></li></ul>
|
|
<a name="wq868"></a>
|
|
<h4 id="wq868">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq869"></a>
|
|
<h4 id="wq869">Example</h4>
|
|
<ul>
|
|
<li>Select all notes from the IN_TRAY sample table that were received at
|
|
least one hour later in the day (any day) than the current time.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> IN_TRAY
|
|
<span class="bold">WHERE TIME(</span>RECEIVED<span class="bold">)</span> >= <span class="bold">CURRENT TIME</span> + 1 <span class="bold">HOUR</span></pre></li></ul>
|
|
<a name="scatimestamp"></a>
|
|
<h3 id="scatimestamp"><a href="rbafzmst02.htm#ToC_616">TIMESTAMP</a></h3><a id="idx1127" name="idx1127"></a><a id="idx1128" name="idx1128"></a>
|
|
<a href="rbafzmstscale.htm#syntimestamp"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq870"></a>
|
|
<div class="fignone" id="wq870">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn195.htm"
|
|
border="0" /></span><a href="#skipsyn-194"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TIMESTAMP--(--<span class="italic">expression-1</span>--+-----------------+--)----------><
|
|
'-,--<span class="italic">expression-2</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-194" id="skipsyn-194"></a></div>
|
|
<a name="syntimestamp"></a>
|
|
<p id="syntimestamp">The TIMESTAMP function returns a timestamp from its argument
|
|
or arguments.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression-1</var></dt>
|
|
<dd>If only one argument is specified, the argument must be an expression
|
|
that returns a value of one of the following built-in data types: a timestamp,
|
|
a character string, or a graphic string. If <var class="pv">expression-1</var> is a character
|
|
or graphic string, it must not be a CLOB or DBCLOB and its value must be one
|
|
of the following:
|
|
<ul>
|
|
<li>A valid string representation of a date or timestamp. For the valid formats
|
|
of string representations of dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>A string with an actual length of 7 that represents a valid date in the
|
|
form yyyynnn, where yyyy are digits denoting a year, and nnn are digits between
|
|
001 and 366 denoting a day of that year.</li>
|
|
<li>A string with an actual length of 14 that represents a valid date and
|
|
time in the form yyyyxxddhhmmss, where yyyy is year, xx is month, dd is day,
|
|
hh is hour, mm is minute, and ss is seconds.</li>
|
|
<li>A character string with an actual length of 13 that is assumed
|
|
to be a result from the GENERATE_UNIQUE function.</li></ul>
|
|
<p>If both arguments are specified, the first argument must be an expression
|
|
that returns a value of one of the following built-in data types: a date,
|
|
a character string, or a graphic string. If <var class="pv">expression-1</var> is a character
|
|
or graphic string, it must not be a CLOB or DBCLOB and its value must be a
|
|
valid string representation of a date.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression-2</var></dt>
|
|
<dd>The second argument must be an expression that returns a value of one
|
|
of the following built-in data types: a time, a character string, or a graphic
|
|
string.
|
|
<p>If <var class="pv">expression-2</var> is a character or graphic string, it must
|
|
not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a time. For the valid formats of string representations of times, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a timestamp. If either argument can be null,
|
|
the result can be null; if either argument is null, the result is the null
|
|
value.</p>
|
|
<p>The other rules depend on whether the second argument is specified: </p>
|
|
<ul>
|
|
<li>If both arguments are specified:
|
|
<p>The result is a timestamp with the
|
|
date specified by the first argument and the time specified by the second
|
|
argument. The microsecond part of the timestamp is zero.</p></li>
|
|
<li>If only one argument is specified and it is a timestamp:
|
|
<p>The result
|
|
is that timestamp.</p></li>
|
|
<li>If only one argument is specified and it is a character string:
|
|
<p>The
|
|
result is the timestamp represented by that character string. If the argument
|
|
is a character string of length 14, the timestamp has a microsecond part of
|
|
zero.</p></li></ul>
|
|
<p>When a string representation of a date, time, or timestamp is SBCS data
|
|
with a CCSID that is not the same as the default CCSID for SBCS data, that
|
|
value is converted to adhere to the default CCSID for SBCS data before it
|
|
is interpreted and converted to a timestamp value.</p>
|
|
<p>When a string representation of a date, time, or timestamp is mixed data
|
|
with a CCSID that is not the same as the default CCSID for mixed data, that
|
|
value is converted to adhere to the default CCSID for mixed data before it
|
|
is interpreted and converted to a timestamp value.</p>
|
|
<a name="wq871"></a>
|
|
<h4 id="wq871">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> If only one argument is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq872"></a>
|
|
<h4 id="wq872">Example</h4>
|
|
<ul>
|
|
<li>Assume the following date and time values:
|
|
<pre class="xmp"> <span class="bold">SELECT TIMESTAMP( DATE(</span>'1988-12-25'<span class="bold">)</span>, <span class="bold">TIME(</span>'17.12.30'<span class="bold">) )</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value '1988-12-25-17.12.30.000000'.</li></ul>
|
|
<a name="scaisotmsp"></a>
|
|
<h3 id="scaisotmsp"><a href="rbafzmst02.htm#ToC_619">TIMESTAMP_ISO</a></h3><a id="idx1129" name="idx1129"></a><a id="idx1130" name="idx1130"></a>
|
|
<a href="rbafzmstscale.htm#syntimestampiso"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq873"></a>
|
|
<div class="fignone" id="wq873">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn196.htm"
|
|
border="0" /></span><a href="#skipsyn-195"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TIMESTAMP_ISO--(--<span class="italic">expression</span>--)-----------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-195" id="skipsyn-195"></a></div>
|
|
<a name="syntimestampiso"></a>
|
|
<p id="syntimestampiso">Returns a timestamp value based on date, time, or
|
|
timestamp argument. If the argument is a date, it inserts zero for the time
|
|
and microseconds parts of the timestamp. If the argument is a time, it inserts
|
|
the value of CURRENT DATE for the date part of the timestamp and zero for
|
|
the microseconds part of the timestamp.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a timestamp, a date, a time, a character string,
|
|
or a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date, time, or timestamp. For the valid formats of string representations
|
|
of dates, times, and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a timestamp. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>When a string representation of a date, time, or timestamp is SBCS data
|
|
with a CCSID that is not the same as the default CCSID for SBCS data, that
|
|
value is converted to adhere to the default CCSID for SBCS data before it
|
|
is interpreted and converted to a timestamp value.</p>
|
|
<p>When a string representation of a date, time, or timestamp is mixed data
|
|
with a CCSID that is not the same as the default CCSID for mixed data, that
|
|
value is converted to adhere to the default CCSID for mixed data before it
|
|
is interpreted and converted to a timestamp value.</p>
|
|
<a name="wq874"></a>
|
|
<h4 id="wq874">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> The CAST specification should
|
|
be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq875"></a>
|
|
<h4 id="wq875">Example</h4>
|
|
<ul>
|
|
<li>Assume the following date value:
|
|
<pre class="xmp"> <span class="bold">SELECT TIMESTAMP_ISO( DATE(</span> '1988-12-25' <span class="bold">) )</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value '1988-12-25-00.00.00.000000'.</li></ul>
|
|
<a name="scatimedifstmp"></a>
|
|
<h3 id="scatimedifstmp"><a href="rbafzmst02.htm#ToC_622">TIMESTAMPDIFF</a></h3><a id="idx1131" name="idx1131"></a><a id="idx1132" name="idx1132"></a>
|
|
<a href="rbafzmstscale.htm#syntimestampdiff"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq876"></a>
|
|
<div class="fignone" id="wq876">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn197.htm"
|
|
border="0" /></span><a href="#skipsyn-196"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TIMESTAMPDIFF--(--<span class="italic">numeric-expression</span>--,--<span class="italic">string-expression</span>--)-><
|
|
|
|
</pre>
|
|
<a name="skipsyn-196" id="skipsyn-196"></a></div>
|
|
<a name="syntimestampdiff"></a>
|
|
<p id="syntimestampdiff">The TIMESTAMPDIFF function returns an estimated number
|
|
of intervals of the type defined by the first argument, based on the difference
|
|
between two timestamps.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>The first argument must be a built-in data type of either INTEGER or
|
|
SMALLINT. Valid values of interval (the first argument) are:
|
|
<a name="wq877"></a>
|
|
<table id="wq877" width="100%" summary="" border="0" frame="void" rules="all">
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td><span class="bold">1</span></td>
|
|
<td>Fractions of a second</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">2</span></td>
|
|
<td>Seconds</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">4</span></td>
|
|
<td>Minutes</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">8</span></td>
|
|
<td>Hours</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">16</span></td>
|
|
<td>Days</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">32</span></td>
|
|
<td>Weeks</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">64</span></td>
|
|
<td>Months</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">128</span></td>
|
|
<td>Quarters</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="bold">256</span></td>
|
|
<td>Years</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd><var class="pv">string-expression</var> is the result of subtracting two timestamps
|
|
and converting the result to a string of length 22. The argument must be an
|
|
expression that returns a value of a built-in character string or a graphic
|
|
string.
|
|
<p>If <var class="pv">string-expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is an integer. If either argument can be null,
|
|
the result can be null; if either argument is null, the result is the null
|
|
value.</p>
|
|
<p>The following assumptions may be used in estimating the difference: </p>
|
|
<ul>
|
|
<li>there are 365 days in a year</li>
|
|
<li>there are 30 days in a month</li>
|
|
<li>there are 24 hours in a day</li>
|
|
<li>there are 60 minutes in an hour</li>
|
|
<li>there are 60 seconds in a minute</li></ul>
|
|
<p>These assumptions are used when converting the information in the second
|
|
argument, which is a timestamp duration, to the interval type specified in
|
|
the first argument. The returned estimate may vary by a number of days. For
|
|
example, if the number of days (interval 16) is requested for a difference
|
|
in timestamps for '1997-03-01-00.00.00' and '1997-02-01-00.00.00', the result
|
|
is 30. This is because the difference between the timestamps is 1 month so
|
|
the assumption of 30 days in a month applies.</p>
|
|
<a name="wq878"></a>
|
|
<h4 id="wq878">Example</h4>
|
|
<ul>
|
|
<li>Estimate the age of employees in months.
|
|
<pre class="xmp"><span class="bold">SELECT
|
|
TIMESTAMPDIFF(</span>64,
|
|
<span class="bold">CAST(CURRENT_TIMESTAMP-CAST(</span>BIRTHDATE<span class="bold"> AS TIMESTAMP) AS CHAR(22)))
|
|
AS</span> AGE_IN_MONTHS
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scatrans"></a>
|
|
<h3 id="scatrans"><a href="rbafzmst02.htm#ToC_624">TRANSLATE</a></h3><a id="idx1133" name="idx1133"></a><a id="idx1134" name="idx1134"></a>
|
|
<a href="rbafzmstscale.htm#syntranslate"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq879"></a>
|
|
<div class="fignone" id="wq879">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn198.htm"
|
|
border="0" /></span><a href="#skipsyn-197"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TRANSLATE---------------------------------------------------->
|
|
|
|
>--(--<span class="italic">expression</span>--+----------------------------------------------+--)-><
|
|
'-,--<span class="italic">to-string</span>--+----------------------------+-'
|
|
'-,--<span class="italic">from-string</span>--+--------+-'
|
|
'-,--<span class="italic">pad</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-197" id="skipsyn-197"></a></div>
|
|
<a name="syntranslate"></a>
|
|
<p id="syntranslate">The TRANSLATE function returns a value in which one or
|
|
more characters in <span class="italic">expression</span> may have been converted
|
|
into other characters.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string to be converted <span class="italic">expression</span> must be any built-in numeric or string data type. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">to-string</var></dt>
|
|
<dd>A string that specifies the characters to which certain characters in <span class="italic">expression</span> are to be converted. This string is sometimes
|
|
called the <span class="italic">output translation table</span>. The string must
|
|
be any built-in numeric or string constant. A numeric argument is cast to
|
|
a character string before evaluating the function. For more information on
|
|
converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>. A
|
|
character string argument must have an actual length that is not greater than
|
|
256.
|
|
<p>If the length attribute of the <span class="italic">to-string</span> is
|
|
less than the length attribute of the <span class="italic">from-string</span>,
|
|
then the <span class="italic">to-string</span> is padded to the longer length
|
|
using either the <span class="italic">pad</span> character if it is specified
|
|
or a blank if a <span class="italic">pad</span> character is not specified. If
|
|
the length attribute of the <span class="italic">to-string</span> is greater than
|
|
the length attribute of the <span class="italic">from-string</span>, the extra
|
|
characters in <span class="italic">to-string</span> are ignored without warning.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">from-string</var></dt>
|
|
<dd>A string that specifies the characters that if found in <span class="italic">expression</span> are to be converted. This string is sometimes called the <span class="italic">input translation table</span>. When a character in <span class="italic">from-string</span> is found, the character in <span class="italic">expression</span> is converted to the character in <span class="italic">to-string</span> that
|
|
is in the corresponding position of the character in <span class="italic">from-string</span>.
|
|
<p>The string must be any built-in numeric or string constant. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
A character string argument must have an actual length that is not greater
|
|
than 256.</p>
|
|
<p>If there are duplicate characters in <span class="italic">from-string</span>, the first one scanning from the left is used and no warning is issued.
|
|
The default value for <span class="italic">from-string</span> is a string starting
|
|
with the character X'00' and ending with the character X'FF' (decimal 255).</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">pad</var></dt>
|
|
<dd>A string that specifies the character with which to pad <span class="italic">to-string</span> if its length is less than <span class="italic">from-string</span>.
|
|
The string must be a character string constant with a length of 1. The default
|
|
is an SBCS blank.
|
|
</dd>
|
|
</dl>
|
|
<p>If the first argument is a UTF-16, UCS-2, or UTF-8 string, no other arguments
|
|
may be specified.</p>
|
|
<p>If only the first argument is specified, the SBCS characters of the argument
|
|
are converted to uppercase, based on the CCSID of the argument. Only SBCS
|
|
characters are converted. The characters a-z are converted to A-Z, and characters
|
|
with diacritical marks are converted to their uppercase equivalent, if any.
|
|
If the first argument is UTF–16, UCS-2, or UTF-8, the alphabetic UTF-16,
|
|
UCS-2, or UTF-8 characters are converted to uppercase. Refer to the <a href="../nls/rbagsucslevel1maptble.htm">UCS-2 level 1 mapping tables</a> section of the <a href="../nls/rbagsglobalmain.htm">Globalization</a> topic in the iSeries Information Center for a description of the monocasing tables that
|
|
are used for this conversion.</p>
|
|
<p>If more than one argument is specified, the result string is built character
|
|
by character from <span class="italic">expression</span>, converting characters
|
|
in <span class="italic">from-string</span> to the corresponding character in <span class="italic">to-string</span>. For each character in <span class="italic">expression</span>, the same character is searched for in <span class="italic">from-string</span>. If the character is found to be the <span class="italic">n</span>th character
|
|
in <span class="italic">from-string</span>, the resulting string will contain
|
|
the <span class="italic">n</span>th character from <span class="italic">to-string</span>. If <span class="italic">to-string</span> is less than <span class="italic">n</span> characters long, the resulting string will contain the pad character.
|
|
If the character is not found in <span class="italic">from-string</span>, it is
|
|
moved to the result string unconverted.</p>
|
|
<p>Conversion is done on a byte basis and, if used improperly, may result
|
|
in an invalid mixed string. The SRTSEQ attribute does not apply to the TRANSLATE
|
|
function.</p>
|
|
<p>The result of the function has the same data type, length attribute, actual
|
|
length, and CCSID as the argument. If the first argument can be null, the
|
|
result can be null. If the argument is null, the result is the null value.</p>
|
|
<p>When TRANSLATE is specified in a query, the query cannot contain:</p>
|
|
<ul>
|
|
<li>EXCEPT or INTERSECT operations,</li>
|
|
<li>OLAP specifications,</li>
|
|
<li>recursive common table expressions,</li>
|
|
<li>ORDER OF, or</li>
|
|
<li>scalar fullselects (scalar subselects are supported).</li></ul>
|
|
<a name="wq880"></a>
|
|
<h4 id="wq880">Examples</h4>
|
|
<ul>
|
|
<li>Monocase the string 'abcdef'.
|
|
<pre class="xmp"> <span class="bold">SELECT TRANSLATE</span>('abcdef')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 'ABCDEF'.</li>
|
|
<li>Monocase the mixed character string.
|
|
<pre class="xmp"></pre>
|
|
<p><tt class="xph"> <span class="bold">SELECT TRANSLATE</span>(</tt>
|
|
<img src="rv2w957.gif" alt="Monocased mixed character string" /><tt class="xph">)</tt></p>
|
|
<p><tt class="xph"> <span class="bold">FROM</span> SYSIBM.SYSDUMMY1</tt></p>
|
|
<p>Returns the value
|
|
<img src="rv2w958.gif" alt="Result of TRANSLATE" /></p></li>
|
|
<li>Given that the host variable SITE is a varying-length character string
|
|
with a value of 'Pivabiska Lake Place'.
|
|
<pre class="xmp"> <span class="bold">SELECT TRANSLATE</span>(:SITE, '$', 'L')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 'Pivabiska $ake Place'.
|
|
<p></p>
|
|
<pre class="xmp"> <span class="bold">SELECT TRANSLATE</span>(:SITE, '$$', 'Ll')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre><p class="indatacontent">Returns
|
|
the value 'Pivabiska $ake P$ace'.</p>
|
|
<p></p>
|
|
<pre class="xmp"> <span class="bold">SELECT TRANSLATE</span>(:SITE, 'pLA', 'Place', '.')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre><p class="indatacontent">Returns
|
|
the value 'pivAbiskA LAk. pLA..'.</p></li></ul>
|
|
<a name="trimfun"></a>
|
|
<h3 id="trimfun"><a href="rbafzmst02.htm#ToC_626">TRIM</a></h3><a id="idx1135" name="idx1135"></a><a id="idx1136" name="idx1136"></a>
|
|
<a href="rbafzmstscale.htm#syntrim"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq881"></a>
|
|
<div class="fignone" id="wq881">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn199.htm"
|
|
border="0" /></span><a href="#skipsyn-198"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-TRIM--(--+-----------------------------------------+--<span class="italic">expression</span>--)-><
|
|
| .-BOTH-----. |
|
|
'-+----------+--+-----------------+--FROM-'
|
|
+-B--------+ '-<span class="italic">strip-character</span>-'
|
|
+-LEADING--+
|
|
+-L--------+
|
|
+-TRAILING-+
|
|
'-T--------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-198" id="skipsyn-198"></a></div>
|
|
<a name="syntrim"></a>
|
|
<p id="syntrim">The TRIM function removes blanks or another specified character
|
|
from the end or beginning of a string expression.</p>
|
|
<p>The first argument, if specified, indicates whether characters are removed
|
|
from the end or beginning of the string. If the first argument is not specified,
|
|
then the characters are removed from both the end and the beginning of the
|
|
string.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">strip-character</var></dt>
|
|
<dd>The second argument, if specified, is a single-character constant that
|
|
indicates the binary, SBCS, or DBCS character that is to be removed. If <span class="italic">expression</span> is a binary string, the second argument must
|
|
be a binary string constant. If <span class="italic">expression</span> is a DBCS
|
|
graphic or DBCS-only string, the second argument must be a graphic constant
|
|
consisting of a single DBCS character. If the second argument is not specified
|
|
then:
|
|
<ul>
|
|
<li>If <span class="italic">expression</span> is a binary string, then the default
|
|
strip character is a hexadecimal zero (X'00').</li>
|
|
<li>If <span class="italic">expression</span> is a DBCS graphic string, then the
|
|
default strip character is a DBCS blank.</li>
|
|
<li>If <span class="italic">expression</span> is a UTF-16 or UCS-2 graphic string,
|
|
then the default strip character is a UTF-16 or UCS-2 blank.</li>
|
|
<li>If <span class="italic">expression</span> is a UTF-8 character string, then
|
|
the default strip character is a UTF-8 blank.</li>
|
|
<li>Otherwise, the default strip character is an SBCS blank.</li></ul>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of any built-in
|
|
numeric or string data type. A numeric argument is cast to a character string
|
|
before evaluating the function. For more information on converting numeric
|
|
to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The data type of the result depends on the data type of <span class="italic">expression</span>:</p>
|
|
<a name="wq882"></a>
|
|
<table id="wq882" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq883" width="50%" align="left" valign="bottom">Data type of <span class="italic">expression</span></th>
|
|
<th id="wq884" width="50%" align="left" valign="bottom">Data type of the Result</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq883">CHAR or VARCHAR</td>
|
|
<td align="left" valign="top" headers="wq884">VARCHAR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq883">CLOB</td>
|
|
<td align="left" valign="top" headers="wq884">CLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq883">GRAPHIC or VARGRAPHIC</td>
|
|
<td align="left" valign="top" headers="wq884">VARGRAPHIC</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq883">DBCLOB</td>
|
|
<td align="left" valign="top" headers="wq884">DBCLOB</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq883">BINARY or VARBINARY</td>
|
|
<td align="left" valign="top" headers="wq884">VARBINARY</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq883">BLOB</td>
|
|
<td align="left" valign="top" headers="wq884">BLOB</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The length attribute of the result is the same as the length attribute
|
|
of <span class="italic">expression</span>. The actual length of the result is
|
|
the length of the expression minus the number of bytes removed. If all characters
|
|
are removed, the result is an empty string.</p>
|
|
<p>If the first argument can be null, the result can be null; if the first
|
|
argument is null, the result is the null value.</p>
|
|
<p>The CCSID of the result is the same as that of the string.</p>
|
|
<p>The SRTSEQ attribute does not apply to the TRIM function.</p>
|
|
<a name="wq885"></a>
|
|
<h4 id="wq885">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable HELLO of type CHAR(9) has a value
|
|
of ' Hello '.
|
|
<pre class="xmp"> <span class="bold">SELECT TRIM(</span>:HELLO<span class="bold">)</span>, <span class="bold">TRIM( TRAILING FROM</span> :HELLO<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results
|
|
in 'Hello' and ' Hello' respectively.</li>
|
|
<li>Assume the host variable BALANCE of type CHAR(9) has a value of '000345.50'.
|
|
<pre class="xmp"> <span class="bold">SELECT TRIM( L</span> '0' <span class="bold">FROM</span> :BALANCE <span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Results
|
|
in: '345.50'</li>
|
|
<li>Assume the string to be stripped contains mixed data.
|
|
<p><span class="bold">SELECT TRIM( BOTH </span>
|
|
<img src="rv2w947.gif" alt="The argument of the TRIM" /><span class="bold"> FROM </span>
|
|
<img src="rv2w955.gif" alt="A string of mixed data" /> <span class="bold"> )</span></p>
|
|
<p> <span class="bold">FROM</span> SYSIBM.SYSDUMMY1</p>
|
|
<p>Results in:
|
|
<img src="rv2w956.gif" alt="Result of TRIM" /></p></li></ul>
|
|
<a name="scatrunc"></a>
|
|
<h3 id="scatrunc"><a href="rbafzmst02.htm#ToC_628">TRUNCATE or TRUNC</a></h3><a id="idx1137" name="idx1137"></a><a id="idx1138" name="idx1138"></a>
|
|
<a href="rbafzmstscale.htm#syntrunc"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq886"></a>
|
|
<div class="fignone" id="wq886">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn200.htm"
|
|
border="0" /></span><a href="#skipsyn-199"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-+-TRUNCATE-+--(--<span class="italic">expression-1</span>--,--<span class="italic">expression-2</span>--)-----------><
|
|
'-TRUNC----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-199" id="skipsyn-199"></a></div>
|
|
<a name="syntrunc"></a>
|
|
<p id="syntrunc">The TRUNCATE function returns <var class="pv">expression–1</var> truncated
|
|
to some number of places to the right or left of the decimal point.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression–1</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric, character-string,
|
|
or graphic-string data type. A string argument is converted to double-precision
|
|
floating point before evaluating the function. For more information on converting
|
|
strings to double-precision floating point, see <a href="rbafzmstscale.htm#dblprc">DOUBLE_PRECISION or DOUBLE</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression–2</var></dt>
|
|
<dd>The argument must be an expression that returns a value of a built-in
|
|
small integer, large integer, or big integer data type. The absolute value
|
|
of integer specifies the number of places to the right of the decimal point
|
|
for the result if <var class="pv">expression–2</var> is not negative, or to left
|
|
of the decimal point if <var class="pv">expression–2</var> is negative.
|
|
<p>If <var class="pv">expression–2</var> is not negative, <var class="pv">expression–1</var> is truncated
|
|
to the <var class="pv">expression–2</var> number of places to the right of the decimal
|
|
point.</p>
|
|
<p>If <var class="pv">expression–2</var> is negative, <var class="pv">expression–1</var> is truncated to the absolute value of (<var class="pv">expression–2</var>+1)
|
|
number of places to the left of the decimal point.</p>
|
|
<p>If the absolute value
|
|
of <var class="pv">expression–2</var> is larger than the number of digits to the
|
|
left of the decimal point, the result is 0. For example, TRUNCATE(748.58,-4)
|
|
= 0.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The data type and length attribute of the result are the same as the data
|
|
type and length attribute of the first argument.</p>
|
|
<p>If either argument can be null, the result can be null. If either argument
|
|
is null, the result is the null value.</p>
|
|
<a name="wq887"></a>
|
|
<h4 id="wq887">Examples</h4>
|
|
<ul>
|
|
<li>Calculate the average monthly salary for the highest paid employee. Truncate
|
|
the result to two places to the right of the decimal point.
|
|
<pre class="xmp"> <span class="bold">SELECT TRUNCATE(MAX(</span>SALARY/12, 2<span class="bold">)</span>
|
|
<span class="bold">FROM</span> EMPLOYEE</pre>Because the highest
|
|
paid employee in the sample employee table earns $52750.00 per year, the example
|
|
returns the value 4395.83.</li>
|
|
<li>Calculate the number 873.726 truncated to 2, 1, 0, -1, -2, and -3 decimal
|
|
places respectively.
|
|
<pre class="xmp"> <span class="bold">SELECT TRUNCATE(</span>873.726, 2<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>873.726, 1<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>873.726, 0<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>873.726, -1<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>873.726, -2<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>873.726, -3<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>Returns
|
|
the following values respectively:</p>
|
|
<pre class="xmp">0873.720 0873.700 0873.000 0870.000 0800.000 0000.000</pre></li>
|
|
<li>Calculate both positive and negative numbers.
|
|
<pre class="xmp"> <span class="bold">SELECT TRUNCATE(</span> 3.5, 0<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span> 3.1, 0<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>-3.1, 0<span class="bold">),</span>
|
|
<span class="bold">TRUNCATE(</span>-3.5, 0<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>
|
|
<p>This
|
|
example returns: </p>
|
|
<pre class="xmp">3.0 3.0 -3.0 -3.0</pre><p class="indatacontent">respectively.</p></li></ul>
|
|
<a name="scaucase"></a>
|
|
<h3 id="scaucase"><a href="rbafzmst02.htm#ToC_630">UCASE</a></h3><a id="idx1139" name="idx1139"></a><a id="idx1140" name="idx1140"></a>
|
|
<a href="rbafzmstscale.htm#synucase"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq888"></a>
|
|
<div class="fignone" id="wq888">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn201.htm"
|
|
border="0" /></span><a href="#skipsyn-200"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-UCASE--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-200" id="skipsyn-200"></a></div>
|
|
<a name="synucase"></a>
|
|
<p id="synucase">The UCASE function returns a string in which all the characters
|
|
have been converted to uppercase characters, based on the CCSID of the argument.</p>
|
|
<p>The UCASE function is identical to the UPPER function. For more information,
|
|
see <a href="rbafzmstscale.htm#scaupper">UPPER</a>.</p>
|
|
<a name="scaupper"></a>
|
|
<h3 id="scaupper"><a href="rbafzmst02.htm#ToC_631">UPPER</a></h3><a id="idx1141" name="idx1141"></a><a id="idx1142" name="idx1142"></a>
|
|
<a href="rbafzmstscale.htm#synupper"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq889"></a>
|
|
<div class="fignone" id="wq889">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn202.htm"
|
|
border="0" /></span><a href="#skipsyn-201"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-UPPER--(--<span class="italic">expression</span>--)-------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-201" id="skipsyn-201"></a></div>
|
|
<a name="synupper"></a>
|
|
<p id="synupper">The UPPER function returns a string in which all the characters
|
|
have been converted to uppercase characters, based on the CCSID of the argument.
|
|
Only SBCS, UTF-16, and UCS-2 graphic characters are converted. The characters
|
|
a-z are converted to A-Z, and characters with diacritical marks are converted
|
|
to their uppercase equivalent, if any. Refer to the <a href="../nls/rbagsucslevel1maptble.htm">UCS-2 level 1 mapping tables</a> section of the <a href="../nls/rbagsglobalmain.htm">Globalization</a> topic in the iSeries Information Center for a description of the monocasing tables that
|
|
are used for this translation.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>An expression that specifies the string to be converted. <var class="pv">expression</var> must be any built-in numeric, character, UTF–16, or UCS-2 graphic
|
|
string. A numeric argument is cast to a character string before evaluating
|
|
the function. For more information on converting numeric to a character string,
|
|
see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function has the same data type, length attribute, actual
|
|
length, and CCSID as the argument. If the argument can be null, the result
|
|
can be null; if the argument is null, the result is the null value.</p>
|
|
<p>When UPPER is specified in a query, the query cannot contain:</p>
|
|
<ul>
|
|
<li>EXCEPT or INTERSECT operations,</li>
|
|
<li>OLAP specifications,</li>
|
|
<li>recursive common table expressions,</li>
|
|
<li>ORDER OF, or</li>
|
|
<li>scalar fullselects (scalar subselects are supported).</li></ul>
|
|
<a name="wq890"></a>
|
|
<h4 id="wq890">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> UCASE is a synonym for UPPER.</p>
|
|
<a name="wq891"></a>
|
|
<h4 id="wq891">Examples</h4>
|
|
<ul>
|
|
<li>Uppercase the string 'abcdef' using the UPPER scalar function.
|
|
<pre class="xmp"><span class="bold">SELECT UPPER</span>('abcdef')
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre> Returns
|
|
the value 'ABCDEF'.</li>
|
|
<li>Uppercase the mixed character string using the UPPER scalar function.
|
|
<p><span class="bold">SELECT UPPER</span>(
|
|
<img src="rv2w957.gif" alt="Uppercase the mixed character string using the UPPER scalar function: 'ab shift-out C shift-in def'" />)</p>
|
|
<p> <span class="bold">FROM</span> SYSIBM.SYSDUMMY1</p>
|
|
<p>Returns the value:
|
|
<img src="rv2w958.gif" alt="Result of UPPER function: 'AB shift-out C shift-in DEF'" /></p></li></ul>
|
|
<a name="scavalue"></a>
|
|
<h3 id="scavalue"><a href="rbafzmst02.htm#ToC_634">VALUE</a></h3><a id="idx1143" name="idx1143"></a><a id="idx1144" name="idx1144"></a>
|
|
<a href="rbafzmstscale.htm#synvalue"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq892"></a>
|
|
<div class="fignone" id="wq892">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn203.htm"
|
|
border="0" /></span><a href="#skipsyn-202"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-VALUE--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-202" id="skipsyn-202"></a></div>
|
|
<a name="synvalue"></a>
|
|
<p id="synvalue">The VALUE function returns the value of the first non-null
|
|
expression.</p>
|
|
<p>The VALUE function is identical to the COALESCE scalar function. For more
|
|
information, see <a href="rbafzmstscale.htm#scacoales">COALESCE</a>.</p>
|
|
<a name="wq893"></a>
|
|
<h4 id="wq893">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> COALESCE should be used for
|
|
conformance to the SQL 1999 standard.</p>
|
|
<a name="scavarbinary"></a>
|
|
<h3 id="scavarbinary"><a href="rbafzmst02.htm#ToC_636">VARBINARY</a></h3><a id="idx1145" name="idx1145"></a><a id="idx1146" name="idx1146"></a>
|
|
<a href="rbafzmstscale.htm#synvarbinary"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq894"></a>
|
|
<div class="fignone" id="wq894">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn204.htm"
|
|
border="0" /></span><a href="#skipsyn-203"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARBINARY--(--<span class="italic">string-expression</span>--+------------+--)----------><
|
|
'-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-203" id="skipsyn-203"></a></div>
|
|
<a name="synvarbinary"></a>
|
|
<p id="synvarbinary">The VARBINARY function returns a VARBINARY representation
|
|
of a string of any type.</p>
|
|
<p>The result of the function is VARBINARY. If the first argument can be null,
|
|
the result can be null; if the first argument is null, the result is the null
|
|
value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>A <span class="italic">string-expression</span> whose value can be a character
|
|
string, graphic string, binary string, or row ID.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting binary string. The value must be between 1 and 32740 (32739
|
|
if nullable).
|
|
<p>If <var class="pv">integer</var> is not specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">string-expression</span> is the empty string constant,
|
|
the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument, unless the argument is a graphic string.
|
|
In this case, the length attribute of the result is twice the length attribute
|
|
of the argument.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length
|
|
attribute of the result and the actual length of the expression (or twice
|
|
the length of the expression when the input is graphic data). If the length
|
|
of the <span class="italic">string-expression</span> is greater than the length
|
|
attribute of the result, truncation is performed. A warning (SQLSTATE 01004)
|
|
is returned unless the first input argument is a character string and all
|
|
the truncated characters are blanks, or the first input argument is a graphic
|
|
string and all the truncated characters are double-byte blanks, or the first
|
|
input argument is a binary string and all the truncated bytes are hexadecimal
|
|
zeroes.</p>
|
|
</dd>
|
|
</dl>
|
|
<a name="wq895"></a>
|
|
<h4 id="wq895">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the length is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq896"></a>
|
|
<h4 id="wq896">Example</h4>
|
|
<ul>
|
|
<li>The following function returns a VARBINARY for the string 'This is a VARBINARY'.
|
|
<pre class="xmp"> <span class="bold">SELECT VARBINARY(</span>'This is a VARBINARY'<span class="bold">)</span>
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre></li></ul>
|
|
<a name="scavarchar"></a>
|
|
<h3 id="scavarchar"><a href="rbafzmst02.htm#ToC_639">VARCHAR</a></h3><a id="idx1147" name="idx1147"></a><a id="idx1148" name="idx1148"></a>
|
|
<a href="rbafzmstscale.htm#synvarchar"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq897"></a>
|
|
<div class="fignone" id="wq897">
|
|
<p><span class="bold">Datetime to Varchar</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn205.htm"
|
|
border="0" /></span><a href="#skipsyn-204"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR--(--<span class="italic">datetime-expression</span>--+--------------+--)--------><
|
|
'-,--+-ISO---+-'
|
|
+-USA---+
|
|
+-EUR---+
|
|
+-JIS---+
|
|
'-LOCAL-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-204" id="skipsyn-204"></a>
|
|
<p><span class="bold">Character to Varchar</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn206.htm"
|
|
border="0" /></span><a href="#skipsyn-205"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR (--<span class="italic">character-expression</span>------------------------------>
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-205" id="skipsyn-205"></a>
|
|
<p><span class="bold">Graphic to Varchar</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn207.htm"
|
|
border="0" /></span><a href="#skipsyn-206"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR (--<span class="italic">graphic-expression</span>-------------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-206" id="skipsyn-206"></a>
|
|
<p><span class="bold">Integer to Varchar</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn208.htm"
|
|
border="0" /></span><a href="#skipsyn-207"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR--(--<span class="italic">integer-expression</span>--)---------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-207" id="skipsyn-207"></a>
|
|
<p><span class="bold">Decimal to Varchar</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn209.htm"
|
|
border="0" /></span><a href="#skipsyn-208"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR------------------------------------------------------>
|
|
|
|
>--(--<span class="italic">decimal-expression</span>--+----------------------+--)----------><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-208" id="skipsyn-208"></a>
|
|
<p><span class="bold">Floating-point to Varchar</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn210.htm"
|
|
border="0" /></span><a href="#skipsyn-209"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR------------------------------------------------------>
|
|
|
|
>--(--<span class="italic">floating-point-expression</span>--+----------------------+--)---><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-209" id="skipsyn-209"></a></div>
|
|
<a name="synvarchar"></a>
|
|
<p id="synvarchar">The VARCHAR function returns a character-string representation
|
|
of:</p>
|
|
<ul>
|
|
<li>An integer number if the first argument is a SMALLINT, INTEGER, or BIGINT.</li>
|
|
<li>A decimal number if the first argument is a packed or zoned decimal number.</li>
|
|
<li>A double-precision floating-point number if the first argument is a DOUBLE
|
|
or REAL.</li>
|
|
<li>A character string if the first argument is any type of character string.</li>
|
|
<li>A graphic string if the first argument is any graphic string.</li>
|
|
<li>A date value if the first argument is a DATE.</li>
|
|
<li>A time value if the first argument is a TIME.</li>
|
|
<li>A timestamp value if the first argument is a TIMESTAMP.</li></ul>
|
|
<p>The result of the function is a varying-length string. If the first argument
|
|
can be null, the result can be null; if the first argument is null, the result
|
|
is the null value.</p>
|
|
<p><span class="bold">Datetime to Character</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">datetime-expression</var></dt>
|
|
<dd>An expression that is one of the following three built-in data types
|
|
<dl>
|
|
<dt class="bold">date</dt><a id="idx1149" name="idx1149"></a>
|
|
<dd>The result is the character-string representation of the date in the
|
|
format specified by the second argument. If the second argument is not specified,
|
|
the format used is the default date format. If the format is ISO, USA, EUR,
|
|
or JIS, the length attribute and actual length of the result is 10. Otherwise
|
|
the length attribute and actual length of the result is the length of the
|
|
default date format. For more information see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
<dt class="bold">time</dt>
|
|
<dd>The result is the character-string representation of the time in the
|
|
format specified by the second argument. If the second argument is not specified,
|
|
the format used is the default time format. The length attribute and actual
|
|
length of the result is 8. For more information see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
<dt class="bold"><var class="pv"></var>timestamp</dt>
|
|
<dd>The second argument is not applicable and must not be specified.
|
|
<p>The result is the character-string representation of the timestamp. The length
|
|
attribute and actual length of the result is 26.</p>
|
|
</dd>
|
|
</dl>The CCSID of the string is the default SBCS CCSID at the current server.
|
|
</dd>
|
|
<dt class="bold">ISO, EUR, USA, or JIS</dt>
|
|
<dd>Specifies the date or time format of the resulting character string.
|
|
For more information, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.
|
|
</dd>
|
|
<dt class="bold">LOCAL</dt>
|
|
<dd>Specifies that the date or time format of the resulting character string
|
|
should come from the DATFMT, DATSEP, TIMFMT, and TIMSEP attributes of the
|
|
job at the current server.
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Character to Varchar</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">character-expression</var></dt>
|
|
<dd>An expression that returns a value that is a built-in CHAR, VARCHAR,
|
|
or CLOB data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting varying length character string. The value must be between
|
|
1 and 32740 (32739 if nullable). If the first argument is mixed data, the
|
|
second argument cannot be less than 4.
|
|
<p>If the second argument is not specified
|
|
or DEFAULT is specified:</p>
|
|
<ul>
|
|
<li>If the <span class="italic">character-expression</span> is an empty string
|
|
constant, the length attribute of the result is 1.</li>
|
|
<li>Otherwise, the length attribute of the result is the same as the length
|
|
attribute of the first argument.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length
|
|
attribute of the result and the actual length of <span class="italic">character-expression</span>. If the length of the <var class="pv">character-expression</var> is greater than
|
|
the length attribute of the result, truncation is performed. A warning (SQLSTATE
|
|
01004) is returned unless the truncated characters were all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a valid SBCS CCSID, mixed data CCSID, or 65535 (bit
|
|
data). If the third argument is an SBCS CCSID, then the result is SBCS data.
|
|
If the third argument is a mixed CCSID, then the result is mixed data. If
|
|
the third argument is 65535, then the result is bit data. If the third argument
|
|
is a SBCS CCSID, then the first argument cannot be a DBCS-either or DBCS-only
|
|
string.
|
|
<p>If the third argument is not specified then: </p>
|
|
<ul>
|
|
<li>If the first argument is SBCS data, then the result is SBCS data. The
|
|
CCSID of the result is the same as the CCSID of the first argument.</li>
|
|
<li>If the first argument is mixed data (DBCS-open, DBCS-only, or DBCS-either),
|
|
then the result is mixed data. The CCSID of the result is the same as the
|
|
CCSID of the first argument.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Graphic to Varchar</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">graphic-expression</var></dt>
|
|
<dd>An expression that returns a value that is a GRAPHIC, VARGRAPHIC, and
|
|
DBCLOB data type. It must not be DBCS-graphic data.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
for the resulting varying length character string. The value must be between
|
|
1 and 32740 (32739 if nullable). If the first argument contains DBCS data,
|
|
the second argument cannot be less than 4.
|
|
<p>If the second argument is not
|
|
specified or DEFAULT is specified, the length attribute of the result is determined
|
|
as follows (where <span class="italic">n</span> is the length attribute of the
|
|
first argument): </p>
|
|
<ul>
|
|
<li>If the <span class="italic">graphic-expression</span> is the empty graphic
|
|
string constant, the length attribute of the result is 1.</li>
|
|
<li>If the result is SBCS data, the result length is <span class="italic">n</span>.</li>
|
|
<li>If the result is mixed data, the result length is (2.5*(<span class="italic">n</span>-1)) + 4.</li></ul>
|
|
<p>The actual length of the result is the minimum of the length attribute
|
|
of the result and the actual length of <span class="italic">graphic-expression</span>. If the length of the <var class="pv">character-expression</var> is greater than
|
|
the length attribute of the result, truncation is performed. A warning (SQLSTATE
|
|
01004) is returned unless the truncated characters were all blanks.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a valid SBCS CCSID or mixed data CCSID. If the third
|
|
argument is an SBCS CCSID, then the result is SBCS data. If the third argument
|
|
is a mixed CCSID, then the result is mixed data. The third argument cannot
|
|
be 65535.
|
|
<p>If the third argument is not specified, the CCSID of the result
|
|
is the default CCSID at the current server. If the default CCSID is mixed
|
|
data, then the result is mixed data. If the default CCSID is SBCS data, then
|
|
the result is SBCS data.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Integer to Varchar</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">integer-expression</var></dt>
|
|
<dd>An expression that returns a value that is an integer data type (either
|
|
SMALLINT, INTEGER, or BIGINT).
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length character string of the argument in
|
|
the form of an SQL integer constant. The result consists of n characters that
|
|
are the significant digits that represent the value of the argument with a
|
|
preceding minus sign if the argument is negative. It is left justified.</p>
|
|
<ul>
|
|
<li>If the argument is a small integer, the length attribute of the result
|
|
is 6.</li>
|
|
<li>If the argument is a large integer, the length attribute of the result
|
|
is 11.</li>
|
|
<li>If the argument is a big integer, the length attribute of the result is
|
|
20.</li></ul>
|
|
<p>The actual length of the result is the smallest number of characters that
|
|
can be used to represent the value of the argument. Leading zeroes are not
|
|
included. If the argument is negative, the first character of the result is
|
|
a minus sign. Otherwise, the first character is a digit.</p>
|
|
<p>The CCSID of the result is the default SBCS CCSID at the current server.</p>
|
|
<p><span class="bold">Decimal to Varchar</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">decimal-expression</var></dt>
|
|
<dd>An expression that returns a value that is a packed or zoned decimal
|
|
data type (either DECIMAL or NUMERIC). If a different precision and scale
|
|
is desired, the DECIMAL scalar function can be used to make the change.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length character string representation of
|
|
the argument. The result includes a decimal character and up to <var class="pv">p</var>
|
|
digits, where <var class="pv">p</var> is the precision of the <var class="pv">decimal-expression</var> with
|
|
a preceding minus sign if the argument is negative. Leading zeros are not
|
|
returned. Trailing zeros are returned.</p>
|
|
<p>The length attribute of the result is 2+<var class="pv">p</var> where <var class="pv">p</var> is
|
|
the precision of the <var class="pv">decimal-expression</var>. The actual length of the
|
|
result is the smallest number of characters that can be used to represent
|
|
the result, except that trailing characters are included. Leading zeros are
|
|
not included. If the argument is negative, the result begins with a minus
|
|
sign. Otherwise, the result begins with a digit.</p>
|
|
<p> The CCSID of the result is the default SBCS CCSID at the current server.</p>
|
|
<p><span class="bold">Floating-point to Varchar</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">floating-point expression</var></dt>
|
|
<dd>An expression that returns a value that is a floating-point data type
|
|
(DOUBLE or REAL).
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length character string representation of
|
|
the argument in the form of a floating-point constant.</p>
|
|
<p>The length attribute of the result is 24. The actual length of the result
|
|
is the smallest number of characters that can represent the value of the argument
|
|
such that the mantissa consists of a single digit other than zero followed
|
|
by the <var class="pv">decimal-character</var> and a sequence of digits. If the argument
|
|
is negative, the first character of the result is a minus sign; otherwise,
|
|
the first character is a digit. If the argument is zero, the result is 0E0.</p>
|
|
<p>The CCSID of the result is the default SBCS CCSID at the current server.</p>
|
|
<a name="wq898"></a>
|
|
<h4 id="wq898">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> If the length attribute is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq899"></a>
|
|
<h4 id="wq899">Example</h4>
|
|
<ul>
|
|
<li>Make EMPNO varying-length with a length of 10.
|
|
<pre class="xmp"> <span class="bold">SELECT VARCHAR</span>(EMPNO,10)
|
|
<span class="bold">INTO</span> :VARHV
|
|
<span class="bold">FROM</span> EMPLOYEE</pre></li></ul>
|
|
<a name="scavarcharformat"></a>
|
|
<h3 id="scavarcharformat"><a href="rbafzmst02.htm#ToC_642">VARCHAR_FORMAT</a></h3><a id="idx1150" name="idx1150"></a><a id="idx1151" name="idx1151"></a><a id="idx1152" name="idx1152"></a><a id="idx1153" name="idx1153"></a>
|
|
<a href="rbafzmstscale.htm#synvarcharformat"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq900"></a>
|
|
<div class="fignone" id="wq900">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn211.htm"
|
|
border="0" /></span><a href="#skipsyn-210"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARCHAR_FORMAT--(--<span class="italic">expression</span>--,--<span class="italic">format-string</span>--)----------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-210" id="skipsyn-210"></a></div>
|
|
<a name="synvarcharformat"></a>
|
|
<p id="synvarcharformat">The VARCHAR_FORMAT function returns a character representation
|
|
of a timestamp in the format indicated by <var class="pv">format-string</var>.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a timestamp, a character string, or a graphic
|
|
string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string, it must
|
|
not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a timestamp. For the valid formats of string representations of timestamps,
|
|
see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
<p>Leading and trailing blanks
|
|
are removed from <var class="pv">expression</var>, and the resulting substring is interpreted
|
|
as a timestamp using the format specified by <var class="pv">format-string</var>.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">format-string</var></dt>
|
|
<dd>An expression that returns a built-in character string data type or
|
|
graphic string data type. <var class="pv">format-string</var> contains a template of how <var class="pv">expression</var> is to be formatted. Leading and trailing blanks are trimmed
|
|
from <var class="pv">format-string</var>. The resulting value is then folded to uppercase,
|
|
so the characters in the value may be in any case. The only valid format that
|
|
can be specified for the function is:
|
|
<p> 'YYYY-MM-DD HH24:MI:SS'</p>
|
|
<p>where:</p>
|
|
<dl>
|
|
<dt class="bold">YYYY</dt>
|
|
<dd>4-digit year
|
|
</dd>
|
|
<dt class="bold">MM</dt>
|
|
<dd>Month (01-12, January = 01)
|
|
</dd>
|
|
<dt class="bold">DD</dt>
|
|
<dd>Day of month (01-31)
|
|
</dd>
|
|
<dt class="bold">HH24</dt>
|
|
<dd>Hour of day (00–24, when the value is 24, the minutes and seconds
|
|
must be 0).
|
|
</dd>
|
|
<dt class="bold">MM</dt>
|
|
<dd>Minutes (00–59)
|
|
</dd>
|
|
<dt class="bold">SS</dt>
|
|
<dd>Seconds (00–59)
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
<p>The result is the varying-length character string that contains the argument
|
|
in the format specified by <var class="pv">format-string</var>. <var class="pv">format-string</var> also
|
|
determines the length attribute and actual length of the result. If either
|
|
argument can be null, the result can be null; if either argument is null,
|
|
the result is the null value.</p>
|
|
<p>The CCSID of the result is the default SBCS CCSID of the current server.</p>
|
|
<a name="wq901"></a>
|
|
<h4 id="wq901">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> TO_CHAR is a synonym for VARCHAR_FORMAT.</p>
|
|
<a name="wq902"></a>
|
|
<h4 id="wq902">Example</h4>
|
|
<ul>
|
|
<li>Set the character variable TVAR to the timestamp value of RECEIVED from
|
|
CORPDATA.IN_TRAY, using the character string format supported by the function
|
|
to specify the format of the value for TVAR.
|
|
<pre class="xmp"><span class="bold">SELECT VARCHAR_FORMAT(</span>RECEIVED,'YYYY-MM-DD HH24:MI:SS'<span class="bold">)
|
|
INTO</span> :TVAR
|
|
<span class="bold">FROM</span> CORPDATA.IN_TRAY </pre></li></ul>
|
|
<a name="scavargraph"></a>
|
|
<h3 id="scavargraph"><a href="rbafzmst02.htm#ToC_645">VARGRAPHIC</a></h3><a id="idx1154" name="idx1154"></a><a id="idx1155" name="idx1155"></a>
|
|
<a href="rbafzmstscale.htm#synvargraphic"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq903"></a>
|
|
<div class="fignone" id="wq903">
|
|
<p><span class="bold">Character to Vargraphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn212.htm"
|
|
border="0" /></span><a href="#skipsyn-211"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARGRAPHIC--(--<span class="italic">character-expression</span>-------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-211" id="skipsyn-211"></a>
|
|
<p><span class="bold">Graphic to Vargraphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn213.htm"
|
|
border="0" /></span><a href="#skipsyn-212"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARGRAPHIC--(--<span class="italic">graphic-expression</span>---------------------------->
|
|
|
|
>--+--------------------------------+--)-----------------------><
|
|
'-,--+-<span class="italic">length</span>--+--+------------+-'
|
|
'-DEFAULT-' '-,--<span class="italic">integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-212" id="skipsyn-212"></a>
|
|
<p><span class="bold">Integer to Vargraphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn214.htm"
|
|
border="0" /></span><a href="#skipsyn-213"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARGRAPHIC--(--<span class="italic">integer-expression</span>--)------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-213" id="skipsyn-213"></a>
|
|
<p><span class="bold">Decimal to Vargraphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn215.htm"
|
|
border="0" /></span><a href="#skipsyn-214"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARGRAPHIC--------------------------------------------------->
|
|
|
|
>--(--<span class="italic">decimal-expression</span>--+----------------------+--)----------><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-214" id="skipsyn-214"></a>
|
|
<p><span class="bold">Floating-point to Vargraphic</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn216.htm"
|
|
border="0" /></span><a href="#skipsyn-215"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-VARGRAPHIC--------------------------------------------------->
|
|
|
|
>--(--<span class="italic">floating-point-expression</span>--+----------------------+--)---><
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-215" id="skipsyn-215"></a></div>
|
|
<a name="synvargraphic"></a>
|
|
<p id="synvargraphic">The VARGRAPHIC function returns a graphic-string representation
|
|
of </p>
|
|
<ul>
|
|
<li>An integer number if the first argument is a SMALLINT, INTEGER, or BIGINT.</li>
|
|
<li>A decimal number if the first argument is a packed or zoned decimal number.</li>
|
|
<li>A double-precision floating-point number if the first argument is a DOUBLE
|
|
or REAL.</li>
|
|
<li>A character string if the first argument is any type of character string.</li>
|
|
<li>A graphic string if the first argument is a UTF-16 or UCS-2 graphic string.</li></ul>
|
|
<p>The result of the function is a varying-length graphic string (VARGRAPHIC).</p>
|
|
<p>If the expression can be null, the result can be null. If the expression
|
|
is null, the result is the null value. If the expression is an empty string
|
|
or the EBCDIC string <tt class="xph">X'0E0F'</tt>, the result is an empty string.</p>
|
|
<p><span class="bold">Character to Graphic</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">character-expression</var></dt>
|
|
<dd>Specifies a character string expression. It cannot be a CHAR or VARCHAR
|
|
bit data.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
of the result and must be an integer constant between 1 and 16370 if the first
|
|
argument is not nullable or between 1 and 16369 if the first argument is nullable.
|
|
<p>If the second argument is not specified, or if DEFAULT is specified, the length
|
|
attribute of the result is the same as the length attribute of the first argument,
|
|
except if the expression is an empty string or the EBCDIC string X'0E0F',
|
|
the length attribute of the result is 1.</p>
|
|
<p>The actual length of the result
|
|
depends on the number of characters in the argument. Each character of the
|
|
argument determines a character of the result. If the length attribute of
|
|
the resulting varying-length string is less than the actual length of the
|
|
first argument, truncation is performed and no warning is returned.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a DBCS, UTF-16, or UCS-2 CCSID. The CCSID cannot be
|
|
65535. If the CCSID represents UTF-16 or UCS-2 graphic data, each character
|
|
of the argument determines a character of the result. The nth character of
|
|
the result is the UTF-16 or UCS-2 equivalent of the nth character of the argument.
|
|
<p>If <var class="pv">integer</var> is not specified then the CCSID of the result is determined
|
|
by a mixed CCSID. Let M denote that mixed CCSID.</p>
|
|
<p>In the following rules,
|
|
S denotes one of the following: </p>
|
|
<ul>
|
|
<li>If the string expression is a host variable containing data in a foreign
|
|
encoding scheme, S is the result of the expression after converting the data
|
|
to a CCSID in a native encoding scheme. (See <a href="rbafzmstccseta.htm#ccseta">Character conversion</a> for more
|
|
information.)</li>
|
|
<li>If the string expression is data in a native encoding scheme, S is that
|
|
string expression.</li></ul>
|
|
<p>M is determined as follows: </p>
|
|
<ul>
|
|
<li>If the CCSID of S is 1208 (UTF-8), M is 1200 (UTF–16).</li>
|
|
<li>If the CCSID of S is a mixed CCSID, M is that CCSID.</li>
|
|
<li>If the CCSID of S is an SBCS CCSID:
|
|
<ul>
|
|
<li>If the CCSID of S has an associated mixed CCSID, M is that CCSID.</li>
|
|
<li>Otherwise the operation is not allowed.</li></ul></li></ul>
|
|
<p>The following table summarizes the result CCSID based on M.</p>
|
|
<a name="wq904"></a>
|
|
<table id="wq904" width="100%" summary="" border="1" frame="border" rules="all">
|
|
<thead valign="bottom">
|
|
<tr>
|
|
<th id="wq905" width="14%" align="left" valign="bottom">M</th>
|
|
<th id="wq906" width="19%" align="left" valign="bottom">Result CCSID</th>
|
|
<th id="wq907" width="28%" align="left" valign="bottom">Description</th>
|
|
<th id="wq908" width="37%" align="left" valign="bottom">DBCS Substitution Character</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">930</td>
|
|
<td align="left" valign="top" headers="wq906">300</td>
|
|
<td align="left" valign="top" headers="wq907">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">933</td>
|
|
<td align="left" valign="top" headers="wq906">834</td>
|
|
<td align="left" valign="top" headers="wq907">Korean EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">935</td>
|
|
<td align="left" valign="top" headers="wq906">837</td>
|
|
<td align="left" valign="top" headers="wq907">S-Chinese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">937</td>
|
|
<td align="left" valign="top" headers="wq906">835</td>
|
|
<td align="left" valign="top" headers="wq907">T-Chinese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">939</td>
|
|
<td align="left" valign="top" headers="wq906">300</td>
|
|
<td align="left" valign="top" headers="wq907">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">5026</td>
|
|
<td align="left" valign="top" headers="wq906">4396</td>
|
|
<td align="left" valign="top" headers="wq907">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" valign="top" headers="wq905">5035</td>
|
|
<td align="left" valign="top" headers="wq906">4396</td>
|
|
<td align="left" valign="top" headers="wq907">Japanese EBCDIC</td>
|
|
<td align="left" valign="top" headers="wq908">X'FEFE'</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The equivalence of SBCS and DBCS characters depends on M. Regardless
|
|
of the CCSID, every double-byte code point in the argument is considered a
|
|
DBCS character, and every single-byte code point in the argument is considered
|
|
an SBCS character with the exception of the EBCDIC mixed data shift codes <tt class="xph">X'0E'</tt> and <tt class="xph">X'0F'</tt>. </p>
|
|
<ul>
|
|
<li>If the nth character of the argument is a DBCS character, the nth character
|
|
of the result is that DBCS character.</li>
|
|
<li>If the nth character of the argument is an SBCS character that has an
|
|
equivalent DBCS character, the nth character of the result is that equivalent
|
|
DBCS character.</li>
|
|
<li>If the nth character of the argument is an SBCS character that does not
|
|
have an equivalent DBCS character, the nth character of the result is the
|
|
DBCS substitution character.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Graphic to Vargraphic</span></p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">graphic-expression</var></dt>
|
|
<dd>An expression that returns a value that is a graphic string.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">length</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the length attribute
|
|
of the result and must be an integer constant between 1 and 16370 if the first
|
|
argument is not nullable or between 1 and 16369 if the first argument is nullable.
|
|
<p>If the second argument is not specified, or if DEFAULT is specified, the length
|
|
attribute of the result is the same as the length attribute of the first argument,
|
|
except if the expression is an empty string, the length attribute of the result
|
|
is 1.</p>
|
|
<p>The actual length of the result depends on the number of characters
|
|
in <var class="pv">graphic-expression</var>. If the length of <var class="pv">graphic-expression</var> is
|
|
greater than the length specified, the result is truncated and no warning
|
|
is returned.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">integer</var></dt>
|
|
<dd><span>An integer constant that</span> specifies the CCSID of
|
|
the result. It must be a DBCS, UTF-16, or UCS-2 CCSID. The CCSID cannot be
|
|
65535.
|
|
<p>If <var class="pv">integer</var> is not specified then the CCSID of the result
|
|
is the CCSID of the first argument.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><span class="bold">Integer to Vargraphic</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">integer-expression</var></dt>
|
|
<dd>An expression that returns a value that is an integer data type (either
|
|
SMALLINT, INTEGER, or BIGINT).
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length graphic string of the argument in the
|
|
form of an SQL integer constant. The result consists of n characters that
|
|
are the significant digits that represent the value of the argument with a
|
|
preceding minus sign if the argument is negative. It is left justified.</p>
|
|
<ul>
|
|
<li>If the argument is a small integer, the length attribute of the result
|
|
is 6.</li>
|
|
<li>If the argument is a large integer, the length attribute of the result
|
|
is 11.</li>
|
|
<li>If the argument is a big integer, the length attribute of the result is
|
|
20.</li></ul>
|
|
<p>The actual length of the result is the smallest number of characters that
|
|
can be used to represent the value of the argument. Leading zeroes are not
|
|
included. If the argument is negative, the first character of the result is
|
|
a minus sign. Otherwise, the first character is a digit.</p>
|
|
<p>The CCSID of the result is 1200 (UTF-16).</p>
|
|
<p><span class="bold">Decimal to Vargraphic</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">decimal-expression</var></dt>
|
|
<dd>An expression that returns a value that is a packed or zoned decimal
|
|
data type (either DECIMAL or NUMERIC). If a different precision and scale
|
|
is desired, the DECIMAL scalar function can be used to make the change.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length graphic string representation of the
|
|
argument. The result includes a decimal character and up to <var class="pv">p</var> digits,
|
|
where <var class="pv">p</var> is the precision of the <var class="pv">decimal-expression</var> with
|
|
a preceding minus sign if the argument is negative. Leading zeros are not
|
|
returned. Trailing zeros are returned.</p>
|
|
<p>The length attribute of the result is 2+<var class="pv">p</var> where <var class="pv">p</var> is
|
|
the precision of the <var class="pv">decimal-expression</var>. The actual length of the
|
|
result is the smallest number of characters that can be used to represent
|
|
the result, except that trailing characters are included. Leading zeros are
|
|
not included. If the argument is negative, the result begins with a minus
|
|
sign. Otherwise, the result begins with a digit.</p>
|
|
<p> The CCSID of the result is 1200 (UTF-16).</p>
|
|
<p><span class="bold">Floating-point to Vargraphic</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">floating-point expression</var></dt>
|
|
<dd>An expression that returns a value that is a floating-point data type
|
|
(DOUBLE or REAL).
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that is used to delimit
|
|
the decimal digits in the result character string. The character must be a
|
|
period or comma. If the second argument is not specified, the decimal point
|
|
is the default decimal point. For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is a varying-length graphic string representation of the
|
|
argument in the form of a floating-point constant.</p>
|
|
<p>The length attribute of the result is 24. The actual length of the result
|
|
is the smallest number of characters that can represent the value of the argument
|
|
such that the mantissa consists of a single digit other than zero followed
|
|
by the <var class="pv">decimal-character</var> and a sequence of digits. If the argument
|
|
is negative, the first character of the result is a minus sign; otherwise,
|
|
the first character is a digit. If the argument is zero, the result is 0E0.</p>
|
|
<p>The CCSID of the result is 1200 (UTF-16).</p>
|
|
<a name="wq909"></a>
|
|
<h4 id="wq909">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> If the first argument is <var class="pv">graphic-expression</var> and the length attribute is specified, the CAST specification
|
|
should be used for maximal portability. For more information, see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq910"></a>
|
|
<h4 id="wq910">Example</h4>
|
|
<ul>
|
|
<li>Using the EMPLOYEE table, set the host variable VAR_DESC (VARGRAPHIC(24))
|
|
to the VARGRAPHIC equivalent of the first name (FIRSTNME) for employee number
|
|
(EMPNO) '000050'.
|
|
<pre class="xmp"> <span class="bold">SELECT VARGRAPHIC</span>(FIRSTNME)
|
|
<span class="bold">INTO</span> :VAR_DESC
|
|
<span class="bold">FROM</span> EMPLOYEE
|
|
<span class="bold">WHERE</span> EMPNO = '000050'</pre></li></ul>
|
|
<a name="scaweek"></a>
|
|
<h3 id="scaweek"><a href="rbafzmst02.htm#ToC_648">WEEK</a></h3><a id="idx1156" name="idx1156"></a><a id="idx1157" name="idx1157"></a>
|
|
<a href="rbafzmstscale.htm#synweek"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq911"></a>
|
|
<div class="fignone" id="wq911">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn217.htm"
|
|
border="0" /></span><a href="#skipsyn-216"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-WEEK--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-216" id="skipsyn-216"></a></div>
|
|
<a name="synweek"></a>
|
|
<p id="synweek">The WEEK function returns an integer between 1 and 54 that
|
|
represents the week of the year. The week starts with Sunday, and January
|
|
1 is always in the first week.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq912"></a>
|
|
<h4 id="wq912">Example</h4>
|
|
<ul>
|
|
<li>Using the PROJECT table, set the host variable WEEK (INTEGER) to the week
|
|
that project ('PL2100') ended.
|
|
<pre class="xmp"> <span class="bold">SELECT WEEK(</span>PRENDATE<span class="bold">)
|
|
INTO</span> :WEEK
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNO = 'PL2100'</pre>Results
|
|
in WEEK being set to 38.</li>
|
|
<li>Assume that table X has a DATE column called DATE_1 with various dates
|
|
from the list below.
|
|
<pre class="xmp"> <span class="bold">SELECT </span>DATE_1, <span class="bold">WEEK(</span>DATE_1<span class="bold">)</span>
|
|
<span class="bold">FROM</span> X </pre>Results in the following
|
|
list shows what is returned by the WEEK function for various dates.
|
|
<pre class="xmp"> 1997-12-28 53
|
|
1997-12-31 53
|
|
1998-01-01 1
|
|
1999-01-01 1
|
|
1999-01-04 2
|
|
1999-12-31 53
|
|
2000-01-01 1
|
|
2000-01-03 2
|
|
</pre></li></ul>
|
|
<a name="scaisoweek"></a>
|
|
<h3 id="scaisoweek"><a href="rbafzmst02.htm#ToC_650">WEEK_ISO</a></h3><a id="idx1158" name="idx1158"></a><a id="idx1159" name="idx1159"></a>
|
|
<a href="rbafzmstscale.htm#synweek_iso"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq913"></a>
|
|
<div class="fignone" id="wq913">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn218.htm"
|
|
border="0" /></span><a href="#skipsyn-217"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-WEEK_ISO--(--<span class="italic">expression</span>--)----------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-217" id="skipsyn-217"></a></div>
|
|
<a name="synweek_iso"></a>
|
|
<p id="synweek_iso">The WEEK_ISO function returns an integer between 1 and
|
|
53 that represents the week of the year. The week starts with Monday. Week
|
|
1 is the first week of the year to contain a Thursday, which is equivalent
|
|
to the first week containing January 4. Thus, it is possible to have up to
|
|
3 days at the beginning of the year appear as the last week of the previous
|
|
year or to have up to 3 days at the end of a year appear as the first week
|
|
of the next year.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, or
|
|
a graphic string.
|
|
<p>If <var class="pv">expression</var> is a character or graphic string,
|
|
it must not be a CLOB or DBCLOB and its value must be a valid string representation
|
|
of a date or timestamp. For the valid formats of string representations of
|
|
dates and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<a name="wq914"></a>
|
|
<h4 id="wq914">Examples</h4>
|
|
<ul>
|
|
<li>Using the PROJECT table, set the host variable WEEK (INTEGER) to the week
|
|
that project ('AD2100') ended.
|
|
<pre class="xmp"> <span class="bold">SELECT WEEK_ISO(</span>PRENDATE<span class="bold">)
|
|
INTO</span> :WEEK
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNO = 'AD3100'</pre>Results
|
|
in WEEK being set to 5.</li>
|
|
<li>Assume that table X has a DATE column called DATE_1 with various dates
|
|
from the list below.
|
|
<pre class="xmp"> <span class="bold">SELECT </span>DATE_1, <span class="bold">WEEK_ISO(</span>DATE_1<span class="bold">)</span>
|
|
<span class="bold">FROM</span> X </pre>Results in the following:
|
|
<pre class="xmp"> 1997-12-28 52
|
|
1997-12-31 1
|
|
1998-01-01 1
|
|
1999-01-01 53
|
|
1999-01-04 1
|
|
1999-12-31 52
|
|
2000-01-01 52
|
|
2000-01-03 1
|
|
</pre></li></ul>
|
|
<a name="scaxor"></a>
|
|
<h3 id="scaxor"><a href="rbafzmst02.htm#ToC_652">XOR</a></h3><a id="idx1160" name="idx1160"></a><a id="idx1161" name="idx1161"></a>
|
|
<a href="rbafzmstscale.htm#synxor"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq915"></a>
|
|
<div class="fignone" id="wq915">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn219.htm"
|
|
border="0" /></span><a href="#skipsyn-218"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .---------------.
|
|
V |
|
|
>>-XOR--(--<span class="italic">expression</span>----,--<span class="italic">expression</span>-+--)--------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-218" id="skipsyn-218"></a></div>
|
|
<a name="synxor"></a>
|
|
<p id="synxor">The XOR function returns a string that is the logical XOR of
|
|
the argument strings. This function takes the first argument string, does
|
|
an XOR operation with the next string, and then continues to do XOR operations
|
|
for each successive argument using the previous result. If an argument is
|
|
encountered that is shorter than the previous result, it is padded with blanks.</p>
|
|
<p>The arguments must be compatible.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The arguments must be expressions that return a value of any built-in
|
|
numeric or string data type, but cannot be LOBs. The arguments cannot be mixed
|
|
data character strings, UTF-8 character strings, or graphic strings. A numeric
|
|
argument is cast to a character string before evaluating the function. For
|
|
more information on converting numeric to a character string, see <a href="rbafzmstscale.htm#scavarchar">VARCHAR</a>.
|
|
</dd>
|
|
</dl>
|
|
<p>The arguments are converted, if necessary, to the attributes of the result.
|
|
The attributes of the result are determined as follows: </p>
|
|
<ul>
|
|
<li>If all the arguments are fixed-length strings, the result is a fixed-length
|
|
string of length <span class="italic">n</span>, where <span class="italic">n</span> is
|
|
the length of the longest argument.</li>
|
|
<li>If any argument is a varying-length string, the result is a varying-length
|
|
string with length attribute <span class="italic">n</span>, where <span class="italic">n</span> is the length attribute of the argument with greatest length attribute.
|
|
The actual length of the result is <span class="italic">m</span>, where <span class="italic">m</span> is the actual length of the longest argument.</li></ul>
|
|
<p>If an argument can be null, the result can be null; if an argument is null,
|
|
the result is the null value.</p>
|
|
<p>The CCSID of the result is 65535.</p>
|
|
<a name="wq916"></a>
|
|
<h4 id="wq916">Example</h4>
|
|
<ul>
|
|
<li>Assume the host variable L1 is a CHARACTER(2) host variable
|
|
with a value of X'E1E1', host variable L2 is a CHARACTER(3) host variable
|
|
with a value of X'F0F000', and host variable L3 is a CHARACTER(4) host variable
|
|
with a value of X'0000000F'.
|
|
<pre class="xmp"> <span class="bold">SELECT XOR</span>(:L1,:L2,:L3)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value X'1111404F'.</li></ul>
|
|
<a name="scayear"></a>
|
|
<h3 id="scayear"><a href="rbafzmst02.htm#ToC_654">YEAR</a></h3><a id="idx1162" name="idx1162"></a><a id="idx1163" name="idx1163"></a>
|
|
<a href="rbafzmstscale.htm#synyear"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq917"></a>
|
|
<div class="fignone" id="wq917">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn220.htm"
|
|
border="0" /></span><a href="#skipsyn-219"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-YEAR--(--<span class="italic">expression</span>--)--------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-219" id="skipsyn-219"></a></div>
|
|
<a name="synyear"></a>
|
|
<p id="synyear">The YEAR function returns the year part of a value.</p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">expression</var></dt>
|
|
<dd>The argument must be an expression that returns a value of one of the
|
|
following built-in data types: a date, a timestamp, a character string, a
|
|
graphic string, or a numeric data type.
|
|
<ul>
|
|
<li>If <var class="pv">expression</var> is a character or graphic string, it must not be
|
|
a CLOB or DBCLOB and its value must be a valid string representation of a
|
|
date or timestamp. For the valid formats of string representations of dates
|
|
and timestamps, see <a href="rbafzmstch2data.htm#dtstrng">String representations of datetime values</a>.</li>
|
|
<li>If <var class="pv">expression</var> is a number, it must be a date duration or timestamp
|
|
duration. For the valid formats of datetime durations, see <a href="rbafzmstch2expr.htm#dtdur">Datetime operands and durations</a>.</li></ul>
|
|
</dd>
|
|
</dl>
|
|
<p>The result of the function is a large integer. If the argument can be null,
|
|
the result can be null; if the argument is null, the result is the null value.</p>
|
|
<p>The other rules depend on the data type of the argument: </p>
|
|
<ul>
|
|
<li>If the argument is a date or a timestamp or a valid character-string representation
|
|
of a date or timestamp:
|
|
<p>The result is the year part of the value, which
|
|
is an integer between 1 and 9999.</p></li>
|
|
<li>If the argument is a date duration or timestamp duration:
|
|
<p>The result
|
|
is the year part of the value, which is an integer between -9999 and
|
|
9999. A nonzero result has the same sign as the argument.</p></li></ul>
|
|
<a name="wq918"></a>
|
|
<h4 id="wq918">Examples</h4>
|
|
<ul>
|
|
<li>Select all the projects in the PROJECT table that are scheduled to start
|
|
(PRSTDATE) and end (PRENDATE) in the same calendar year.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> PROJECT
|
|
<span class="bold">WHERE YEAR(</span>PRSTDATE<span class="bold">)</span> = <span class="bold">YEAR(</span>PRENDATE<span class="bold">)</span></pre></li>
|
|
<li>Select all the projects in the PROJECT table that are scheduled to take
|
|
less than one year to complete.
|
|
<pre class="xmp"> <span class="bold">SELECT *
|
|
FROM</span> PROJECT
|
|
<span class="bold">WHERE YEAR(</span>PRENDATE - PRSTDATE<span class="bold">)</span> < 1</pre></li></ul>
|
|
<a name="scazoned"></a>
|
|
<h3 id="scazoned"><a href="rbafzmst02.htm#ToC_656">ZONED</a></h3><a id="idx1164" name="idx1164"></a><a id="idx1165" name="idx1165"></a>
|
|
<a href="rbafzmstscale.htm#synzoned"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq919"></a>
|
|
<div class="fignone" id="wq919">
|
|
<p><span class="bold">Numeric to Zoned Decimal</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn221.htm"
|
|
border="0" /></span><a href="#skipsyn-220"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ZONED-------------------------------------------------------->
|
|
|
|
>--(--<span class="italic">numeric-expression</span>--+--------------------------------------------+--)-><
|
|
'-,--<span class="italic">precision-integer</span>--+------------------+-'
|
|
'-,--<span class="italic">scale-integer</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-220" id="skipsyn-220"></a>
|
|
<p><span class="bold">String to Zoned Decimal</span></p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn222.htm"
|
|
border="0" /></span><a href="#skipsyn-221"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-ZONED-------------------------------------------------------->
|
|
|
|
>--(--<span class="italic">string-expression</span>--+------------------------------------------------------+--)-><
|
|
'-,--<span class="italic">precision</span>--+------------------------------------+-'
|
|
'-,--<span class="italic">scale</span>--+----------------------+-'
|
|
'-,--<span class="italic">decimal-character</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-221" id="skipsyn-221"></a></div>
|
|
<a name="synzoned"></a>
|
|
<p id="synzoned">The ZONED function returns a zoned decimal representation
|
|
of: </p>
|
|
<ul>
|
|
<li>A number</li>
|
|
<li>A character or graphic string representation of a decimal number</li>
|
|
<li>A character or graphic string representation of an integer</li>
|
|
<li>A character or graphic string representation of a floating-point number</li></ul>
|
|
<p>The result of the function is a zoned decimal number with precision of <span class="italic">p</span> and scale of <span class="italic">s</span>, where <span class="italic">p</span> and <span class="italic">s</span> are the second and third arguments. If
|
|
the first argument can be null, the result can be null; if the first argument
|
|
is null, the result is the null value.</p>
|
|
<p><span class="bold">Numeric to Zoned Decimal</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">numeric-expression</var></dt>
|
|
<dd>An expression that returns a value of any built-in numeric data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">precision</var></dt>
|
|
<dd>An integer constant with a value greater than or equal to 1 and less
|
|
than or equal to 63.
|
|
<p>The default for <var class="pv">precision</var> depends on the data
|
|
type of the <var class="pv">numeric-expression</var>: </p>
|
|
<ul>
|
|
<li>15 for floating point, decimal, numeric, or nonzero scale binary</li>
|
|
<li>19 for big integer</li>
|
|
<li>11 for large integer</li>
|
|
<li>5 for small integer</li></ul>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">scale</var></dt>
|
|
<dd>An integer constant that is greater than or equal to 0 and less than
|
|
or equal to <var class="pv">precision</var>. If not specified, the default is 0.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is the same number that would occur if the first argument
|
|
were assigned to a decimal column or variable with a precision of <span class="italic">p</span> and a scale of <span class="italic">s</span>. An error is returned if the
|
|
number of significant decimal digits required to represent the whole part
|
|
of the number is greater than <span class="italic">p</span>-<span class="italic">s</span>.</p>
|
|
<p><span class="bold">String to Zoned Decimal</span> </p>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">string-expression</var></dt>
|
|
<dd>An expression that returns a value that is a character-string or graphic-string
|
|
representation of a number.
|
|
<p>If the argument is a <var class="pv">string-expression</var>,
|
|
the result is the same number that would result from CAST( <var class="pv">string-expression</var> AS NUMERIC(<var class="pv">precision</var>, <var class="pv">scale</var>)). Leading and trailing
|
|
blanks are eliminated and the resulting string must conform to the rules for
|
|
forming a floating-point, integer, or decimal constant. If the whole part
|
|
of the argument is not within the range of decimal with the specified <var class="pv">precision</var>, an error is returned. Any fractional part of the argument
|
|
is truncated.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">precision</var></dt>
|
|
<dd>An integer constant that is greater than or equal to 1 and less than
|
|
or equal to 63. If not specified, the default is 15.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">scale</var></dt>
|
|
<dd>An integer constant that is greater than or equal to 0 and less than
|
|
or equal to <var class="pv">precision</var>. If not specified, the default is 0.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">decimal-character</var></dt>
|
|
<dd>Specifies the single-byte character constant that was used to delimit
|
|
the decimal digits in <var class="pv">string-expression</var> from the whole part of the
|
|
number. The character must be a period or comma. If the second argument is
|
|
not specified, the decimal point is the default decimal separator character.
|
|
For more information, see <a href="rbafzmstch2cons.htm#datsep">Decimal point</a>.
|
|
</dd>
|
|
</dl><p class="indatacontent">The result is the same number that would result from CAST(<var class="pv">string-expression</var> AS NUMERIC(<var class="pv">p</var>,<var class="pv">s</var>)). Digits are truncated from the end
|
|
if the number of digits to the right of the <var class="pv">decimal-character</var> is
|
|
greater than the scale <var class="pv">s</var>. An error is returned if the number of significant
|
|
digits to the left of the <var class="pv">decimal-character</var> (the whole part of the
|
|
number) in <var class="pv">string-expression</var> is greater than <var class="pv">p-s</var>. The default
|
|
decimal separator character is not valid in the substring if the <var class="pv">decimal-character</var> argument is specified.</p>
|
|
<a name="wq920"></a>
|
|
<h4 id="wq920">Note</h4>
|
|
<p><span class="bold">Syntax alternatives:</span> When the precision is specified,
|
|
the CAST specification should be used for maximal portability. For more information,
|
|
see <a href="rbafzmstdatetimearith.htm#cast">CAST specification</a>.</p>
|
|
<a name="wq921"></a>
|
|
<h4 id="wq921">Examples</h4>
|
|
<ul>
|
|
<li>Assume the host variable Z1 is a decimal host variable with a value of
|
|
1.123.
|
|
<pre class="xmp"> <span class="bold">SELECT ZONED</span>(:Z1,15,14)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 1.12300000000000.</li>
|
|
<li>Assume the host variable Z1 is a decimal host variable with a value of
|
|
1123.
|
|
<pre class="xmp"> <span class="bold">SELECT ZONED</span>(:Z1,11,2)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 1123.00.</li>
|
|
<li>Likewise,
|
|
<pre class="xmp"> <span class="bold">SELECT ZONED</span>(:Z1,4)
|
|
<span class="bold">FROM</span> SYSIBM.SYSDUMMY1</pre>Returns
|
|
the value 1123.</li></ul>
|
|
<hr /><div class="fnnum"><a id="wq547" name="wq547" href="rbafzmstscale.htm#wq546">41</a>.</div>
|
|
<div class="fntext">This function cannot be used as a source function when creating a user-defined
|
|
function. Because it accepts any compatible data types as arguments, it is
|
|
not necessary to create additional signatures to support distinct types.</div><div class="fnnum"><a id="wq602" name="wq602" href="rbafzmstscale.htm#wq601">42</a>.</div>
|
|
<div class="fntext">If the argument identifies a DDS created logical
|
|
file that is based on more than one physical file member, DBPARTITIONNUM will
|
|
not return 0, but instead will return the underlying physical file member
|
|
number.</div><div class="fnnum"><a id="wq639" name="wq639" href="rbafzmstscale.htm#wq638">43</a>.</div>
|
|
<div class="fntext">If the CCSID of <span class="italic">comment string</span> is 5026 or 930, the CCSID of the results
|
|
will be 939.</div><div class="fnnum"><a id="wq686" name="wq686" href="rbafzmstscale.htm#wq685">44</a>.</div>
|
|
<div class="fntext">This hexadecimal representation for DATE, TIMESTAMP, and NUMERIC data types
|
|
is different from other database products because the internal form for these
|
|
data types is different.</div><div class="fnnum"><a id="wq721" name="wq721" href="rbafzmstscale.htm#wq720">45</a>.</div>
|
|
<div class="fntext">The LEFT function accepts
|
|
mixed data strings. However, because LEFT operates on a strict byte-count
|
|
basis, the result will not necessarily be a properly formed mixed data string.</div><div class="fnnum"><a id="wq744" name="wq744" href="rbafzmstscale.htm#wq743">46</a>.</div>
|
|
<div class="fntext">The LTRIM function returns the same results
|
|
as: STRIP(<var class="pv">expression</var>,LEADING)</div><div class="fnnum"><a id="wq790" name="wq790" href="rbafzmstscale.htm#wq789">47</a>.</div>
|
|
<div class="fntext">This includes
|
|
the case where the <var class="pv">search-string</var> is longer than the <var class="pv">source-string</var>.</div><div class="fnnum"><a id="wq794" name="wq794" href="rbafzmstscale.htm#wq793">48</a>.</div>
|
|
<div class="fntext">The result of the POWER
|
|
function is exactly the same as the result of exponentiation: <var class="pv">expression-1</var> ** <var class="pv">expression-2</var>.</div><div class="fnnum"><a id="wq812" name="wq812" href="rbafzmstscale.htm#wq811">49</a>.</div>
|
|
<div class="fntext">If the value of <var class="pv">string-expression</var> is mixed data that is not a properly
|
|
formed mixed data string, the result will not be a properly formed mixed data
|
|
string.</div><div class="fnnum"><a id="wq818" name="wq818" href="rbafzmstscale.htm#wq817">50</a>.</div>
|
|
<div class="fntext">The RIGHT function accepts
|
|
mixed data strings. However, because RIGHT operates on a strict byte-count
|
|
basis, the result will not necessarily be a properly formed mixed data string.</div><div class="fnnum"><a id="wq832" name="wq832" href="rbafzmstscale.htm#wq831">51</a>.</div>
|
|
<div class="fntext">The RTRIM function returns the same results
|
|
as: STRIP(<var class="pv">expression</var>,TRAILING)</div><div class="fnnum"><a id="wq857" name="wq857" href="rbafzmstscale.htm#wq856">52</a>.</div>
|
|
<div class="fntext">The SUBSTR function accepts mixed data strings. However, because SUBSTR operates
|
|
on a strict byte-count basis, the result will not necessarily be a properly
|
|
formed mixed data string.</div>
|
|
<br />
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstcolfunc.htm">Previous Page</a> | <a href="rbafzmstsubsel.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>
|