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

96 lines
5.3 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 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: Assignments involving different UDTs" />
<meta name="abstract" content="Suppose you have defined two sourced UDFs on the built-in SUM function to support SUM on U.S. and Canadian dollars, similar to the UDF sourced on Euros in the Example: Sourced UDFs involving UDTs." />
<meta name="description" content="Suppose you have defined two sourced UDFs on the built-in SUM function to support SUM on U.S. and Canadian dollars, similar to the UDF sourced on Euros in the Example: Sourced UDFs involving UDTs." />
<meta name="DC.subject" content="UDTs (User-defined types), assignments involving different UDTs example, examples, assignments involving different UDTs" />
<meta name="keywords" content="UDTs (User-defined types), assignments involving different UDTs example, examples, assignments involving different UDTs" />
<meta name="DC.Relation" scheme="URI" content="rbafyexampudt.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafyudsrc.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="rbafyasdudt" />
<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: Assignments involving different UDTs </title>
</head>
<body id="rbafyasdudt"><a name="rbafyasdudt"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Assignments involving different UDTs </h1>
<div><p><span>Suppose you have defined two sourced UDFs
on the built-in SUM function to support SUM on U.S. and Canadian dollars,
similar to the UDF sourced on Euros in the Example: Sourced UDFs involving
UDTs.</span></p>
<div class="section"><pre>
<strong>CREATE FUNCTION SUM</strong> (CANADIAN_DOLLAR)
<strong>RETURNS</strong> CANADIAN_DOLLAR
<strong>SOURCE</strong> SYSIBM.SUM (<strong>DECIMAL</strong>())
<strong>CREATE FUNCTION SUM</strong> (US_DOLLAR)
<strong>RETURNS</strong> US_DOLLAR
<strong>SOURCE</strong> SYSIBM.SUM (<strong>DECIMAL</strong>())</pre>
</div>
<div class="section"><p>Now suppose your supervisor requests that you maintain the annual
total sales in U.S. dollars of each product and in each country, in separate
tables:</p>
<pre>
<strong>CREATE TABLE</strong> US_SALES_04
(PRODUCT_ITEM <strong>INTEGER</strong>,
TOTAL US_DOLLAR)
<strong>CREATE TABLE</strong> GERMAN_SALES_04
(PRODUCT_ITEM <strong>INTEGER</strong>,
TOTAL US_DOLLAR)
<strong>CREATE TABLE</strong> CANADIAN_SALES_04
(PRODUCT_ITEM <strong>INTEGER</strong>,
TOTAL US_DOLLAR)
<strong>INSERT INTO</strong> US_SALES_04
<strong>SELECT</strong> PRODUCT_ITEM, <strong>SUM</strong> (TOTAL)
<strong>FROM</strong> US_SALES
<strong>WHERE</strong> YEAR = 2004
<strong>GROUP BY</strong> PRODUCT_ITEM
<strong>INSERT INTO</strong> GERMAN_SALES_04
<strong>SELECT</strong> PRODUCT_ITEM, US_DOLLAR (<strong>SUM</strong> (TOTAL))
<strong>FROM</strong> GERMAN_SALES
<strong>WHERE</strong> YEAR = 2004
<strong>GROUP BY</strong> PRODUCT_ITEM
<strong>INSERT INTO</strong> CANADIAN_SALES_04
<strong>SELECT</strong> PRODUCT_ITEM, US_DOLLAR (<strong>SUM</strong> (TOTAL))
<strong>FROM</strong> CANADIAN_SALES
<strong>WHERE</strong> YEAR = 2004
<strong>GROUP BY</strong> PRODUCT_ITEM</pre>
</div>
<div class="section"><p>You explicitly cast the amounts in Canadian dollars
and Euros to U.S. dollars since different UDTs are not directly
assignable to each other. You cannot use the cast specification syntax because
UDTs can only be cast to their own source type.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyexampudt.htm" title="These are examples of using UDTs.">Examples: Use UDTs</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rbafyudsrc.htm" title="Suppose you have defined a sourced UDF on the built-in SUM function to support SUM on Euros.">Example: Sourced UDFs involving UDTs</a></div>
</div>
</div>
</body>
</html>