911 lines
54 KiB
HTML
911 lines
54 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="DECLARE GLOBAL TEMPORARY TABLE statement,
|
||
|
DECLARE GLOBAL TEMPORARY TABLE, SQL statements, global temporary, table,
|
||
|
in DECLARE GLOBAL TEMPORARY TABLE statement, table-name, column-name,
|
||
|
system-column-name, FOR COLUMN clause, system column name, data-type,
|
||
|
in DECLARE GLOBAL TEMPORARY TABLE, data type for DECLARE GLOBAL TEMPORARY TABLE,
|
||
|
CCSID clause, CHAR, DOUBLE PRECISION, DECIMAL, FLOAT, BIGINT, INTEGER, NUMERIC,
|
||
|
REAL, SMALLINT, VARCHAR, VARGRAPHIC, GRAPHIC, FOR BIT DATA clause,
|
||
|
FOR MIXED DATA clause, FOR SBCS DATA clause, BINARY, VARBINARY, BLOB, CLOB,
|
||
|
DBCLOB, ROWID, distinct-type, buit-in-type, NOT NULL clause, WITH DEFAULT clause,
|
||
|
DEFAULT clause, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, cast-function,
|
||
|
constant, USER clause, GENERATED, IDENTITY, datalink-options, LIKE clause,
|
||
|
AS subquery clause, INCLUDING clause, EXCLUDING clause, USING clause,
|
||
|
WITH REPLACE clause, ON COMMIT clause, NOT LOGGED clause, ON ROLLBACK clause" />
|
||
|
<title>DECLARE GLOBAL TEMPORARY TABLE</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="dgtt"></a>
|
||
|
<h2 id="dgtt"><a href="rbafzmst02.htm#ToC_977">DECLARE GLOBAL TEMPORARY TABLE</a></h2><a id="idx2228" name="idx2228"></a><a id="idx2229" name="idx2229"></a><a id="idx2230" name="idx2230"></a>
|
||
|
<p>The DECLARE GLOBAL TEMPORARY TABLE statement defines a declared temporary
|
||
|
table for the current application process. The declared temporary table description
|
||
|
does not appear in the system catalog. It is not persistent and cannot be
|
||
|
shared with other application processes. Each application process that defines
|
||
|
a declared global temporary table of the same name has its own unique description
|
||
|
of the temporary table. When the application process ends, the temporary table
|
||
|
is dropped.</p>
|
||
|
<a name="wq1390"></a>
|
||
|
<h3 id="wq1390"><a href="rbafzmst02.htm#ToC_978">Invocation</a></h3>
|
||
|
<p>This statement can be embedded in an application program or issued interactively.
|
||
|
It is an executable statement that can be dynamically prepared.</p>
|
||
|
<a name="wq1391"></a>
|
||
|
<h3 id="wq1391"><a href="rbafzmst02.htm#ToC_979">Authorization</a></h3>
|
||
|
<p>If the LIKE or AS <var class="pv">select-statement</var> clause is specified, the privileges
|
||
|
held by the authorization ID of the statement must include at least one of
|
||
|
the following on any table or view specified in the LIKE clause or as-subquuery
|
||
|
clause: </p>
|
||
|
<ul>
|
||
|
<li>The SELECT privilege for the table or view</li>
|
||
|
<li>Ownership of the table or view</li>
|
||
|
<li>Administrative authority</li></ul>
|
||
|
<p>If a distinct type is referenced, the privileges held by the authorization ID of
|
||
|
the statement must include at least one of the following: </p>
|
||
|
<ul>
|
||
|
<li>For each distinct type identified in the statement:
|
||
|
<ul>
|
||
|
<li>The USAGE privilege on the distinct type, and</li>
|
||
|
<li>The system authority *EXECUTE on the library containing the distinct type</li></ul></li>
|
||
|
<li>Administrative authority</li></ul>
|
||
|
<p>For information on the system authorities corresponding to SQL privileges,
|
||
|
see <a href="rbafzmstgnt.htm#eqtablet">Corresponding System Authorities When Checking Privileges to a Table or View</a> and <a href="rbafzmstgntudtp.htm#eqtabled">Corresponding System Authorities When Checking Privileges to a Distinct Type</a>.</p>
|
||
|
<a name="wq1392"></a>
|
||
|
<h3 id="wq1392"><a href="rbafzmst02.htm#ToC_980">Syntax</a></h3>
|
||
|
<a href="rbafzmstdgtt.htm#synsdgtt"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
||
|
<a name="wq1393"></a>
|
||
|
<div class="fignone" id="wq1393">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn316.htm"
|
||
|
border="0" /></span><a href="#skipsyn-315"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>>>-DECLARE GLOBAL TEMPORARY TABLE--<span class="italic">table-name</span>------------------->
|
||
|
|
||
|
.-,------------------------------------------.
|
||
|
V |
|
||
|
>--+-(----+-<span class="italic">column-definition</span>----------------------+-+--)-+----->
|
||
|
| '-LIKE--+-<span class="italic">table-name</span>-+--+--------------+-' |
|
||
|
| '-<span class="italic">view-name</span>--' '-<span class="italic">copy-options</span>-' |
|
||
|
+-LIKE--+-<span class="italic">table-name</span>-+--+--------------+---------------+
|
||
|
| '-<span class="italic">view-name</span>--' '-<span class="italic">copy-options</span>-' |
|
||
|
'-<span class="italic">as-subquery-clause</span>-----------------------------------'
|
||
|
|
||
|
.-----------------------------------------------.
|
||
|
V | (1)
|
||
|
>----+-WITH REPLACE------------------------------+-+-----------><
|
||
|
| .-ON COMMIT DELETE ROWS---. |
|
||
|
+-+-------------------------+---------------+
|
||
|
| '-ON COMMIT PRESERVE ROWS-' |
|
||
|
| .-ON ROLLBACK DELETE ROWS---. |
|
||
|
'-NOT LOGGED--+---------------------------+-'
|
||
|
'-ON ROLLBACK PRESERVE ROWS-'
|
||
|
|
||
|
column-definition:
|
||
|
|
||
|
|--<span class="italic">column-name</span>--+-------------------------------------+--------->
|
||
|
| .-COLUMN-. |
|
||
|
'-FOR--+--------+--<span class="italic">system-column-name</span>-'
|
||
|
|
||
|
>--<span class="italic">data-type</span>---------------------------------------------------->
|
||
|
|
||
|
.-----------------------------------------------------.
|
||
|
V | (1)
|
||
|
>----+-------------------------------------------------+-+-------|
|
||
|
+-+-<span class="italic">default-clause</span>------------------------------+-+
|
||
|
| +-<span>GENERATED</span>--+-<span>ALWAYS</span>-----+--<span><span class="italic">identity-options</span></span>-+ |
|
||
|
| | '-<span>BY DEFAULT</span>-' | |
|
||
|
| '-NOT NULL------------------------------------' |
|
||
|
| (2) |
|
||
|
'-<span class="italic">datalink-options</span>--------------------------------'
|
||
|
|
||
|
data-type:
|
||
|
|
||
|
|--+-<span class="italic">built-in-type</span>------+---------------------------------------|
|
||
|
'-<span class="italic">distinct-type-name</span>-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-315" id="skipsyn-315"></a>
|
||
|
<a name="wq1394"></a>
|
||
|
<div class="notelisttitle" id="wq1394">Notes:</div>
|
||
|
<ol type="1">
|
||
|
<li>The same clause must not be specified more than once.</li>
|
||
|
<li>The datalink-options can only be specified for DATALINKs and distinct-types
|
||
|
sourced on DATALINKs.</li>
|
||
|
</ol></div>
|
||
|
<a name="wq1396"></a>
|
||
|
<div class="fignone" id="wq1396">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn317.htm"
|
||
|
border="0" /></span><a href="#skipsyn-316"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>built-in-type:
|
||
|
|
||
|
|--+-+---SMALLINT---+-----------------------------------------------------------------------------------------------+--|
|
||
|
| +-+-INTEGER-+--+ |
|
||
|
| | '-INT-----' | |
|
||
|
| '---BIGINT-----' |
|
||
|
| .-(5,0)------------------------. |
|
||
|
+-+-+-DECIMAL-+-+--+------------------------------+--------------------------------------------------------------+
|
||
|
| | '-DEC-----' | | .-,0--------. | |
|
||
|
| '-NUMERIC-----' '-(--<span class="italic">integer</span>--+-----------+--)-' |
|
||
|
| '-<span class="italic">, integer</span>-' |
|
||
|
| .-(--52--)------. |
|
||
|
+-+-FLOAT--+---------------+-+-----------------------------------------------------------------------------------+
|
||
|
| | '-(--<span class="italic">integer</span>--)-' | |
|
||
|
| +-REAL---------------------+ |
|
||
|
| | .-PRECISION-. | |
|
||
|
| '-DOUBLE--+-----------+----' |
|
||
|
| .-(--1--)-------. |
|
||
|
+-+-+-+-CHARACTER-+--+---------------+-------------------------------+--+----------------+---------------------+-+
|
||
|
| | | '-CHAR------' '-(--<span class="italic">integer</span>--)-' | +-FOR BIT DATA---+ | |
|
||
|
| | '-+-+-CHARACTER-+--VARYING-+--(--<span class="italic">integer</span>--)--+-----------------+-' +-FOR SBCS DATA--+ | |
|
||
|
| | | '-CHAR------' | '-<span class="italic">allocate-clause</span>-' +-FOR MIXED DATA-+ | |
|
||
|
| | '-VARCHAR----------------' '-<span class="italic">ccsid-clause</span>---' | |
|
||
|
| | .-(--1M--)-------------. | |
|
||
|
| '-----+-+-<span>CHARACTER</span>-+--<span>LARGE OBJECT</span>-+------+----------------------+--+-----------------+--+----------------+-' |
|
||
|
| | '-<span>CHAR</span>------' | '-(--<span class="italic">integer</span>--+---+--)-' '-<span class="italic">allocate-clause</span>-' +-FOR SBCS DATA--+ |
|
||
|
| '-<span>CLOB</span>------------------------' +-K-+ +-FOR MIXED DATA-+ |
|
||
|
| +-M-+ '-<span class="italic">ccsid-clause</span>---' |
|
||
|
| '-G-' |
|
||
|
| .-(--1--)-------. |
|
||
|
+-+---GRAPHIC----+---------------+----------------------------+--+--------------+--------------------------------+
|
||
|
| | '-(--<span class="italic">integer</span>--)-' | '-<span class="italic">ccsid-clause</span>-' |
|
||
|
| +-+-GRAPHIC VARYING-+--(--<span class="italic">integer</span>--)--+-----------------+---+ |
|
||
|
| | '-VARGRAPHIC------' '-<span class="italic">allocate-clause</span>-' | |
|
||
|
| | .-(--1M--)-------------. | |
|
||
|
| '---DBCLOB----+----------------------+--+-----------------+-' |
|
||
|
| '-(--<span class="italic">integer</span>--+---+--)-' '-<span class="italic">allocate-clause</span>-' |
|
||
|
| +-K-+ |
|
||
|
| +-M-+ |
|
||
|
| '-G-' |
|
||
|
| .-(--1--)-------. |
|
||
|
+-+-+-BINARY--+---------------+------------------------------+-----------------+---------------------------------+
|
||
|
| | | '-(--<span class="italic">integer</span>--)-' | | |
|
||
|
| | '-+-BINARY VARYING-+--(--<span class="italic">integer</span>--)--+-----------------+-' | |
|
||
|
| | '-VARBINARY------' '-<span class="italic">allocate-clause</span>-' | |
|
||
|
| | .-(--1M--)-------------. | |
|
||
|
| '---+-BLOB----------------+----+----------------------+--+-----------------+-' |
|
||
|
| '-BINARY LARGE OBJECT-' '-(--<span class="italic">integer</span>--+---+--)-' '-<span class="italic">allocate-clause</span>-' |
|
||
|
| +-K-+ |
|
||
|
| +-M-+ |
|
||
|
| '-G-' |
|
||
|
+-+-DATE------+--------------------------------------------------------------------------------------------------+
|
||
|
| +-TIME------+ |
|
||
|
| '-TIMESTAMP-' |
|
||
|
| .-(--200--)-----. |
|
||
|
'---DATALINK--+---------------+--+-----------------+--+--------------+-------------------------------------------'
|
||
|
'-(--<span class="italic">integer</span>--)-' '-<span class="italic">allocate-clause</span>-' '-<span class="italic">ccsid-clause</span>-'
|
||
|
|
||
|
ccsid-clause:
|
||
|
|
||
|
.-NOT NORMALIZED-.
|
||
|
|--CCSID--<span class="italic">integer</span>--+----------------+---------------------------|
|
||
|
'-NORMALIZED-----'
|
||
|
|
||
|
allocate-clause:
|
||
|
|
||
|
|--ALLOCATE--<span class="italic">(integer)</span>------------------------------------------|
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-316" id="skipsyn-316"></a></div>
|
||
|
<a name="wq1397"></a>
|
||
|
<div class="fignone" id="wq1397">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn318.htm"
|
||
|
border="0" /></span><a href="#skipsyn-317"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>default-clause:
|
||
|
|
||
|
.-WITH-.
|
||
|
|--+------+--DEFAULT--+-------------------------------------------------+--|
|
||
|
+-<span class="italic">constant</span>----------------------------------------+
|
||
|
+-USER--------------------------------------------+
|
||
|
+-NULL--------------------------------------------+
|
||
|
+-CURRENT_DATE------------------------------------+
|
||
|
+-CURRENT_TIME------------------------------------+
|
||
|
+-CURRENT_TIMESTAMP-------------------------------+
|
||
|
'-<span class="italic">cast-function-name</span>--(--+-<span class="italic">constant</span>----------+--)-'
|
||
|
+-USER--------------+
|
||
|
+-CURRENT_DATE------+
|
||
|
+-CURRENT_TIME------+
|
||
|
'-CURRENT_TIMESTAMP-'
|
||
|
|
||
|
identity-options:
|
||
|
|
||
|
|--AS IDENTITY--+-------------------------------------------------------+--|
|
||
|
| .-,-------------------------------------------. |
|
||
|
| V .-<span class="italic">1</span>----------------. (1) | |
|
||
|
'-(----+-START WITH--+-<span class="italic">numeric-constant</span>-+---+------+--)-'
|
||
|
| .-<span class="italic">1</span>----------------. |
|
||
|
+-INCREMENT BY--+-<span class="italic">numeric-constant</span>-+-+
|
||
|
| .-NO MINVALUE----------------. |
|
||
|
+-+-MINVALUE--<span class="italic">numeric-constant</span>-+-----+
|
||
|
| .-NO MAXVALUE----------------. |
|
||
|
+-+-MAXVALUE--<span class="italic">numeric-constant</span>-+-----+
|
||
|
| .-NO CYCLE-. |
|
||
|
+-+-CYCLE----+-----------------------+
|
||
|
| .-CACHE--<span class="italic">20</span>------. |
|
||
|
+-+-NO CACHE-------+-----------------+
|
||
|
| '-CACHE--<span class="italic">integer</span>-' |
|
||
|
| .-NO ORDER-. |
|
||
|
'-+-ORDER----+-----------------------'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-317" id="skipsyn-317"></a>
|
||
|
<a name="wq1398"></a>
|
||
|
<div class="notelisttitle" id="wq1398">Notes:</div>
|
||
|
<ol type="1">
|
||
|
<li>The same clause must not be specified more than once.</li>
|
||
|
</ol></div>
|
||
|
<a name="wq1400"></a>
|
||
|
<div class="fignone" id="wq1400">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn319.htm"
|
||
|
border="0" /></span><a href="#skipsyn-318"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>datalink-options:
|
||
|
|
||
|
.-LINKTYPE URL-. .-NO LINK CONTROL-.
|
||
|
|--+--------------+--+-----------------+------------------------|
|
||
|
|
||
|
copy-options:
|
||
|
|
||
|
.-COLUMN ATTRIBUTES-. .-COLUMN-. (1)
|
||
|
|----+-EXCLUDING IDENTITY--+-------------------+-+--+-EXCLUDING--+--------+--DEFAULTS-+---------|
|
||
|
| .-COLUMN ATTRIBUTES-. | | .-COLUMN-. |
|
||
|
'-INCLUDING IDENTITY--+-------------------+-' +-INCLUDING--+--------+--DEFAULTS-+
|
||
|
'-USING TYPE DEFAULTS-------------'
|
||
|
|
||
|
as-subquery-clause:
|
||
|
|
||
|
|--+----------------------------------------------------------------+-->
|
||
|
| .------------------------------------------------------. |
|
||
|
| V | |
|
||
|
'-(----<span class="italic">column-name</span>--+-------------------------------------+-+--)-'
|
||
|
| .-COLUMN-. |
|
||
|
'-FOR--+--------+--<span class="italic">system-column-name</span>-'
|
||
|
|
||
|
>--AS--(--<span class="italic">select-statement</span>--)--+-WITH NO DATA-+--+--------------+--|
|
||
|
'-WITH DATA----' '-<span class="italic">copy-options</span>-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-318" id="skipsyn-318"></a>
|
||
|
<a name="wq1401"></a>
|
||
|
<div class="notelisttitle" id="wq1401">Notes:</div>
|
||
|
<ol type="1">
|
||
|
<li>The clauses can be specified in any order.</li>
|
||
|
</ol></div>
|
||
|
<a name="synsdgtt"></a>
|
||
|
<h3 id="synsdgtt"><a href="rbafzmst02.htm#ToC_981">Description</a></h3>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">table-name</var></dt>
|
||
|
<dd>Names the temporary table. <a id="idx2231" name="idx2231"></a> The qualifier,
|
||
|
if specified explicitly, must be SESSION, otherwise an error is returned.
|
||
|
If the qualifier is not specified, it is implicitly defined to be SESSION.
|
||
|
If a declared temporary table, or an index or view that is dependent on a
|
||
|
declared temporary table already exists with the same name, an error is returned.
|
||
|
<p>If a persistent table, view, index, or alias already exists with the same
|
||
|
name and the schema name SESSION:</p>
|
||
|
<ul>
|
||
|
<li>The declared temporary table is still defined with SESSION.<var class="pv">table-name</var>. An error is not issued because the resolution of a declared temporary
|
||
|
table name does not include a permanent library.</li>
|
||
|
<li>Any references to SESSION.<var class="pv">table-name</var> will resolve to the declared
|
||
|
temporary table rather than to a permanent table, view, index, or alias with
|
||
|
a name of SESSION.<var class="pv">table-name</var>.</li></ul>
|
||
|
<p>The table will be created in library QTEMP.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1403"></a>
|
||
|
<h3 id="wq1403"><a href="rbafzmst02.htm#ToC_982">column-definition</a></h3>
|
||
|
<p>Defines the attributes of a column. There must be at least one column definition
|
||
|
and no more than 8000 column definitions.</p>
|
||
|
<p>The sum of the row buffer byte counts of the columns must not be greater
|
||
|
than 32766 or, if a VARCHAR or VARGRAPHIC column is specified, 32740. Additionally,
|
||
|
if a LOB is specified, the sum of the row data byte counts of the columns
|
||
|
must not be greater than 3.5 gigabytes. For information on the byte counts
|
||
|
of columns according to data type, see <a href="rbafzmsthctabl.htm#unctabl">Notes</a>.</p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">column-name</var> </dt><a id="idx2232" name="idx2232"></a>
|
||
|
<dd>Names a column of the table. Do not qualify <var class="pv">column-name</var> and
|
||
|
do not use the same name for more than one column of the table or for a system-column-name
|
||
|
of the table.
|
||
|
</dd>
|
||
|
<dt class="bold">FOR COLUMN <var class="pv">system-column-name</var> </dt><a id="idx2233" name="idx2233"></a><a id="idx2234" name="idx2234"></a>
|
||
|
<dd>Provides an i5/OS name for the column. Do not use the same name for
|
||
|
more than one column of the table or for a column-name of the table. <a id="idx2235" name="idx2235"></a>
|
||
|
<p>If the system-column-name is
|
||
|
not specified, and the column-name is not a valid system-column-name, a system
|
||
|
column name is generated. For more information about how system column names
|
||
|
are generated, see <a href="rbafzmsthctabl.htm#cnamrul">Rules for Column Name Generation</a>.</p>
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">data-type</var></dt><a id="idx2236" name="idx2236"></a><a id="idx2237" name="idx2237"></a><a id="idx2238" name="idx2238"></a><a id="idx2239" name="idx2239"></a><a id="idx2240" name="idx2240"></a><a id="idx2241" name="idx2241"></a><a id="idx2242" name="idx2242"></a><a id="idx2243" name="idx2243"></a><a id="idx2244" name="idx2244"></a><a id="idx2245" name="idx2245"></a><a id="idx2246" name="idx2246"></a><a id="idx2247" name="idx2247"></a><a id="idx2248" name="idx2248"></a><a id="idx2249" name="idx2249"></a><a id="idx2250" name="idx2250"></a><a id="idx2251" name="idx2251"></a><a id="idx2252" name="idx2252"></a><a id="idx2253" name="idx2253"></a><a id="idx2254" name="idx2254"></a><a id="idx2255" name="idx2255"></a><a id="idx2256" name="idx2256"></a><a id="idx2257" name="idx2257"></a><a id="idx2258" name="idx2258"></a><a id="idx2259" name="idx2259"></a><a id="idx2260" name="idx2260"></a>
|
||
|
<dd>Specifies the data type of the column.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">built-in-type</var> </dt><a id="idx2261" name="idx2261"></a>
|
||
|
<dd>Specifies a built-in data type. See <a href="rbafzmsthctabl.htm#hctabl">CREATE TABLE</a> for a description
|
||
|
of <span class="italic">built-in-type</span>.
|
||
|
<p>A ROWID column or a DATALINK column
|
||
|
with FILE LINK CONTROL cannot be specified for a global temporary table.</p>
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">distinct-type-name</var> </dt><a id="idx2262" name="idx2262"></a>
|
||
|
<dd>Specifies that the data type of the column is a distinct type (a user-defined
|
||
|
data type). The length, precision, and scale of the column are respectively
|
||
|
the length, precision, and scale of the source type of the distinct type.
|
||
|
If a distinct type name is specified without a schema name, the distinct type
|
||
|
name is resolved by searching the schemas on the SQL path.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">NOT NULL </dt><a id="idx2263" name="idx2263"></a>
|
||
|
<dd>Prevents the column from containing null values. Omission of NOT NULL
|
||
|
implies that the column can be null.
|
||
|
</dd>
|
||
|
<dt class="bold"><a id="crtdft2" name="crtdft2"></a>DEFAULT </dt><a id="idx2264" name="idx2264"></a><a id="idx2265" name="idx2265"></a>
|
||
|
<dd>Specifies a default value for the column. This clause cannot be specified
|
||
|
more than once in a <var class="pv">column-definition</var>. DEFAULT cannot be specified
|
||
|
an identity column (a column that is defined AS IDENTITY). The database manager generates
|
||
|
default values for identity columns. If a value is not specified following
|
||
|
the DEFAULT keyword, then:
|
||
|
<ul>
|
||
|
<li>if the column is nullable, the default value is the null value.</li>
|
||
|
<li>if the column is not nullable, the default depends on the data type of
|
||
|
the column:
|
||
|
<a name="wq1404"></a>
|
||
|
<table id="wq1404" width="90%" summary="" border="1" frame="border" rules="all">
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq1405" width="40%" align="left" valign="top">Data type</th>
|
||
|
<th id="wq1406" width="59%" align="left" valign="top">Default value</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Numeric</td>
|
||
|
<td align="left" valign="top" headers="wq1406">0</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Fixed-length character or graphic string</td>
|
||
|
<td align="left" valign="top" headers="wq1406">Blanks</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Fixed-length binary string</td>
|
||
|
<td align="left" valign="top" headers="wq1406">Hexadecimal zeros</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Varying-length string</td>
|
||
|
<td align="left" valign="top" headers="wq1406">A string length of 0</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Date</td>
|
||
|
<td align="left" valign="top" headers="wq1406">The current date at the time of INSERT</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Time</td>
|
||
|
<td align="left" valign="top" headers="wq1406">The current time at the time of INSERT</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Timestamp</td>
|
||
|
<td align="left" valign="top" headers="wq1406">The current timestamp at the time of INSERT</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405">Datalink</td>
|
||
|
<td align="left" valign="top" headers="wq1406">A value corresponding to DLVALUE('','URL','')</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1405"><var class="pv">distinct-type</var></td>
|
||
|
<td align="left" valign="top" headers="wq1406">The default value of the corresponding source
|
||
|
type of the distinct type.</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table></li></ul>
|
||
|
<p>Omission of NOT NULL and DEFAULT from a <var class="pv">column-definition</var> is
|
||
|
an implicit specification of DEFAULT NULL. </p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><span class="italic">constant</span></dt>
|
||
|
<dd>Specifies the constant as the default for the column. The specified
|
||
|
constant must represent a value that could be assigned to the column in accordance
|
||
|
with the rules of assignment as described in <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.
|
||
|
A floating-point constant must not be used for a SMALLINT, INTEGER, DECIMAL,
|
||
|
or NUMERIC column. A decimal constant must not contain more digits to the
|
||
|
right of the decimal point than the specified scale of the column.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">USER</span></dt>
|
||
|
<dd>Specifies the value of the USER special register at the time of INSERT
|
||
|
or UPDATE as the default value of the column. The data type of the column
|
||
|
must be CHAR or VARCHAR with a length attribute greater than or equal to the
|
||
|
length attribute of the USER special register.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">NULL</span></dt>
|
||
|
<dd>Specifies null as the default for the column. If NOT NULL is specified,
|
||
|
DEFAULT NULL must not be specified within the same <var class="pv">column-definition</var>.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">CURRENT_DATE</span> </dt><a id="idx2266" name="idx2266"></a>
|
||
|
<dd>Specifies the current date as the default for the column. If CURRENT_DATE
|
||
|
is specified, the data type of the column must be DATE or a distinct type
|
||
|
based on a DATE.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">CURRENT_TIME</span> </dt><a id="idx2267" name="idx2267"></a>
|
||
|
<dd>Specifies the current time as the default for the column. If CURRENT_TIME
|
||
|
is specified, the data type of the column must be TIME or a distinct type
|
||
|
based on a TIME.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">CURRENT_TIMESTAMP</span> <a id="idx2268" name="idx2268"></a></dt>
|
||
|
<dd>Specifies the current timestamp as the default for the column. If CURRENT_TIMESTAMP
|
||
|
is specified, the data type of the column must be TIMESTAMP or a distinct
|
||
|
type based on a TIMESTAMP.
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">cast-function-name</var> </dt><a id="idx2269" name="idx2269"></a>
|
||
|
<dd>This form of a default value can only be used with columns defined as
|
||
|
a distinct type, <span>BINARY, VARBINARY,</span> BLOB, CLOB, DBCLOB, DATE, TIME
|
||
|
or TIMESTAMP data types. The following table describes the allowed uses of
|
||
|
these <var class="pv">cast-functions</var>.
|
||
|
<a name="wq1407"></a>
|
||
|
<table id="wq1407" width="100%" summary="" border="1" frame="border" rules="none">
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq1408" width="47%" align="left" valign="top">Data Type</th>
|
||
|
<th id="wq1409" width="52%" align="left" valign="top">Cast Function Name</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1408">Distinct type N based on a <span>BINARY, VARBINARY,</span> BLOB, CLOB, or DBCLOB</td>
|
||
|
<td align="left" valign="top" headers="wq1409"><span>BINARY, VARBINARY,</span> BLOB, CLOB, or
|
||
|
DBCLOB *</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1408">Distinct type N based on a DATE, TIME, or
|
||
|
TIMESTAMP</td>
|
||
|
<td align="left" valign="top" headers="wq1409">N (the user-defined cast function that was
|
||
|
generated when N was created) **
|
||
|
<div class="lines">or<br />
|
||
|
DATE, TIME, or TIMESTAMP *<br />
|
||
|
</div></td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1408">Distinct type N based on other data types</td>
|
||
|
<td align="left" valign="top" headers="wq1409">N (the user-defined cast function that was
|
||
|
generated when N was created) **</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1408"><span>BINARY, VARBINARY,</span> BLOB, CLOB, or
|
||
|
DBCLOB</td>
|
||
|
<td align="left" valign="top" headers="wq1409"><span>BINARY, VARBINARY,</span> BLOB, CLOB, or
|
||
|
DBCLOB *</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1408">DATE, TIME, or TIMESTAMP</td>
|
||
|
<td align="left" valign="top" headers="wq1409">DATE, TIME, or TIMESTAMP *</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td colspan="2" align="left" valign="top" headers="wq1408 wq1409">
|
||
|
<a name="wq1410"></a>
|
||
|
<div class="notetitle" id="wq1410">Notes:</div>
|
||
|
<div class="notebody">
|
||
|
<p>* The name of the function must
|
||
|
match the name of the data type (or the source type of the distinct type)
|
||
|
with an implicit or explicit schema name of QSYS2.</p>
|
||
|
<p>**
|
||
|
The name of the function must match the name of the distinct type for the
|
||
|
column. If qualified with a schema name, it must be the same as the schema
|
||
|
name for the distinct type. If not qualified, the schema name from function
|
||
|
resolution must be the same as the schema name for the distinct type.</p></div></td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">constant</var> </dt><a id="idx2270" name="idx2270"></a>
|
||
|
<dd>Specifies a constant as the argument. The constant must conform to the
|
||
|
rules of a constant for the source type of the distinct type or for the data
|
||
|
type if not a distinct type. For <span>BINARY, VARBINARY,</span> BLOB, CLOB, DBCLOB,
|
||
|
DATE, TIME, and TIMESTAMP functions, the constant must be a string constant.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">USER</span></dt><a id="idx2271" name="idx2271"></a>
|
||
|
<dd>Specifies the value of the USER special register at the time of INSERT
|
||
|
or UPDATE as the default value for the column. The data type of the source
|
||
|
type of the distinct type of the column must be CHAR or VARCHAR with a length
|
||
|
attribute greater than or equal to the length attribute of the USER special
|
||
|
register.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">CURRENT_DATE</span> </dt><a id="idx2272" name="idx2272"></a>
|
||
|
<dd>Specifies the current date as the default for the column. If CURRENT_DATE
|
||
|
is specified, the data type of the source type of the distinct type of the
|
||
|
column must be DATE.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">CURRENT_TIME</span> </dt><a id="idx2273" name="idx2273"></a>
|
||
|
<dd>Specifies the current time as the default for the column. If CURRENT_TIME
|
||
|
is specified, the data type of the source type of the distinct type of the
|
||
|
column must be TIME.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">CURRENT_TIMESTAMP</span> </dt><a id="idx2274" name="idx2274"></a>
|
||
|
<dd>Specifies the current timestamp as the default for the column. If CURRENT_TIMESTAMP
|
||
|
is specified, the data type of the source type of the distinct type of the
|
||
|
column must be TIMESTAMP.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>If the value specified is not valid, an error is returned.</p>
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">GENERATED</span> </dt><a id="idx2275" name="idx2275"></a>
|
||
|
<dd>Specifies that the database manager generates values for the column. GENERATED may
|
||
|
be specified if the column is to be considered an identity column (defined
|
||
|
with the AS IDENTITY clause).
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><span class="bold">ALWAYS</span></dt>
|
||
|
<dd>Specifies that the database manager will always generate a value for the column when
|
||
|
a row is inserted into the table. ALWAYS is the recommended value.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">BY DEFAULT</span></dt>
|
||
|
<dd>Specifies that the database manager will generate a value for the column when a row
|
||
|
is inserted only if a value is not specified for the column. If a value is
|
||
|
specified, the database manager uses that value.
|
||
|
<p>For an identity column, the database manager inserts
|
||
|
a specified value but does not verify that it is a unique value for the column
|
||
|
unless the identity column has a unique constraint or a unique index that
|
||
|
solely specifies the identity column.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="bold">AS IDENTITY</span> </dt><a id="idx2276" name="idx2276"></a>
|
||
|
<dd>Specifies that the column is an identity column for the table. A table
|
||
|
can have only one identity column. AS IDENTITY can be specified only if the
|
||
|
data type for the column is an exact numeric type with a scale of zero (SMALLINT,
|
||
|
INTEGER, BIGINT, DECIMAL or NUMERIC with a scale of zero, or a distinct type
|
||
|
based on one of these data types). If a DECIMAL or NUMERIC data type is specified,
|
||
|
the precision must not be greater than 31.
|
||
|
<p>An identity column is implicitly
|
||
|
NOT NULL. See the AS IDENTITY clause in <a href="rbafzmsthctabl.htm#hctabl">CREATE TABLE</a> for the descriptions
|
||
|
of the identity attributes.</p>
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">datalink-options</var> </dt><a id="idx2277" name="idx2277"></a>
|
||
|
<dd>Specifies the options associated with a DATALINK data type.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">LINKTYPE URL</dt>
|
||
|
<dd>Defines the type of link as a Uniform Resource Locator (URL).
|
||
|
</dd>
|
||
|
<dt class="bold">NO LINK CONTROL</dt>
|
||
|
<dd>Specifies that there will not be any check made to determine that the
|
||
|
linked files exist. Only the syntax of the URL will be checked. There is no
|
||
|
database manager control over the linked files.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1411"></a>
|
||
|
<h3 id="wq1411"><a href="rbafzmst02.htm#ToC_983">LIKE</a></h3><a id="idx2278" name="idx2278"></a>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">table-name</var> or <var class="pv">view-name</var> </dt>
|
||
|
<dd>Specifies that the columns defined in the specified table or view are
|
||
|
included in this table. The <var class="pv">table-name</var> or <var class="pv">view-name</var> specified
|
||
|
in a LIKE clause must identify the table or view that already exists at the application server.
|
||
|
<p>The use of LIKE is an implicit definition of n columns, where n is the number
|
||
|
of columns in the identified table or view. The implicit definition includes
|
||
|
the following attributes of the n columns (if applicable to the data type):</p>
|
||
|
<ul>
|
||
|
<li>Column name (and system column name)</li>
|
||
|
<li>Data type, length, precision, and scale</li>
|
||
|
<li>CCSID</li></ul>
|
||
|
<p>If the LIKE clause is specified immediately following the <var class="pv">table-name</var> and not enclosed in parenthesis, the following column attributes
|
||
|
are also included, otherwise they are not included (the default value and
|
||
|
identity attributes can also be controlled by using the <var class="pv">copy-options</var>):</p>
|
||
|
<ul>
|
||
|
<li>Default value, if a <var class="pv">table-name</var> is specified (<var class="pv">view-name</var> is
|
||
|
not specified)</li>
|
||
|
<li>Identity attributes</li>
|
||
|
<li>Nullability</li>
|
||
|
<li>Column heading and text (see <a href="rbafzmstlabelon.htm#labelon">LABEL</a>)</li></ul>
|
||
|
<p>If the specified table or view is a non-SQL created physical file
|
||
|
or logical file, any non-SQL attributes are removed. For example, the date
|
||
|
and time format will be changed to ISO.</p>
|
||
|
<p>The implicit definition does
|
||
|
not include any other optional attributes of the identified table or view.
|
||
|
For example, the new table does not automatically include a primary key or
|
||
|
foreign key from a table. The new table has these and other optional attributes
|
||
|
only if the optional clauses are explicitly specified.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1412"></a>
|
||
|
<h3 id="wq1412"><a href="rbafzmst02.htm#ToC_984">as-subquery-clause</a></h3><a id="idx2279" name="idx2279"></a>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">column-name</var> </dt>
|
||
|
<dd>Names a column of the table. Do not qualify <var class="pv">column-name</var> and
|
||
|
do not use the same name for more than one column of the table or for a system-column-name
|
||
|
of the table.
|
||
|
</dd>
|
||
|
<dt class="bold">FOR COLUMN <var class="pv">system-column-name</var> </dt>
|
||
|
<dd>Provides an i5/OS name for the column. Do not use the same name for
|
||
|
more than one column of the table or for a column-name of the table.
|
||
|
<p>If
|
||
|
the system-column-name is not specified, and the column-name is not a valid
|
||
|
system-column-name, a system column name is generated. For more information
|
||
|
about how system column names are generated, see <a href="rbafzmsthctabl.htm#cnamrul">Rules for Column Name Generation</a>.</p>
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">select-statement</var> </dt>
|
||
|
<dd>Specifies that the columns of the table are to have the same name and
|
||
|
description as the columns that would appear in the derived result table of
|
||
|
the <var class="pv">select-statement</var> if the <var class="pv">select-statement</var> were to be
|
||
|
executed. The use of AS <var class="pv">select-statement</var> is an implicit definition
|
||
|
of <var class="pv">n</var> columns for the table, where <var class="pv">n</var> is the number of columns
|
||
|
that would result from the <var class="pv">select-statement</var>. The implicit definition
|
||
|
includes the following attributes of the <var class="pv">n</var> columns (if applicable
|
||
|
to the data type):
|
||
|
<ul>
|
||
|
<li>Column name (and system column name)</li>
|
||
|
<li>Data type, length, precision, and scale</li>
|
||
|
<li>CCSID</li>
|
||
|
<li>Nullability</li>
|
||
|
<li>Column heading and text (see <a href="rbafzmstlabelon.htm#labelon">LABEL</a>)</li></ul>
|
||
|
<p>The following attributes are not included (the default value and identity
|
||
|
attributes may be included by using the <var class="pv">copy-options</var>):</p>
|
||
|
<ul>
|
||
|
<li>Default value</li>
|
||
|
<li>Identity attributes</li></ul>
|
||
|
<p>The implicit definition does not include any other optional attributes
|
||
|
of the tables or views referenced in the <var class="pv">select-statement</var>.</p>
|
||
|
<p>The implicitly defined columns of the table inherit the names of the columns
|
||
|
from the result table of the <var class="pv">select-statement</var>. Therefore, a column
|
||
|
name must be specified in the <var class="pv">select-statement</var> or in the column name
|
||
|
list for all result columns. For result columns that are derived from expressions,
|
||
|
constants, and functions, the <var class="pv">select-statement</var> must include the AS
|
||
|
column-name clause immediately after the result column or a name must be specified
|
||
|
in the column list preceding the <var class="pv">select-statement</var>.</p>
|
||
|
<p>The <var class="pv">select-statement</var> must not refer to variables or include parameter markers
|
||
|
(question marks). The <var class="pv">select-statement</var> must not contain a PREVIOUS
|
||
|
VALUE or a NEXT VALUE expression.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">WITH DATA</dt>
|
||
|
<dd>Specifies that the <var class="pv">select-statement</var> is executed. After the
|
||
|
table is created, the result table rows of the <var class="pv">select-statement</var> are
|
||
|
automatically inserted into the table.
|
||
|
</dd>
|
||
|
<dt class="bold">WITH NO DATA</dt>
|
||
|
<dd>Specifies that the <var class="pv">select-statement</var> is not executed. Therefore,
|
||
|
there is no result table with a set of rows with which to automatically populate
|
||
|
the table.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1413"></a>
|
||
|
<h3 id="wq1413"><a href="rbafzmst02.htm#ToC_985">copy-options</a></h3><a id="idx2280" name="idx2280"></a><a id="idx2281" name="idx2281"></a><a id="idx2282" name="idx2282"></a>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">INCLUDING IDENTITY COLUMN ATTRIBUTES <span>or</span> EXCLUDING IDENTITY COLUMN ATTRIBUTES</dt>
|
||
|
<dd>Specifies whether identity column attributes are inherited.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">INCLUDING IDENTITY COLUMN ATTRIBUTES</dt>
|
||
|
<dd>Specifies that the table inherits the identity attribute, if any, of
|
||
|
the columns resulting from <var class="pv">select-statement</var>, <var class="pv">table-name</var>,
|
||
|
or <var class="pv">view-name</var>. In general, the identity attribute is copied if the
|
||
|
element of the corresponding column in the table, view, or <var class="pv">select-statement</var> is the name of a table column or the name of a view column that directly
|
||
|
or indirectly maps to the name of a base table column with the identity attribute.
|
||
|
If the INCLUDING IDENTITY COLUMN ATTRIBUTES clause is specified with the AS <var class="pv">select-statement</var> clause, the columns of the new table do not inherit
|
||
|
the identity attribute in the following cases:
|
||
|
<ul>
|
||
|
<li>The select list of the <var class="pv">select-statement</var> includes multiple instances
|
||
|
of an identity column name (that is, selecting the same column more than once).</li>
|
||
|
<li>The select list of the <var class="pv">select-statement</var> includes multiple identity
|
||
|
columns (that is, it involves a join).</li>
|
||
|
<li>The identity column is included in an expression in the select list.</li>
|
||
|
<li>The <var class="pv">select-statement</var> includes a set operation (UNION or INTERSECT).</li></ul>
|
||
|
<p>If INCLUDING IDENTITY is not specified, the table will not have an
|
||
|
identity column.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">EXCLUDING IDENTITY COLUMN ATTRIBUTES</dt>
|
||
|
<dd>Specifies that the table does not inherit the identity attribute, if
|
||
|
any, of the columns resulting from the <var class="pv">fullselect</var>, <var class="pv">table-name</var>, or <var class="pv">view-name</var>.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">EXCLUDING COLUMN DEFAULTS <span>or</span> INCLUDING
|
||
|
COLUMN DEFAULTS <span>or</span> USING TYPE DEFAULTS</dt>
|
||
|
<dd>Specifies whether column defaults are inherited.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">EXCLUDING COLUMN DEFAULTS</dt>
|
||
|
<dd>Specifies that the column defaults are not inherited from the definition
|
||
|
of the source table. The default values of the column of the new table are
|
||
|
either null or there are no default values. If the column can be null, the
|
||
|
default is the null value. If the column cannot be null, there is no default
|
||
|
value, and an error occurs if a value is not provided for a column on INSERT
|
||
|
for the new table.
|
||
|
</dd>
|
||
|
<dt class="bold">INCLUDING COLUMN DEFAULTS</dt>
|
||
|
<dd>Specifies that the table inherits the default values of the columns
|
||
|
resulting from the <var class="pv">select-statement</var>, <var class="pv">table-name</var>, or <var class="pv">view-name</var>. A default value is the value assigned to a column when a value
|
||
|
is not specified on an INSERT.
|
||
|
<p>Do not specify INCLUDING COLUMN DEFAULTS,
|
||
|
if you specify USING TYPE DEFAULTS.</p>
|
||
|
<p>If INCLUDING COLUMN DEFAULTS is
|
||
|
not specified, the default values are not inherited.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">USING TYPE DEFAULTS</dt>
|
||
|
<dd>Specifies that the default values for the table depend on the data type
|
||
|
of the columns that result from the <var class="pv">select-statement</var>, <var class="pv">table-name</var>, or <var class="pv">view-name</var>. If the column is nullable, then the default
|
||
|
value is the null value. Otherwise, the default value is as follows:
|
||
|
<a name="wq1414"></a>
|
||
|
<table id="wq1414" width="100%" summary="" border="1" frame="border" rules="all">
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq1415" width="40%" align="left" valign="top">Data type</th>
|
||
|
<th id="wq1416" width="59%" align="left" valign="top">Default value</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Numeric</td>
|
||
|
<td align="left" valign="top" headers="wq1416">0</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Fixed-length character or graphic string</td>
|
||
|
<td align="left" valign="top" headers="wq1416">Blanks</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Fixed-length binary string</td>
|
||
|
<td align="left" valign="top" headers="wq1416">Hexadecimal zeros</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Varying-length string</td>
|
||
|
<td align="left" valign="top" headers="wq1416">A string length of 0</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Date</td>
|
||
|
<td align="left" valign="top" headers="wq1416">The current date at the time of INSERT</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Time</td>
|
||
|
<td align="left" valign="top" headers="wq1416">The current time at the time of INSERT</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Timestamp</td>
|
||
|
<td align="left" valign="top" headers="wq1416">The current timestamp at the time of INSERT</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415">Datalink</td>
|
||
|
<td align="left" valign="top" headers="wq1416">A value corresponding to DLVALUE('','URL','')</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1415"><var class="pv">distinct-type</var></td>
|
||
|
<td align="left" valign="top" headers="wq1416">The default value of the corresponding source
|
||
|
type of the distinct type.</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<p>Do not specify USING TYPE DEFAULTS if INCLUDING COLUMN
|
||
|
DEFAULTS is specified.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">WITH REPLACE</dt><a id="idx2283" name="idx2283"></a>
|
||
|
<dd>Specifies that, in the case that a declared global temporary table already
|
||
|
exists with the specified name, the existing table is replaced with the temporary
|
||
|
table defined by this statement (and all rows of the existing table are deleted).
|
||
|
<p>When WITH REPLACE is not specified, then the name specified must not identify
|
||
|
a declared global temporary table that already exists in the current session.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">ON COMMIT</dt><a id="idx2284" name="idx2284"></a>
|
||
|
<dd>Specifies the action taken on the global temporary table when a COMMIT
|
||
|
operation is performed.
|
||
|
<p>The ON COMMIT clause does not apply if the declared
|
||
|
global temporary table is opened under isolation level No Commit (NC) or if
|
||
|
a COMMIT HOLD operation is performed.</p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">DELETE ROWS</dt>
|
||
|
<dd>All rows of the table will be deleted if no WITH HOLD cursor is open
|
||
|
on the table. This is the default.
|
||
|
</dd>
|
||
|
<dt class="bold">PRESERVE ROWS</dt>
|
||
|
<dd>Rows of the table will be preserved.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">NOT LOGGED</dt><a id="idx2285" name="idx2285"></a>
|
||
|
<dd>Changes to the table are not logged, including creation of the table.
|
||
|
When a ROLLBACK (or ROLLBACK TO SAVEPOINT) operation is performed and the
|
||
|
table was changed in the unit of work (or savepoint), the changes are not
|
||
|
rolled back. If the table was created in the unit of work (or savepoint),
|
||
|
then that table will be dropped. If the table was dropped in the unit of work
|
||
|
(or savepoint) then the table will be restored, but with no rows.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">ON ROLLBACK</dt><a id="idx2286" name="idx2286"></a>
|
||
|
<dd>Specifies the action taken on the global temporary table when a ROLLBACK
|
||
|
operation is performed.
|
||
|
<p> The ON ROLLBACK clause does not apply if the declared
|
||
|
global temporary table was opened under isolation level No Commit (NC) or
|
||
|
if a ROLLBACK HOLD operation is performed.</p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">DELETE ROWS</dt>
|
||
|
<dd>All rows of the table will be deleted. This is the default.
|
||
|
</dd>
|
||
|
<dt class="bold">PRESERVE ROWS</dt>
|
||
|
<dd>Rows of the table will be preserved.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1417"></a>
|
||
|
<h3 id="wq1417"><a href="rbafzmst02.htm#ToC_986">Notes</a></h3>
|
||
|
<p><span class="bold">Instantiation, scope, and termination:</span> Let P denote
|
||
|
an application process and let T be a declared temporary table in an application
|
||
|
program in P:</p>
|
||
|
<ul>
|
||
|
<li>When a program in P issues a DECLARE GLOBAL TEMPORARY TABLE statement,
|
||
|
an empty instance of T is created.</li>
|
||
|
<li>Any program in P can reference T, and any of those references is a reference
|
||
|
to that same instance of T. (If a DECLARE GLOBAL TEMPORARY statement is specified
|
||
|
within a compound statement of an SQL function, SQL procedure, or trigger;
|
||
|
the scope of the declared temporary table is the application process and not
|
||
|
the compound statement.)
|
||
|
<p>If T was declared at a remote server, the reference
|
||
|
to T must use the same connection that was used to declare T and that connection
|
||
|
must not have been terminated after T was declared. When the connection to
|
||
|
the database server at which T was declared terminates, T is dropped.</p></li>
|
||
|
<li>If T is defined with the ON COMMIT DELETE ROWS clause, when a commit operation
|
||
|
terminates a unit of work in P and no program in P has a WITH HOLD cursor
|
||
|
open that is dependent on T, all rows are deleted.</li>
|
||
|
<li>If T is defined with the ON ROLLBACK DELETE ROWS clause, when a rollback
|
||
|
operation terminates a unit of work in P, all rows are deleted.</li>
|
||
|
<li>When the application process that declared T terminates, T is dropped.</li></ul>
|
||
|
<p><span class="bold">Temporary table ownership:</span> The <span class="italic">owner</span> of the table is the user profile of the job executing the statement.</p>
|
||
|
<p><span class="bold">Temporary table authority:</span> When a declared temporary
|
||
|
table is defined, PUBLIC implicitly is granted all table privileges on the
|
||
|
table and authority to drop the table.</p>
|
||
|
<p><span class="bold">Referring to a declared temporary table in other SQL statements:</span> Many SQL statements support declared temporary tables. To refer to a
|
||
|
declared temporary table in an SQL statement other than DECLARE GLOBAL TEMPORARY
|
||
|
TABLE, the table must be implicitly or explicitly qualified with SESSION.</p>
|
||
|
<p>If you use SESSION as the qualifier for a table name but the application
|
||
|
process does not include a DECLARE GLOBAL TEMPORARY TABLE statement for the
|
||
|
table name, the database manager assumes that you are not referring to a declared temporary
|
||
|
table. The database manager resolves such table references to a permanent table.</p>
|
||
|
<p><span class="bold">Restrictions on the use of declared temporary tables:</span> </p>
|
||
|
<ul>
|
||
|
<li>Declared temporary tables cannot be specified in an ALTER TABLE,
|
||
|
COMMENT, GRANT, LABEL, LOCK, RENAME, or REVOKE statement.</li>
|
||
|
<li>Declared temporary tables cannot be specified as the parent table in referential
|
||
|
constraints</li>
|
||
|
<li>If a declared temporary table is referenced in a CREATE INDEX or CREATE
|
||
|
VIEW statement, the index or view must be created in SESSION (or library QTEMP).</li></ul>
|
||
|
<p><span class="bold">Syntax alternatives:</span> The following keywords are synonyms
|
||
|
supported for compatibility to prior releases. These keywords are non-standard
|
||
|
and should not be used:</p>
|
||
|
<ul>
|
||
|
<li>DEFINITION ONLY is a synonym for WITH NO DATA</li></ul>
|
||
|
<a name="wq1418"></a>
|
||
|
<h3 id="wq1418"><a href="rbafzmst02.htm#ToC_987">Examples</a></h3>
|
||
|
<p><span class="italic">Example 1:</span> Define a declared temporary table with
|
||
|
column definitions for an employee number, salary, commission, and bonus. </p>
|
||
|
<pre class="xmp"> <span class="bold">DECLARE GLOBAL TEMPORARY TABLE</span> SESSION.TEMP_EMP
|
||
|
<span class="bold">(</span>EMPNO <span class="bold">CHAR(</span>6<span class="bold">) NOT NULL</span>,
|
||
|
SALARY <span class="bold">DECIMAL(</span>9, 2<span class="bold">)</span>,
|
||
|
BONUS <span class="bold">DECIMAL(</span>9, 2<span class="bold">)</span>,
|
||
|
COMM <span class="bold">DECIMAL(</span>9, 2<span class="bold">))</span>
|
||
|
<span class="bold">ON COMMIT PRESERVE ROWS</span></pre>
|
||
|
<p><span class="italic">Example 2:</span> Assume that base table USER1.EMPTAB
|
||
|
exists and that it contains three columns, one of which is an identity column.
|
||
|
Declare a temporary table that has the same column names and attributes (including
|
||
|
identity attributes) as the base table.</p>
|
||
|
<pre class="xmp"> <span class="bold">DECLARE GLOBAL TEMPORARY TABLE</span> TEMPTAB1
|
||
|
<span class="bold">LIKE</span> USER1.EMPTAB
|
||
|
<span class="bold">INCLUDING IDENTITY</span>
|
||
|
<span class="bold">ON COMMIT PRESERVE ROWS</span></pre><p class="indatacontent">In the above example, the database manager uses
|
||
|
SESSION as the implicit qualifier for TEMPTAB1.</p><a id="idx2287" name="idx2287"></a><a id="idx2288" name="idx2288"></a>
|
||
|
<hr /><br />
|
||
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmsth2clcu.htm">Previous Page</a> | <a href="rbafzmstdclpef.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>
|