10.12.2012 Views

Application Programming and SQL Guide - Kmlinux

Application Programming and SQL Guide - Kmlinux

Application Programming and SQL Guide - Kmlinux

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 1. Compatibility of data types for assignments <strong>and</strong> comparisons. Y indicates that the data types are compatible.<br />

N indicates no compatibility. For any number in a column, read the corresponding note at the bottom of the table.<br />

Oper<strong>and</strong>s<br />

Binary<br />

integer<br />

Decimal<br />

number<br />

Floating<br />

point<br />

Character<br />

string<br />

Graphic<br />

string<br />

Binary<br />

string Date Time<br />

Time-<br />

stamp<br />

Binary Integer Y Y Y N N N N N N N 2<br />

Decimal<br />

Number<br />

Row<br />

ID<br />

Y Y Y N N N N N N N 2<br />

Floating Point Y Y Y N N N N N N N 2<br />

Character<br />

String<br />

N N N Y Y 4,5<br />

Graphic String N N N Y 4,5<br />

Binary String N N N N 3<br />

N 3<br />

1 1 1 N 2<br />

Y N 1,4 1,4 1,4 N 2<br />

N Y N N N N 2<br />

Date N N N 1 1,4 N Y N N N 2<br />

Time N N N 1 1,4 N N Y N N 2<br />

Timestamp N N N 1 1,4 N N N Y N 2<br />

Row ID N N N N N N N N N Y 2<br />

Distinct Type 2 2 2 2 2 2 2 2 2 2 Y 2<br />

Notes:<br />

Distinct<br />

type<br />

1. The compatibility of datetime values is limited to assignment <strong>and</strong> comparison:<br />

v Datetime values can be assigned to string columns <strong>and</strong> to string variables, as explained in Chapter 2 of DB2<br />

<strong>SQL</strong> Reference.<br />

v A valid string representation of a date can be assigned to a date column or compared to a date.<br />

v A valid string representation of a time can be assigned to a time column or compared to a time.<br />

v A valid string representation of a timestamp can be assigned to a timestamp column or compared to a<br />

timestamp.<br />

2. A value with a distinct type is comparable only to a value that is defined with the same distinct type. In general,<br />

DB2 supports assignments between a distinct type value <strong>and</strong> its source data type. For additional information, see<br />

Chapter 2 of DB2 <strong>SQL</strong> Reference.<br />

3. All character strings, even those with subtype FOR BIT DATA, are not compatible with binary strings.<br />

4. On assignment <strong>and</strong> comparison from Graphic to Character, the resulting length in bytes is 3 * (LENGTH(graphic<br />

string)), depending on the CCSIDs.<br />

5. Character strings with subtype FOR BIT DATA are not compatible with Graphic Data.<br />

Selecting columns: SELECT<br />

You have several options for selecting columns from a database for your result<br />

tables. This section describes how to select columns using a variety of techniques.<br />

Selecting all columns: SELECT *<br />

You do not need to know the column names to select DB2 data. Use an asterisk (*)<br />

in the SELECT clause to indicate that you want to retrieve all columns of each<br />

selected row of the named table.<br />

Example: SELECT *: The following <strong>SQL</strong> statement selects all columns from the<br />

department table:<br />

SELECT *<br />

FROM DSN8810.DEPT;<br />

The result table looks similar to the following output:<br />

Chapter 1. Retrieving data 5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!