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

112 lines
5.5 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: Define the UDT and UDFs" />
<meta name="abstract" content="Suppose you want to keep the electronic mail (e-mail) sent to your company in a table." />
<meta name="description" content="Suppose you want to keep the electronic mail (e-mail) sent to your company in a table." />
<meta name="DC.subject" content="examples, defining the UDT and UDFs, UDTs (User-defined types), defining the UDT and UDFs example, UDFs (User-defined functions), defining the UDT and UDFs example" />
<meta name="keywords" content="examples, defining the UDT and UDFs, UDTs (User-defined types), defining the UDT and UDFs example, UDFs (User-defined functions), defining the UDT and UDFs example" />
<meta name="DC.Relation" scheme="URI" content="rbafyexampcomplex.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="rbafydudtudf" />
<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: Define the UDT and UDFs </title>
</head>
<body id="rbafydudtudf"><a name="rbafydudtudf"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Define the UDT and UDFs </h1>
<div><p>Suppose you want to keep the electronic mail (e-mail) sent to your
company in a table.</p>
<div class="section"><p>Ignoring any issues of privacy, you plan to write queries over
such e-mail to find out their subject, how often your e-mail service is used
to receive customer orders, and so on. E-mail can be quite large, and it
has a complex internal structure (a sender, a receiver, the subject, date,
and the e-mail content). Therefore, you decide to represent the e-mail by
means of a UDT whose source type is a large object. You define a set of UDFs
on your e-mail type, such as functions to extract the subject of the e-mail,
the sender, the date, and so on. You also define functions that can perform
searches on the content of the e-mail. You do the above using the following
CREATE statements: </p>
<pre> <strong>CREATE DISTINCT TYPE</strong> E_MAIL <strong>AS BLOB</strong> (1M)
<strong>CREATE FUNCTION</strong> SUBJECT (E_MAIL)
<strong>RETURNS VARCHAR</strong> (200)
<strong>EXTERNAL NAME</strong> 'LIB/PGM(SUBJECT)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION</strong>
<strong>CREATE FUNCTION</strong> SENDER (E_MAIL)
<strong>RETURNS VARCHAR</strong> (200)
<strong>EXTERNAL NAME</strong> 'LIB/PGM(SENDER)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION</strong>
<strong>CREATE FUNCTION</strong> RECEIVER (E_MAIL)
<strong>RETURNS VARCHAR</strong> (200)
<strong>EXTERNAL NAME</strong> 'LIB/PGM(RECEIVER)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION</strong>
<strong> CREATE FUNCTION</strong> SENDING_DATE (E_MAIL)
<strong>RETURNS DATE CAST FROM VARCHAR</strong>(10)
<strong>EXTERNAL NAME</strong> 'LIB/PGM(SENDING_DATE)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION</strong>
<strong>CREATE FUNCTION</strong> CONTENTS (E_MAIL)
<strong>RETURNS BLOB</strong> (1M)
<strong>EXTERNAL NAME</strong> 'LIB/PGM(CONTENTS)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION</strong>
<strong>CREATE FUNCTION</strong> CONTAINS (E_MAIL, <strong>VARCHAR</strong> (200))
<strong>RETURNS INTEGER</strong>
<strong>EXTERNAL NAME</strong> 'LIB/PGM(CONTAINS)'
<strong>LANGUAGE C
PARAMETER STYLE DB2SQL
NO SQL
DETERMINISTIC
NO EXTERNAL ACTION</strong>
<strong>CREATE TABLE</strong> ELECTRONIC_MAIL
(ARRIVAL_TIMESTAMP <strong>TIMESTAMP</strong>,
MESSAGE E_MAIL) </pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyexampcomplex.htm" title="The following examples show how you can use user-defined types (UDTs), user-defined functions (UDFs), and large objects (LOBs) together in complex applications.">Examples of using UDTs, UDFs, and LOBs</a></div>
</div>
</div>
</body>
</html>