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

80 lines
5.1 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="Example: Table function returning document IDs" />
<meta name="abstract" content="In this example, you have written a table function that returns a row consisting of a single document identifier column for each known document in your text management system that matches a given subject area (the first parameter) and contains the given string (second parameter)." />
<meta name="description" content="In this example, you have written a table function that returns a row consisting of a single document identifier column for each known document in your text management system that matches a given subject area (the first parameter) and contains the given string (second parameter)." />
<meta name="DC.subject" content="examples, returning a table function, UDFs (User-defined functions), table function example, CREATE FUNCTION statement" />
<meta name="keywords" content="examples, returning a table function, UDFs (User-defined functions), table function example, CREATE FUNCTION statement" />
<meta name="DC.Relation" scheme="URI" content="rbafyudfdudf.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="rbafyudfcfx7" />
<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>Example: Table function returning document IDs</title>
</head>
<body id="rbafyudfcfx7"><a name="rbafyudfcfx7"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Table function returning document IDs</h1>
<div><p>In this example, you have written a table function that returns
a row consisting of a single document identifier column for each known document
in your text management system that matches a given subject area (the first
parameter) and contains the given string (second parameter).</p>
<div class="section"><p>This UDF uses the functions of the text management system to quickly
identify the documents:</p>
<pre> <strong>CREATE FUNCTION</strong> DOCMATCH (<strong>VARCHAR</strong>(30), <strong>VARCHAR</strong>(255))
<strong>RETURNS TABLE</strong> (DOC_ID <strong>CHAR</strong>(16))
<strong>EXTERNAL NAME</strong> 'DOCFUNCS/UDFMATCH(udfmatch)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION
NOT FENCED
SCRATCHPAD
NO FINAL CALL
DISALLOW PARALLEL
CARDINALITY 20</strong></pre>
<p>Within the context of a single session
it will always return the same table, and therefore it is defined as DETERMINISTIC.
The RETURNS clause defines the output from DOCMATCH, including the column
name DOC_ID. FINAL CALL does not need to be specified for this table function.
The DISALLOW PARALLEL keyword is required since table functions cannot operate
in parallel. Although the size of the output from DOCMATCH can be a large
table, CARDINALITY 20 is a representative value, and is specified to help
the optimizer make good decisions.</p>
</div>
<div class="section"><p>Typically, this table function is used in a join with the table
containing the document text, as follows:</p>
<pre> <strong>SELECT</strong> T.AUTHOR, T.DOCTEXT
<strong>FROM</strong> DOCS <strong>AS</strong> T, <strong>TABLE</strong>(DOCMATCH('MATHEMATICS', 'ZORN''S LEMMA')) <strong>AS</strong> F
<strong>WHERE</strong> T.DOCID = F.DOC_ID</pre>
<p>Note the special syntax
(TABLE keyword) for specifying a table function in a FROM clause. In this
invocation, the DOCMATCH() table function returns a row containing the single
column DOC_ID for each MATHEMATICS document referencing ZORN'S LEMMA. These
DOC_ID values are joined to the master document table, retrieving the author's
name and document text.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyudfdudf.htm" title="A UDF must be registered in the database before the function can be recognized and used by SQL.">Register UDFs</a></div>
</div>
</div>
</body>
</html>