ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafytfconsider.htm

73 lines
4.9 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Table function considerations" />
<meta name="abstract" content="An external table function is a UDF that delivers a table to the SQL in which it was referenced. A table function reference is only valid in a FROM clause of a SELECT statement." />
<meta name="description" content="An external table function is a UDF that delivers a table to the SQL in which it was referenced. A table function reference is only valid in a FROM clause of a SELECT statement." />
<meta name="DC.subject" content="UDFs (User-defined functions), table function, considerations" />
<meta name="keywords" content="UDFs (User-defined functions), table function, considerations" />
<meta name="DC.Relation" scheme="URI" content="rbafywudfextern.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafytfconsider" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Table function considerations</title>
</head>
<body id="rbafytfconsider"><a name="rbafytfconsider"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Table function considerations</h1>
<div><p><span>An external table function is
a UDF that delivers a table to the SQL in which it was referenced. A table
function reference is only valid in a FROM clause of a SELECT statement.</span></p>
<div class="section"><p>When using table functions, observe the following:</p>
<ul><li>Even though a table function delivers a table, the physical interface
between DB2<sup>®</sup> and
the UDF is one-row-at-a-time. There are five types of calls made to a table
function: OPEN, FETCH, CLOSE, FIRST, and FINAL. The existence of FIRST and
FINAL calls depends on how you define the UDF. The same <em>call-type</em> mechanism
that can be used for scalar functions is used to distinguish these calls.</li>
<li>The standard interface used between DB2 and user-defined scalar functions is
extended to accommodate table functions. The <em>SQL-result</em> argument repeats
for table functions; each instance corresponding to a column to be returned
as defined in the RETURNS TABLE clause of the CREATE FUNCTION statement. The <em>SQL-result-ind</em> argument
likewise repeats, each instance related to the corresponding <em>SQL-result</em> instance.</li>
<li>Not every result column defined in the RETURNS clause of the CREATE FUNCTION
statement for the table function has to be returned. The DBINFO keyword of
CREATE FUNCTION, and corresponding <em>dbinfo</em> argument enable the optimization
that only those columns needed for a particular table function reference need
be returned.</li>
<li>The individual column values returned conform in format to the values
returned by scalar functions.</li>
<li>The CREATE FUNCTION statement for a table function has a CARDINALITY <em>n</em> specification.
This specification enables the definer to inform the DB2 optimizer of the approximate size of
the result so that the optimizer can make better decisions when the function
is referenced. Regardless of what has been specified as the CARDINALITY of
a table function, exercise caution against writing a function with infinite
cardinality; that is, a function that always returns a row on a FETCH call. DB2 expects
the <em>end-of-table</em> condition, as a catalyst within its query processing.
So a table function that never returns the end-of-table condition (SQL-state
value '02000') will cause an infinite processing loop.</li>
</ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafywudfextern.htm" title="You can write the executable code of a UDF in a language other than SQL.">Write UDFs as external functions</a></div>
</div>
</div>
</body>
</html>