<?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="Define a UDT" /> <meta name="abstract" content="UDTs are defined with a CREATE DISTINCT TYPE statement." /> <meta name="description" content="UDTs are defined with a CREATE DISTINCT TYPE statement." /> <meta name="DC.subject" content="UDTs (User-defined types), defining a UDT, CREATE DISTINCT TYPE statement, to define a UDT" /> <meta name="keywords" content="UDTs (User-defined types), defining a UDT, CREATE DISTINCT TYPE statement, to define a UDT" /> <meta name="DC.Relation" scheme="URI" content="rbafyuddt.htm" /> <meta name="DC.Relation" scheme="URI" content="rbafymoney.htm" /> <meta name="DC.Relation" scheme="URI" content="rbafyresume.htm" /> <meta name="DC.Relation" scheme="URI" content="rbafyusquref.htm" /> <meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstcrtudt.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="rbafydefudt" /> <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>Define a UDT</title> </head> <body id="rbafydefudt"><a name="rbafydefudt"><!-- --></a> <!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script> <h1 class="topictitle1">Define a UDT</h1> <div><p>UDTs are defined with a CREATE DISTINCT TYPE statement. </p> <div class="section"><p>For the CREATE DISTINCT TYPE statement, note that: </p> </div> <div class="section"> <ol><li>The name of the new UDT can be a qualified or an unqualified name.</li> <li>The source type of the UDT is the type used by the system to internally represent the UDT. For this reason, it must be a built-in data type. Previously defined UDTs cannot be used as source types of other UDTs. </li> </ol> </div> <div class="section"><p>As part of a UDT definition, the system always generates cast functions to: </p> </div> <div class="section"> <ul><li>Cast from the UDT to the source type, using the standard name of the source type. For example, if you create a distinct type based on FLOAT, the cast function called DOUBLE is created. </li> <li>Cast from the source type to the UDT. </li> </ul> </div> <div class="section"><p>These functions are important for the manipulation of UDTs in queries.</p> </div> <div class="section"><p>The function path is used to resolve any references to an unqualified type name or function, except if the type name or function is the main object of a CREATE, DROP, or COMMENT ON statement.</p> </div> </div> <div> <ul class="ullinks"> <li class="ulchildlink"><strong><a href="rbafymoney.htm">Example: Money</a></strong><br /> In this example, suppose you are writing applications that need to handle different currencies and want to ensure that DB2<sup>®</sup> does not allow these currencies to be compared or manipulated directly with one another in queries.</li> <li class="ulchildlink"><strong><a href="rbafyresume.htm">Example: Resume</a></strong><br /> In this example, suppose you want to keep the application forms that are filled out by applicants to your company in a table and you are going to use functions to extract the information from these forms.</li> </ul> <div class="familylinks"> <div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyuddt.htm" title="A user-defined distinct type is a mechanism that allows you to extend DB2 capabilities beyond the built-in data types available.">Use user-defined distinct types (UDT)</a></div> </div> <div class="relref"><strong>Related reference</strong><br /> <div><a href="rbafyusquref.htm" title="If you use a qualified function reference, you restrict the search for a matching function to that schema.">Use qualified function reference</a></div> </div> <div class="relinfo"><strong>Related information</strong><br /> <div><a href="../db2/rbafzmstcrtudt.htm">CREATE DISTINCT TYPE statement</a></div> </div> </div> </body> </html>