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

64 lines
4.2 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="Cast data types" />
<meta name="abstract" content="Sometimes you will find situations where the type of an expression needs to be cast, or changed, to a different data type or to the same data type with a different length, precision, or scale." />
<meta name="description" content="Sometimes you will find situations where the type of an expression needs to be cast, or changed, to a different data type or to the same data type with a different length, precision, or scale." />
<meta name="DC.subject" content="SELECT statement, casting data types, data types, casting" />
<meta name="keywords" content="SELECT statement, casting data types, data types, casting" />
<meta name="DC.Relation" scheme="URI" content="rbafytexas.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstcastdt.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="rbafycasting" />
<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>Cast data types</title>
</head>
<body id="rbafycasting"><a name="rbafycasting"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Cast data types</h1>
<div><p>Sometimes you will find situations where the <em>type</em> of an
expression needs to be cast, or changed, to a different data type or to the
same data type with a different length, precision, or scale.</p>
<div class="section"><p>For example, if you want to compare two columns of different types,
such as a user defined type based on character and an integer, you can change
the character to an integer or the integer to a character to make the comparison
possible. A data type that can be changed to another data type is <em>castable</em> from
the source data type to the target data type.</p>
</div>
<div class="section"><p>You can use cast functions or CAST specification to explicitly
cast a data type to another data type. For example, if you have a column of
dates (BIRTHDATE) defined as DATE and want to cast the column data type to
CHARACTER with a fixed length of 10, enter the following:</p>
<pre><strong>SELECT CHAR</strong> (BIRTHDATE,USA)
<strong>FROM</strong> CORPDATA.EMPLOYEE</pre>
<p>You can also use the CAST specification
to cast data types directly.</p>
<pre><strong>SELECT CAST</strong>(BIRTHDATE <strong>AS CHAR</strong>(10))
<strong>FROM</strong> CORPDATA.EMPLOYEE</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafytexas.htm" title="Learn a variety of ways of tailoring your query to gather data using the SELECT statement. One way to do this is to use the SELECT statement in a program to retrieve a specific row (for example, the row for an employee). Furthermore, you can use clauses to gather data in a specific way.">Retrieve data using the SELECT statement</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../db2/rbafzmstcastdt.htm">Cast between data types</a></div>
</div>
</div>
</body>
</html>