934 lines
52 KiB
HTML
934 lines
52 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="CREATE FUNCTION (External Table) statement,
|
||
|
CREATE FUNCTION (External Table), SQL statements, creating, function, external,
|
||
|
data type for CREATE FUNCTION (External 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, in CREATE FUNCTION (External Table), function-name,
|
||
|
AS LOCATOR clause, RETURNS clause, data-type, LANGUAGE clause, DB2GENERAL clause,
|
||
|
DB2SQL clause, SPECIFIC clause, DETERMINISTIC clause, NOT DETERMINISTIC clause,
|
||
|
CONTAINS SQL clause, NO SQL clause, READS SQL DATA clause,
|
||
|
MODIFIES SQL DATA clause, RETURNS NULL ON NULL INPUT clause,
|
||
|
CALLED ON NULL INPUT clause, STATIC DISPATCH clause, DBINFO clause,
|
||
|
NO DBINFO clause, EXTERNAL ACTION clause, NO EXTERNAL ACTION clause,
|
||
|
FENCED clause, NOT FENCED clause, FINAL CALL clause, NO FINAL CALL clause,
|
||
|
DISALLOW PARALLEL clause, SCRATCHPAD clause, NO SCRATCHPAD clause,
|
||
|
EXTERNAL clause, EXTERNAL NAME clause, CARDINALITY clause" />
|
||
|
<title>CREATE FUNCTION (External 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="cftbe"></a>
|
||
|
<h2 id="cftbe"><a href="rbafzmst02.htm#ToC_860">CREATE FUNCTION (External Table)</a></h2><a id="idx1700" name="idx1700"></a><a id="idx1701" name="idx1701"></a><a id="idx1702" name="idx1702"></a><a id="idx1703" name="idx1703"></a><a id="idx1704" name="idx1704"></a><a id="idx1705" name="idx1705"></a>
|
||
|
<p>This CREATE FUNCTION (External Table) statement creates an external table
|
||
|
function at the current server. The function returns a result table.</p>
|
||
|
<p>A <var class="pv">table function</var> may be used in the FROM clause of a SELECT, and
|
||
|
returns a table to the SELECT by returning one row at a time.</p>
|
||
|
<a name="wq1206"></a>
|
||
|
<h3 id="wq1206"><a href="rbafzmst02.htm#ToC_861">Invocation</a></h3>
|
||
|
<p>You can embed this statement in an application program, or you can issue
|
||
|
this statement interactively. It is an executable statement that can be dynamically
|
||
|
prepared.</p>
|
||
|
<a name="wq1207"></a>
|
||
|
<h3 id="wq1207"><a href="rbafzmst02.htm#ToC_862">Authorization</a></h3>
|
||
|
<p>The privileges held by the authorization id of the statement must include
|
||
|
at least one of the following: </p>
|
||
|
<ul>
|
||
|
<li>For the SYSFUNCS catalog view and SYSPARMS catalog table:
|
||
|
|
||
|
<ul>
|
||
|
<li>The INSERT privilege on the table, and</li>
|
||
|
<li>The system authority *EXECUTE on library QSYS2</li></ul></li>
|
||
|
<li>Administrative Authority</li></ul>
|
||
|
<p>If the external program or service program exists, the privileges held
|
||
|
by the authorization ID of the statement must include at least one of the
|
||
|
following: </p>
|
||
|
<ul>
|
||
|
<li>For the external program or service program that is referenced in the
|
||
|
SQL statement:
|
||
|
<ul>
|
||
|
<li>The system authority *EXECUTE on the library that contains the external
|
||
|
program or service program.</li>
|
||
|
<li>The system authority *EXECUTE on the external program or service program,
|
||
|
and</li>
|
||
|
<li>The system authority *CHANGE on the program or service program. The system
|
||
|
needs this authority to update the program object to contain the information
|
||
|
necessary to save/restore the function to another system. If user does not
|
||
|
have this authority, the function is still created, but the program object
|
||
|
is not updated.</li></ul></li>
|
||
|
<li>Administrative Authority</li></ul>
|
||
|
<p>If SQL names are specified and a user profile exists that has the same
|
||
|
name as the library into which the function is created, and that name is different
|
||
|
from the authorization ID of the statement, then the privileges held by the
|
||
|
authorization ID of the statement must include at least one of the following:
|
||
|
</p>
|
||
|
<ul>
|
||
|
<li>The system authority *ADD to the user profile with that name</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="wq1208"></a>
|
||
|
<h3 id="wq1208"><a href="rbafzmst02.htm#ToC_863">Syntax</a></h3>
|
||
|
<a href="rbafzmstcftbe.htm#synscrtfunet"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
||
|
<a name="wq1209"></a>
|
||
|
<div class="fignone" id="wq1209">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn275.htm"
|
||
|
border="0" /></span><a href="#skipsyn-274"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>>>-CREATE FUNCTION--<span class="italic">function-name</span>------------------------------->
|
||
|
|
||
|
>--(--+---------------------------+--)-------------------------->
|
||
|
| .-,---------------------. |
|
||
|
| V | |
|
||
|
'---<span class="italic">parameter-declaration</span>-+-'
|
||
|
|
||
|
.-,---------------------------------------.
|
||
|
V |
|
||
|
>--RETURNS TABLE--(----<span class="italic">column-name</span>--<span class="italic">data-type2</span>--+------------+-+--)-->
|
||
|
'-AS LOCATOR-'
|
||
|
|
||
|
>--<span class="italic">option-list</span>-------------------------------------------------><
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-274" id="skipsyn-274"></a></div>
|
||
|
<a name="wq1210"></a>
|
||
|
<div class="fignone" id="wq1210">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn276.htm"
|
||
|
border="0" /></span><a href="#skipsyn-275"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>parameter-declaration:
|
||
|
|
||
|
|--+----------------+--<span class="italic">data-type1</span>--+------------+---------------|
|
||
|
'-<span class="italic">parameter-name</span>-' '-AS LOCATOR-'
|
||
|
|
||
|
data-type1, data-type2:
|
||
|
|
||
|
|--+-<span class="italic">built-in-type</span>------+---------------------------------------|
|
||
|
'-<span class="italic">distinct-type-name</span>-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-275" id="skipsyn-275"></a></div>
|
||
|
<a name="wq1211"></a>
|
||
|
<div class="fignone" id="wq1211">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn277.htm"
|
||
|
border="0" /></span><a href="#skipsyn-276"><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>-' |
|
||
|
| .-(--53--)------. |
|
||
|
+-+-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------' | +-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>--+---+--)-' +-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------' | |
|
||
|
| | .-(--1M--)-------------. | |
|
||
|
| '---DBCLOB----+----------------------+-' |
|
||
|
| '-(--<span class="italic">integer</span>--+---+--)-' |
|
||
|
| +-K-+ |
|
||
|
| +-M-+ |
|
||
|
| '-G-' |
|
||
|
| .-(--1--)-------. |
|
||
|
+-+-+-BINARY--+---------------+---------+-----------------+---------------------------------+
|
||
|
| | | '-(--<span class="italic">integer</span>--)-' | | |
|
||
|
| | '-+-BINARY VARYING-+--(--<span class="italic">integer</span>--)-' | |
|
||
|
| | '-VARBINARY------' | |
|
||
|
| | .-(--1M--)-------------. | |
|
||
|
| '---+-BLOB----------------+----+----------------------+-' |
|
||
|
| '-BINARY LARGE OBJECT-' '-(--<span class="italic">integer</span>--+---+--)-' |
|
||
|
| +-K-+ |
|
||
|
| +-M-+ |
|
||
|
| '-G-' |
|
||
|
+-+-DATE-------------------+----------------------------------------------------------------+
|
||
|
| | .-(--0--)-. | |
|
||
|
| +-TIME--+---------+------+ |
|
||
|
| | .-(--6--)-. | |
|
||
|
| '-TIMESTAMP--+---------+-' |
|
||
|
'---ROWID-----------------------------------------------------------------------------------'
|
||
|
|
||
|
ccsid-clause:
|
||
|
|
||
|
.-NOT NORMALIZED-.
|
||
|
|--CCSID--<span class="italic">integer</span>--+----------------+---------------------------|
|
||
|
'-NORMALIZED-----'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-276" id="skipsyn-276"></a></div>
|
||
|
<a name="wq1212"></a>
|
||
|
<div class="fignone" id="wq1212">
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn278.htm"
|
||
|
border="0" /></span><a href="#skipsyn-277"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>option-list:
|
||
|
|
||
|
(1)
|
||
|
|--+-----------------------+------------------------------------>
|
||
|
'-LANGUAGE--+-C-------+-'
|
||
|
+-C++-----+
|
||
|
+-CL------+
|
||
|
+-COBOL---+
|
||
|
+-COBOLLE-+
|
||
|
+-FORTRAN-+
|
||
|
+-JAVA----+
|
||
|
+-PLI-----+
|
||
|
+-RPG-----+
|
||
|
'-RPGLE---'
|
||
|
|
||
|
>--+-PARAMETER STYLE DB2SQL-----+------------------------------->
|
||
|
'-PARAMETER STYLE DB2GENERAL-'
|
||
|
|
||
|
.-NOT DETERMINISTIC-.
|
||
|
>--+-------------------------+--+-------------------+----------->
|
||
|
'-SPECIFIC--<span class="italic">specific-name</span>-' '-DETERMINISTIC-----'
|
||
|
|
||
|
.-READS SQL DATA----. .-CALLED ON NULL INPUT-------.
|
||
|
>--+-------------------+--+----------------------------+-------->
|
||
|
+-NO SQL------------+ '-RETURNS NULL ON NULL INPUT-'
|
||
|
+-CONTAINS SQL------+
|
||
|
'-MODIFIES SQL DATA-'
|
||
|
|
||
|
.-STATIC DISPATCH-. .-NO DBINFO-. .-EXTERNAL ACTION----.
|
||
|
>--+-----------------+--+-----------+--+--------------------+--->
|
||
|
'-DBINFO----' '-NO EXTERNAL ACTION-'
|
||
|
|
||
|
.-FENCED-----. .-NO FINAL CALL-.
|
||
|
>--+------------+--+---------------+----DISALLOW PARALLEL------->
|
||
|
'-NOT FENCED-' '-FINAL CALL----'
|
||
|
|
||
|
.-NO SCRATCHPAD-----------.
|
||
|
>--+-------------------------+---------------------------------->
|
||
|
| .-<span class="italic">100</span>-----. |
|
||
|
'-SCRATCHPAD--+---------+-'
|
||
|
'-<span class="italic">integer</span>-'
|
||
|
|
||
|
.-EXTERNAL-----------------------------.
|
||
|
>--+--------------------------------------+--------------------->
|
||
|
'-EXTERNAL NAME--<span class="italic">external-program-name</span>-'
|
||
|
|
||
|
>--+---------------------+--------------------------------------|
|
||
|
'-CARDINALITY--<span class="italic">bigint</span>-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-277" id="skipsyn-277"></a>
|
||
|
<a name="wq1213"></a>
|
||
|
<div class="notelisttitle" id="wq1213">Notes:</div>
|
||
|
<ol type="1">
|
||
|
<li>The optional clauses can be specified in a different order.</li>
|
||
|
</ol></div>
|
||
|
<p><a id="idx1706" name="idx1706"></a><a id="idx1707" name="idx1707"></a><a id="idx1708" name="idx1708"></a><a id="idx1709" name="idx1709"></a><a id="idx1710" name="idx1710"></a><a id="idx1711" name="idx1711"></a><a id="idx1712" name="idx1712"></a><a id="idx1713" name="idx1713"></a><a id="idx1714" name="idx1714"></a><a id="idx1715" name="idx1715"></a><a id="idx1716" name="idx1716"></a><a id="idx1717" name="idx1717"></a><a id="idx1718" name="idx1718"></a><a id="idx1719" name="idx1719"></a><a id="idx1720" name="idx1720"></a><a id="idx1721" name="idx1721"></a><a id="idx1722" name="idx1722"></a><a id="idx1723" name="idx1723"></a><a id="idx1724" name="idx1724"></a><a id="idx1725" name="idx1725"></a><a id="idx1726" name="idx1726"></a><a id="idx1727" name="idx1727"></a><a id="idx1728" name="idx1728"></a></p><a id="idx1729" name="idx1729"></a>
|
||
|
<a name="synscrtfunet"></a>
|
||
|
<h3 id="synscrtfunet"><a href="rbafzmst02.htm#ToC_864">Description</a></h3>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">function-name</var></dt>
|
||
|
<dd>Names the user-defined function. The combination of name, schema name,
|
||
|
the number of parameters, and the data type of each parameter (without regard
|
||
|
for any length, precision, scale, or CCSID attributes of the data type) must
|
||
|
not identify a user-defined function that exists at the current server.
|
||
|
<p>For SQL naming, the function will be created in the schema specified by the
|
||
|
implicit or explicit qualifier.</p>
|
||
|
<p>For system naming, the function will
|
||
|
be created in the schema that is specified by the qualifier. If no qualifier
|
||
|
is specified: </p>
|
||
|
<ul>
|
||
|
<li>If the value of the CURRENT SCHEMA special register is *LIBL, the function
|
||
|
will be created in the current library (*CURLIB).</li>
|
||
|
<li>Otherwise, the function will be created in the current schema.</li></ul>
|
||
|
<p>In general, more than one function can have the same name if the
|
||
|
function signature of each function is unique.</p>
|
||
|
<p>Certain function names
|
||
|
are reserved for system use. For more information see <a href="rbafzmstcreatef.htm#fnamerst">Choosing the Schema and Function Name</a>.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">(<var class="pv">parameter-declaration,...)</var></dt>
|
||
|
<dd>Specifies the number of parameters of the function and the data type
|
||
|
of each parameter. Although not required, you can give each parameter a name.
|
||
|
<p>The maximum number of parameters allowed in CREATE FUNCTION (External Table)
|
||
|
is 90. The maximum number of parameters may be additionally limited by the
|
||
|
maximum number of parameters allowed by the licensed program that is used
|
||
|
to compile the external program.</p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">parameter-name</var></dt>
|
||
|
<dd>Names the parameter. Although not required, a parameter name
|
||
|
can be specified for each parameter. The name cannot be the same as any other <var class="pv">parameter-name</var> in the parameter list.
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">data-type1</var></dt>
|
||
|
<dd>Specifies the data type of the input parameter. The data
|
||
|
type can be a built-in data type or a distinct type.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">built-in-type</var></dt>
|
||
|
<dd>Specifies a built-in data type. For a more complete description of each
|
||
|
built-in data type, see <a href="rbafzmsthctabl.htm#hctabl">CREATE TABLE</a>. Some data types are not supported
|
||
|
in all languages. For details on the mapping between the SQL data types and
|
||
|
host language data types, see <a href="../rzajp/rzajpkickoff.htm">Embedded SQL Programming</a> book. Built-in data type specifications can be specified if they correspond
|
||
|
to the language that is used to write the user-defined function.
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">distinct-type-name</var></dt>
|
||
|
<dd>Specifies a user-defined distinct type. The length, precision, or scale
|
||
|
attributes for the parameter are those of the source type of the distinct
|
||
|
type (those specified on CREATE DISTINCT TYPE). For more information on creating
|
||
|
a distinct type, see <a href="rbafzmstcrtudt.htm#crtudt">CREATE DISTINCT TYPE</a>.
|
||
|
<p>If the name of the distinct type is
|
||
|
unqualified, the database manager resolves the schema name by searching the
|
||
|
schemas in the SQL path.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>Parameters with a large object (LOB) data type are not supported
|
||
|
when PARAMETER STYLE JAVA is specified.</p>
|
||
|
<p>If a CCSID is specified, the
|
||
|
parameter will be converted to that CCSID prior to passing it to the function.
|
||
|
If a CCSID is not specified, the CCSID is determined by the default CCSID
|
||
|
at the current server at the time the function is invoked.</p>
|
||
|
</dd><a id="idx1730" name="idx1730"></a>
|
||
|
<dt class="bold">AS LOCATOR</dt>
|
||
|
<dd>Specifies that the input parameter is a locator to the value rather
|
||
|
than the actual value. You can specify AS LOCATOR only if the input parameter
|
||
|
has a LOB data type or a distinct type based on a LOB data type. If AS LOCATOR
|
||
|
is specified, FOR SBCS DATA or FOR MIXED DATA must not be specified.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd><a id="idx1731" name="idx1731"></a>
|
||
|
<dt class="bold">RETURNS TABLE</dt>
|
||
|
<dd>Specifies the output table of the function.
|
||
|
<p>Assume the number of parameters
|
||
|
is N. For PARAMETER STYLE DB2GENERAL, there must be no more than (255-(N*2))/2
|
||
|
columns. For PARAMETER STYLE DB2SQL, there must be no more than (247-(N*2))/2
|
||
|
columns.</p><a id="idx1732" name="idx1732"></a><a id="idx1733" name="idx1733"></a>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><var class="pv">column-name</var></dt>
|
||
|
<dd>Specifies the name of a column of the output table. Do not specify the
|
||
|
same name more than once.
|
||
|
</dd>
|
||
|
<dt class="bold"><var class="pv">data-type2</var> </dt>
|
||
|
<dd>Specifies the data type and attributes of the output.
|
||
|
|
||
|
<p>You can specify any built-in data type (except LONG VARCHAR, LONG VARGRAPHIC,
|
||
|
or DataLink) or a distinct type (that is not based on a DataLink).</p>
|
||
|
<p>If a DATE or TIME is specified, the table function must return the date or
|
||
|
time in ISO format.</p>
|
||
|
<p>If a CCSID is specified, </p>
|
||
|
<ul>
|
||
|
<li>If AS LOCATOR is not specified, the result returned is assumed to be encoded
|
||
|
in that CCSID.</li>
|
||
|
<li>If AS LOCATOR is specified and the CCSID of the data the locator points
|
||
|
to is encoded in a different CCSID, the data is converted to the specified
|
||
|
CCSID.</li></ul><p class="indatacontent"> If a CCSID is not specified, </p>
|
||
|
<ul>
|
||
|
<li>If AS LOCATOR is not specified, the result returned is assumed to be encoded
|
||
|
in the CCSID of the job (or associated graphic CCSID of the job for graphic
|
||
|
string return values).</li>
|
||
|
<li>If AS LOCATOR is specified, the data the locator points to is converted
|
||
|
to the CCSID of the job, if the CCSID of the data the locator points to is
|
||
|
encoded in a different CCSID. To avoid any potential loss of characters during
|
||
|
the conversion, consider explicitly specifying a CCSID that can represent
|
||
|
any characters that will be returned from the function. This is especially
|
||
|
important if the data type is graphic string data. In this case, consider
|
||
|
using CCSID 1200 or 13488 (UTF-16 or UCS-2 graphic string data).</li></ul>
|
||
|
<dl class="parml"><a id="idx1734" name="idx1734"></a>
|
||
|
<dt class="bold">AS LOCATOR</dt>
|
||
|
<dd>Specifies that the function returns a locator to the value for the column
|
||
|
rather than the actual value. You can specify AS LOCATOR only for a LOB data
|
||
|
type or a distinct type based on a LOB data type. If AS LOCATOR is specified,
|
||
|
FOR SBCS DATA or FOR MIXED DATA must not be specified.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd><a id="idx1735" name="idx1735"></a>
|
||
|
<dt class="bold">LANGUAGE (language clause)</dt>
|
||
|
<dd>The language clause specifies the language of the external program.
|
||
|
|
||
|
<p>If LANGUAGE is not specified, the LANGUAGE is determined from the program
|
||
|
attribute information associated with the external program at the time the
|
||
|
function is created. The language of the program is assumed to be C if:</p>
|
||
|
<ul>
|
||
|
<li>The program attribute information associated with the program does not
|
||
|
identify a recognizable language</li>
|
||
|
<li>The program cannot be found</li></ul>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">C </dt>
|
||
|
<dd>The external program is written in C.
|
||
|
</dd>
|
||
|
<dt class="bold">C++</dt>
|
||
|
<dd>The external program is written in C++.
|
||
|
</dd>
|
||
|
<dt class="bold">CL </dt>
|
||
|
<dd>The external program is written in CL or ILE CL.
|
||
|
</dd>
|
||
|
<dt class="bold">COBOL</dt>
|
||
|
<dd>The external program is written in COBOL.
|
||
|
</dd>
|
||
|
<dt class="bold">COBOLLE</dt>
|
||
|
<dd>The external program is written in ILE COBOL.
|
||
|
</dd>
|
||
|
<dt class="bold">FORTRAN </dt>
|
||
|
<dd>The external program is written in FORTRAN.
|
||
|
</dd>
|
||
|
<dt class="bold">JAVA</dt>
|
||
|
<dd>The external program is written in JAVA. The database manager will call
|
||
|
the user-defined function as a method in a Java™ class.
|
||
|
</dd>
|
||
|
<dt class="bold">PLI</dt>
|
||
|
<dd>The external program is written in PL/I.
|
||
|
</dd>
|
||
|
<dt class="bold">RPG </dt>
|
||
|
<dd>The external program is written in RPG.
|
||
|
</dd>
|
||
|
<dt class="bold">RPGLE </dt>
|
||
|
<dd>The external program is written in ILE RPG.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">PARAMETER STYLE</dt>
|
||
|
<dd>Specifies the conventions used for passing parameters to and returning
|
||
|
the values from functions:
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">DB2GENERAL</dt><a id="idx1736" name="idx1736"></a>
|
||
|
<dd>This parameter style is used to specify the conventions for passing
|
||
|
parameters to and returning the value from external functions that are defined
|
||
|
as a method in a Java class. All applicable parameters are passed.
|
||
|
The parameters are defined to be in the following order:
|
||
|
|
||
|
<ul>
|
||
|
<li>The first N parameters are the input parameters that are specified on
|
||
|
the CREATE FUNCTION statement.</li>
|
||
|
<li>The next M parameters are the result columns of the function that are
|
||
|
specified on the RETURNS TABLE clause.</li></ul>
|
||
|
<p>DB2GENERAL is only allowed when the LANGUAGE is JAVA.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">DB2SQL</dt><a id="idx1737" name="idx1737"></a>
|
||
|
<dd>All applicable parameters are passed. The parameters are defined to
|
||
|
be in the following order:
|
||
|
<ul>
|
||
|
<li>The first N parameters are the input parameters that are specified on
|
||
|
the CREATE FUNCTION statement.</li>
|
||
|
<li>The next M parameters are the result columns of the function that are
|
||
|
specified on the RETURNS TABLE clause.</li>
|
||
|
<li>N parameters for indicator variables for the input parameters.</li>
|
||
|
<li>M parameters for the indicator variables of the result columns of the
|
||
|
function that are specified on the RETURNS TABLE clause</li>
|
||
|
<li>A CHAR(5) output parameter for SQLSTATE. The SQLSTATE returned indicates
|
||
|
the success or failure of the function. The SQLSTATE returned either be:
|
||
|
<ul>
|
||
|
<li>the SQLSTATE from the last SQL statement executed in the external program,</li>
|
||
|
<li>an SQLSTATE that is assigned by the external program.
|
||
|
<p>The user may
|
||
|
set the SQLSTATE to any valid value in the external program to return an error
|
||
|
or warning from the function.</p></li></ul></li>
|
||
|
<li>A VARCHAR(517) input parameter for the fully qualified function name.</li>
|
||
|
<li>A VARCHAR(128) input parameter for the specific name.</li>
|
||
|
<li>A VARCHAR(70) output parameter for the message text.</li>
|
||
|
<li>A structure (consisting of an INTEGER followed by a CHAR(n)) input and
|
||
|
output parameter for the scratchpad, if SCRATCH PAD was specified on the CREATE
|
||
|
FUNCTION statement.</li>
|
||
|
<li>An INTEGER input parameter for the call type.</li>
|
||
|
<li>A structure for the dbinfo structure, if DBINFO was specified on the CREATE
|
||
|
FUNCTION statement.</li></ul>For more information about the parameters passed, see the include <span>sqludf</span> in the appropriate source file in library QSYSINC.
|
||
|
For example, for C, sqludf can be found in QSYSINC/H.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>Note that the language of the external function determines how
|
||
|
the parameters are passed. For example, in C, any VARCHAR or CHAR parameters
|
||
|
are passed as NUL-terminated strings. For more information, see the <a href="../sqlp/rbafykickoff.htm">SQL Programming</a> book. For Java routines, see the <a href="../rzaha/whatitis.htm">IBM® Developer
|
||
|
Kit for Java</a>.</p>
|
||
|
</dd><a id="idx1738" name="idx1738"></a>
|
||
|
<dt class="bold">SPECIFIC <var class="pv">specific-name</var></dt>
|
||
|
<dd>Provides a unique name for the function. The name is implicitly or explicitly
|
||
|
qualified with a schema name. The name, including the schema name, must not
|
||
|
identify the specific name of another function or procedure that exists at
|
||
|
the current server. If unqualified, the implicit qualifier is the same as
|
||
|
the qualifier of the function name. If qualified, the qualifier must be the
|
||
|
same as the qualifier of the function name.
|
||
|
<p>If specific name is not specified,
|
||
|
it is set to the function name. If a function or procedure with that specific
|
||
|
name already exists, a unique name is generated similar to the rules used
|
||
|
to generate unique table names.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">DETERMINISTIC <span class="base">or</span> NOT DETERMINISTIC</dt><a id="idx1739" name="idx1739"></a><a id="idx1740" name="idx1740"></a>
|
||
|
<dd>Specifies whether the function is deterministic.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">NOT DETERMINISTIC</dt>
|
||
|
<dd>Specifies that the function will not always return the same result from
|
||
|
successive function invocations with identical input arguments. NOT DETERMINISTIC
|
||
|
should be specified if the function contains a reference to a special register,
|
||
|
a non-deterministic function, or a sequence.
|
||
|
</dd>
|
||
|
<dt class="bold">DETERMINISTIC</dt>
|
||
|
<dd>Specifies that the function will always return the same result from
|
||
|
successive invocations with identical input arguments.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">CONTAINS SQL, READS SQL DATA, MODIFIES SQL DATA, <span class="base">or</span> NO SQL</dt>
|
||
|
<dd>Specifies whether the function can execute any SQL statements and, if
|
||
|
so, what type. The database manager verifies that the SQL issued by the function is
|
||
|
consistent with this specification. See <a href="rbafzmstdiftab.htm#diftab">Appendix B. Characteristics of SQL statements</a> for a detailed
|
||
|
list of the SQL statements that can be executed under each data access indication.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">CONTAINS SQL</dt><a id="idx1741" name="idx1741"></a>
|
||
|
<dd>The function does not execute SQL statements that read or modify data.
|
||
|
</dd>
|
||
|
<dt class="bold">NO SQL</dt><a id="idx1742" name="idx1742"></a>
|
||
|
<dd>The function does not execute SQL statements.
|
||
|
</dd>
|
||
|
<dt class="bold">READS SQL DATA</dt><a id="idx1743" name="idx1743"></a>
|
||
|
<dd>The function does not execute SQL statements that modify data.
|
||
|
</dd>
|
||
|
<dt class="bold">MODIFIES SQL DATA</dt><a id="idx1744" name="idx1744"></a>
|
||
|
<dd>The function can execute any SQL statement except those statements that
|
||
|
are not supported in any function.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">RETURNS NULL ON NULL INPUT <span class="base">or</span> CALLED ON
|
||
|
NULL INPUT</dt><a id="idx1745" name="idx1745"></a><a id="idx1746" name="idx1746"></a>
|
||
|
<dd>Specifies whether the function is called if any of the input arguments
|
||
|
is null at execution time.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">RETURNS NULL ON INPUT</dt>
|
||
|
<dd>Specifies that the function is not invoked if any of the input arguments
|
||
|
is null. The result is the null value.
|
||
|
</dd>
|
||
|
<dt class="bold">CALLED ON NULL INPUT</dt>
|
||
|
<dd>Specifies that the function is to be invoked, if any, or all, argument
|
||
|
values are null, making the function responsible for testing for null argument
|
||
|
values. The function can return a null or nonnull value.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">STATIC DISPATCH</dt><a id="idx1747" name="idx1747"></a>
|
||
|
<dd>Specifies that the function is dispatched statically. All functions
|
||
|
are statically dispatched.
|
||
|
</dd>
|
||
|
<dt class="bold">DBINFO</dt><a id="idx1748" name="idx1748"></a><a id="idx1749" name="idx1749"></a>
|
||
|
<dd>Specifies whether or not the function requires the database information
|
||
|
be passed.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">DBINFO</dt>
|
||
|
<dd>Specifies that the database manager should pass a structure containing
|
||
|
status information to the function. <a href="rbafzmstcftbe.htm#dbinfotbt">Table 50</a> contains a description
|
||
|
of the DBINFO structure. Detailed information about the DBINFO structure can
|
||
|
be found in <span>sqludf</span> in the appropriate source file
|
||
|
in library QSYSINC. For example, for C, sqludf can be found in QSYSINC/H.
|
||
|
<a name="dbinfotbt"></a>
|
||
|
<table id="dbinfotbt" width="100%" summary="" border="1" frame="border" rules="all">
|
||
|
<caption>Table 50. DBINFO fields</caption>
|
||
|
<thead valign="bottom">
|
||
|
<tr>
|
||
|
<th id="wq1215" width="21%" align="left" valign="bottom">Field</th>
|
||
|
<th id="wq1216" width="15%" align="left" valign="bottom">Data Type</th>
|
||
|
<th id="wq1217" width="62%" align="left" valign="bottom">Description</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody valign="top">
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Relational database</td>
|
||
|
<td align="left" valign="top" headers="wq1216">VARCHAR(128)</td>
|
||
|
<td align="left" valign="top" headers="wq1217">The name of the current server.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Authorization ID</td>
|
||
|
<td align="left" valign="top" headers="wq1216">VARCHAR(128)</td>
|
||
|
<td align="left" valign="top" headers="wq1217">The run-time authorization ID.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">CCSID Information</td>
|
||
|
<td align="left" valign="top" headers="wq1216">
|
||
|
<div class="lines">INTEGER<br />
|
||
|
INTEGER<br />
|
||
|
INTEGER<br />
|
||
|
</div>
|
||
|
<div class="lines"> <br />
|
||
|
</div>
|
||
|
<div class="lines">INTEGER<br />
|
||
|
INTEGER<br />
|
||
|
INTEGER<br />
|
||
|
</div>
|
||
|
<div class="lines"> <br />
|
||
|
</div>
|
||
|
<div class="lines">INTEGER<br />
|
||
|
INTEGER<br />
|
||
|
INTEGER<br />
|
||
|
</div>
|
||
|
<div class="lines"> <br />
|
||
|
</div>
|
||
|
<div class="lines">INTEGER<br />
|
||
|
</div>
|
||
|
<div class="lines"> <br />
|
||
|
</div>
|
||
|
<div class="lines">CHAR(8)<br />
|
||
|
</div></td>
|
||
|
<td align="left" valign="top" headers="wq1217">The CCSID information of the job. Three sets
|
||
|
of three CCSIDs are returned. The following information identifies the three
|
||
|
CCSIDs in each set:
|
||
|
<ul>
|
||
|
<li>SBCS CCSID</li>
|
||
|
<li>DBCS CCSID</li>
|
||
|
<li>Mixed CCSID</li></ul>Following the three sets of CCSIDs is an integer that indicates which
|
||
|
set of three sets of CCSIDs is applicable and eight bytes of reserved space.
|
||
|
<p>If a CCSID is not explicitly specified for a parameter on the CREATE FUNCTION
|
||
|
statement, the input string is assumed to be encoded in the CCSID of the job
|
||
|
at the time the function is executed. If the CCSID of the input string is
|
||
|
not the same as the CCSID of the parameter, the input string passed to the
|
||
|
external function will be converted before calling the external program.</p></td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Target column</td>
|
||
|
<td align="left" valign="top" headers="wq1216">VARCHAR(128)
|
||
|
<div class="lines">VARCHAR(128)<br />
|
||
|
</div>
|
||
|
<div class="lines">VARCHAR(128)<br />
|
||
|
</div></td>
|
||
|
<td align="left" valign="top" headers="wq1217">If a user-defined function is specified on
|
||
|
the right-hand side of a SET clause in an UPDATE statement, the following
|
||
|
information identifies the target column:
|
||
|
<ul>
|
||
|
<li>Schema name</li>
|
||
|
<li>Base table name</li>
|
||
|
<li>Column name</li></ul>If the user-defined function is not on the right-hand side of a SET clause
|
||
|
in an UPDATE statement, these fields are blank.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Version and release</td>
|
||
|
<td align="left" valign="top" headers="wq1216">CHAR(8)</td>
|
||
|
<td align="left" valign="top" headers="wq1217">The version, release, and modification level
|
||
|
of the database manager.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Platform</td>
|
||
|
<td align="left" valign="top" headers="wq1216">INTEGER</td>
|
||
|
<td align="left" valign="top" headers="wq1217">The server's platform type.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Number of table function column list entries</td>
|
||
|
<td align="left" valign="top" headers="wq1216">SMALLINT</td>
|
||
|
<td align="left" valign="top" headers="wq1217">The number of non-zero entries in the table
|
||
|
function column list specified in the "Table function column
|
||
|
list" field below.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Reserved</td>
|
||
|
<td align="left" valign="top" headers="wq1216">CHAR(24)</td>
|
||
|
<td align="left" valign="top" headers="wq1217">Reserved for future use.</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="left" valign="top" headers="wq1215">Table function column list</td>
|
||
|
<td align="left" valign="top" headers="wq1216">Pointer (16 Bytes)</td>
|
||
|
<td align="left" valign="top" headers="wq1217">This field is a pointer to an array of short
|
||
|
integers which is dynamically allocated by the database manager. Only the first n entries,
|
||
|
where n is specified in the "Number of table function column list entries"
|
||
|
field, are of interest, n may be equal to 0, and is less than or equal to
|
||
|
the number of result columns defined for the function in the RETURNS TABLE
|
||
|
clause. The values correspond to the ordinal numbers of the columns which
|
||
|
this statement needs from the table function. A value of 1 means the first
|
||
|
defined result column, 2 means the second defined result column, and so on.
|
||
|
The values may be in any order. Note that n could be equal to zero for a statement
|
||
|
that is similar to SELECT COUNT(*) FROM TABLE(TF(...)) AS QQ, where no actual
|
||
|
column values are needed by the query.
|
||
|
<p>This array represents an opportunity
|
||
|
for optimization. The function need not return all values for all the result
|
||
|
columns of the table function. Only a subset of the values may be needed in
|
||
|
a particular context, and these are the columns identified (by number) in
|
||
|
the array. Since this optimization may complicate the function logic, the
|
||
|
function can choose to return every defined column.</p></td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</dd>
|
||
|
<dt class="bold">NO DBINFO</dt>
|
||
|
<dd>Specifies that the function does not require the database information
|
||
|
to be passed.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">EXTERNAL ACTION <span class="base">or</span> NO EXTERNAL ACTION</dt><a id="idx1750" name="idx1750"></a><a id="idx1751" name="idx1751"></a>
|
||
|
<dd>Specifies whether the function contains an external action.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">EXTERNAL ACTION</dt>
|
||
|
<dd>The function performs some external action (outside the scope of the
|
||
|
function program). Thus, the function must be invoked with each successive
|
||
|
function invocation. EXTERNAL ACTION should be specified if the function contains
|
||
|
a reference to another function that has an external action.
|
||
|
</dd>
|
||
|
<dt class="bold">NO EXTERNAL ACTION</dt>
|
||
|
<dd>The function does not perform an external action. It need not be called
|
||
|
with each successive function invocation.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">FENCED <span class="base">or</span> NOT FENCED</dt><a id="idx1752" name="idx1752"></a><a id="idx1753" name="idx1753"></a>
|
||
|
<dd>Specifies whether the external function runs in an environment that
|
||
|
is isolated from the database manager environment.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">FENCED</dt>
|
||
|
<dd>The function will run in a separate thread.
|
||
|
<p>FENCED functions cannot
|
||
|
keep SQL cursors open across individual calls to the function. However, the
|
||
|
cursors in one thread are independent of the cursors in any other threads
|
||
|
which reduces the possibility of cursor name conflicts.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">NOT FENCED</dt>
|
||
|
<dd>The function may run in the same thread as the invoking SQL statement.
|
||
|
<p>NOT FENCED functions can keep SQL cursors open across individual calls to
|
||
|
the function. Since cursors can be kept open, the cursor position will also
|
||
|
be preserved between calls to the function. However, cursor names may conflict
|
||
|
since the UDF is now running in the same thread as the invoking SQL statement
|
||
|
and other NOT FENCED UDFs.</p>
|
||
|
<p>NOT FENCED functions usually perform better
|
||
|
than FENCED functions.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">FINAL CALL</dt><a id="idx1754" name="idx1754"></a><a id="idx1755" name="idx1755"></a>
|
||
|
<dd> Specifies whether the function requires a final call (and a separate
|
||
|
first call). For table functions, the call-type argument is ALWAYS present,
|
||
|
regardless of which FINAL CALL option is chosen. The call-type argument indicates
|
||
|
first call, open call, fetch call, close call, or final call.
|
||
|
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">FINAL CALL</dt>
|
||
|
<dd>Specifies that the function requires a final call (and a separate first
|
||
|
call). It also controls when the scratchpad is re-initialized. If NO FINAL
|
||
|
CALL is specified, then the database manager can only make three types of calls to the
|
||
|
table function: open, fetch and close. However, if FINAL CALL is specified,
|
||
|
then in addition to open, fetch and close, a first call and a final call can
|
||
|
be made to the table function.Specifies that a final call is made to the function.
|
||
|
To differentiate between final calls and other calls, the function receives
|
||
|
an additional argument that specifies the type of call.
|
||
|
<p>The types of calls
|
||
|
are:</p>
|
||
|
<dl>
|
||
|
<dt class="bold">First Call</dt>
|
||
|
<dd>Specifies the first call to the function for this reference to the function
|
||
|
in this SQL statement.
|
||
|
</dd>
|
||
|
<dt class="bold">Open Call</dt>
|
||
|
<dd>Specifies a call to open the table function result in this SQL statement.
|
||
|
</dd>
|
||
|
<dt class="bold">Fetch Call</dt>
|
||
|
<dd>Specifies a call to fetch a row from the table function in this SQL
|
||
|
statement.
|
||
|
</dd>
|
||
|
<dt class="bold">Close Call</dt>
|
||
|
<dd>Specifies a call to close the table function result in this SQL statement.
|
||
|
</dd>
|
||
|
<dt class="bold">Final Call</dt>
|
||
|
<dd>Specifies the last call to the function to enable the function to free
|
||
|
resources. If an error occurs, the database manager attempts to make the final
|
||
|
call.
|
||
|
<p>A final call occurs at these times:</p>
|
||
|
<ul>
|
||
|
<li><span class="italic">End of statement:</span> When the cursor is closed for
|
||
|
cursor-oriented statements, or the execution of the statement has completed.</li>
|
||
|
<li><span class="italic">End of transaction:</span> When normal end of statement
|
||
|
processing does not occur. For example, the logic of an application, for some
|
||
|
reason, bypasses closing the cursor.</li></ul>
|
||
|
<p>If a commit operation occurs while a cursor defined as WITH HOLD
|
||
|
is open, a final call is made when the cursor is closed or the application
|
||
|
ends.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>Commitable operations should not be performed during a FINAL CALL,
|
||
|
because the FINAL CALL may occur during a close invoked as part of a COMMIT
|
||
|
operation.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">NO FINAL CALL</dt>
|
||
|
<dd>Specifies that the function does not require a final call (and a separate
|
||
|
first call). However the open, fetch, and close calls are still made.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">DISALLOW PARALLEL</dt><a id="idx1756" name="idx1756"></a>
|
||
|
<dd>Specifies that the function cannot be run in parallel. Table functions
|
||
|
cannot run in parallel.
|
||
|
</dd>
|
||
|
<dt class="bold">SCRATCHPAD</dt><a id="idx1757" name="idx1757"></a><a id="idx1758" name="idx1758"></a>
|
||
|
<dd>Specifies whether the function requires a static memory area.
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"> SCRATCHPAD <var class="pv">integer</var></dt>
|
||
|
<dd>Specifies that the function requires a persistent memory area of length
|
||
|
integer. The integer can range from 1 to 16,000,000. If the memory area is
|
||
|
not specified, the size of the area is 100 bytes. If parameter style DB2SQL
|
||
|
is specified, a pointer is passed following the required parameters that points
|
||
|
to a static storage area. Only 1 memory area will be allocated for the function.
|
||
|
<p>The scope of a scratchpad is the SQL statement. For each reference to the
|
||
|
function in an SQL statement, there is one scratchpad. For example, assuming
|
||
|
that function UDFX was defined with the SCRATCHPAD keyword, two scratchpads
|
||
|
are allocated for the two references to UDFX in the following SQL statement:</p>
|
||
|
<pre class="xmp"><span class="bold">SELECT</span> A.C1, B.C1
|
||
|
<span class="bold">FROM TABLE(</span>UDFX<span class="bold">(</span>:hv1<span class="bold">)) AS </span>A, <span class="bold">TABLE(</span>UDFX<span class="bold">(</span>:hv1<span class="bold">)) AS</span> B </pre>
|
||
|
</dd>
|
||
|
<dt class="bold"> NO SCRATCHPAD</dt>
|
||
|
<dd>Specifies that the function does not require a persistent memory area.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
</dd>
|
||
|
<dt class="bold">EXTERNAL NAME <var class="pv">external-program-name</var></dt><a id="idx1759" name="idx1759"></a><a id="idx1760" name="idx1760"></a>
|
||
|
<dd>Specifies the program, service program, or java class that will be executed
|
||
|
when the function is invoked in an SQL statement. The name must identify a
|
||
|
program, service program, or java class that exists at the application server at the
|
||
|
time the function is invoked. If the naming option is *SYS and the name is
|
||
|
not qualified:
|
||
|
<ul>
|
||
|
<li>The current path will be used to search for the program or service program
|
||
|
at the time the function is invoked.</li>
|
||
|
<li>*LIBL will be used to search for the program or service program at the
|
||
|
time grants or revokes are performed on the function.</li></ul>
|
||
|
<p>The validity of the name is checked at the application server. If the format
|
||
|
of the name is not correct, an error is returned.</p>
|
||
|
<p>If external-program-name
|
||
|
is not specified, the external program name is assumed to be the same as the
|
||
|
function name.</p>
|
||
|
<p>The program, service program, or java class need not
|
||
|
exist at the time the function is created, but it must exist at the time the
|
||
|
function is invoked.</p>
|
||
|
<p>A CONNECT, SET CONNECTION, RELEASE, DISCONNECT,
|
||
|
COMMIT, ROLLBACK and SET TRANSACTION statement is not allowed in the external
|
||
|
program of the function.</p>
|
||
|
</dd>
|
||
|
<dt class="bold">CARDINALITY <var class="pv">bigint</var></dt><a id="idx1761" name="idx1761"></a>
|
||
|
<dd>Specifies an estimate of the expected number of rows to be
|
||
|
returned by the function for the database manager to use during optimization. <var class="pv">bigint</var> must be in the range from 0 to 9 223 372 036 854 775
|
||
|
807 inclusive. The database manager assumes a finite value if CARDINALITY
|
||
|
is not specified.
|
||
|
<p>A table function that returns a row every time it is called
|
||
|
and never returns the end-of-table condition has infinite cardinality. A query
|
||
|
that invokes such a function and requires an eventual end-of-table condition
|
||
|
before it can return any data will not return unless interrupted. Table functions
|
||
|
that never return the end-of-table condition should not be used in queries
|
||
|
involving DISTINCT, GROUP BY, or ORDER BY.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1218"></a>
|
||
|
<h3 id="wq1218"><a href="rbafzmst02.htm#ToC_865">Notes</a></h3>
|
||
|
<p><span class="bold">General considerations for defining user-defined functions:</span> See <a href="rbafzmstcreatef.htm#createf">CREATE FUNCTION</a> for general information on defining user-defined
|
||
|
functions.</p>
|
||
|
<p><span class="bold">Creating the function:</span> When an external function
|
||
|
associated with an ILE external program or service program is created, an
|
||
|
attempt is made to save the function's attributes in the associated program
|
||
|
or service program object. If the *PGM or *SRVPGM object is saved and then
|
||
|
restored to this or another system, the catalogs are automatically updated
|
||
|
with those attributes.</p>
|
||
|
<p>The attributes can be saved for external functions subject to the following
|
||
|
restrictions:</p>
|
||
|
<ul>
|
||
|
<li>The external program library must not be SYSIBM, QSYS, or QSYS2.</li>
|
||
|
<li>The external program must exist when the CREATE FUNCTION statement is
|
||
|
issued.</li>
|
||
|
<li>The external program must be an ILE *PGM or *SRVPGM object.</li></ul><p class="indatacontent">If the object cannot be updated, the function will still be created.</p>
|
||
|
<p>During restore of the function:</p>
|
||
|
<ul>
|
||
|
<li>If the specific name was specified when the function was originally created
|
||
|
and it is not unique, an error is issued.</li>
|
||
|
<li>If the specific name was not specified, a unique name is generated if
|
||
|
necessary.</li>
|
||
|
<li>If the same function signature already exists in the catalog:
|
||
|
<ul>
|
||
|
<li>If the external program or service program name is the same as the one
|
||
|
registered in the catalog, the function information in the catalog will be
|
||
|
replaced.</li>
|
||
|
<li>Otherwise, the function cannot be registered, and an error is issued.</li></ul></li></ul>
|
||
|
<p><span class="bold">Invoking the function:</span> When an external function
|
||
|
is invoked, it runs in whatever activation group was specified when the external
|
||
|
program or service program was created. However, ACTGRP(*CALLER) should normally
|
||
|
be used so that the function runs in the same activation group as the calling
|
||
|
program. ACTGRP(*NEW) is not allowed.</p>
|
||
|
<p><span class="bold">Notes for Java functions:</span> To be able to run Java functions, you must have the IBM Developer Kit for Java (5722-JV1) installed on your system.
|
||
|
Otherwise, an SQLCODE of -443 will be returned and a CPDB521 message will
|
||
|
be placed in the job log.</p>
|
||
|
<p>If an error occurs while running a Java procedure, an SQLCODE of -443 will
|
||
|
be returned. Depending on the error, other messages may exist in the job log
|
||
|
of the job where the procedure was run.</p>
|
||
|
<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>The keywords VARIANT and NOT VARIANT can be used as synonyms for NOT DETERMINISTIC
|
||
|
and DETERMINISTIC.</li>
|
||
|
<li>The keywords NULL CALL and NOT NULL CALL can be used as synonyms for CALLED
|
||
|
ON NULL INPUT and RETURNS NULL ON NULL INPUT.</li>
|
||
|
<li>The value DB2GENRL may be used as a synonym for DB2GENERAL.</li>
|
||
|
<li>The keywords PARAMETER STYLE in the PARAMETER STYLE clause are optional.</li>
|
||
|
<li>The keywords IS DETERMINISTIC may be used as a synonym for DETERMINISTIC.</li></ul>
|
||
|
<a name="wq1219"></a>
|
||
|
<h3 id="wq1219"><a href="rbafzmst02.htm#ToC_866">Example</a></h3>
|
||
|
<p>The following creates a table function written to return a row consisting
|
||
|
of a single document identifier column for each known document in a text management
|
||
|
system. The first parameter matches a given subject area and the second parameter
|
||
|
contains a given string.</p>
|
||
|
<p>Within the context of a single session, the UDF will always return the
|
||
|
same table, and therefore it is defined as DETERMINISTIC. Note the RETURNS
|
||
|
clause which defines the output from DOCMATCH. FINAL CALL must be specified
|
||
|
for each table function. In addition, the DISALLOW PARALLEL keyword is added
|
||
|
as table functions cannot operate in parallel. Although the size of the output
|
||
|
for DOCMATCH is highly variable, CARDINALITY 20 is a representative value,
|
||
|
and is specified to help the optimizer.</p>
|
||
|
<pre class="xmp"><span class="bold">CREATE FUNCTION</span> DOCMATCH <span class="bold">(VARCHAR(</span>30<span class="bold">)</span>, <span class="bold">VARCHAR(</span>255<span class="bold">))</span>
|
||
|
<span class="bold">RETURNS TABLE (</span>DOCID <span class="bold">CHAR(</span>16<span class="bold">))</span>
|
||
|
<span class="bold">EXTERNAL NAME</span> 'MYLIB/RAJIV(UDFMATCH)'
|
||
|
<span class="bold">LANGUAGE C</span>
|
||
|
<span class="bold">PARAMETER STYLE DB2SQL</span>
|
||
|
<span class="bold">NO SQL</span>
|
||
|
<span class="bold">DETERMINISTIC</span>
|
||
|
<span class="bold">NO EXTERNAL ACTION</span>
|
||
|
<span class="bold">NOT FENCED</span>
|
||
|
<span class="bold">SCRATCHPAD</span>
|
||
|
<span class="bold">FINAL CALL</span>
|
||
|
<span class="bold">DISALLOW PARALLEL</span>
|
||
|
<span class="bold">CARDINALITY</span> 20</pre>
|
||
|
<hr /><br />
|
||
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstcfsce.htm">Previous Page</a> | <a href="rbafzmstcfso.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>
|