DB2 Data type Conversions

Source: Internet
Author: User
Tags db2

DB2 Data type conversions:

1. CAST ()
CAST (<expression> as <data_ type>[length])

2. CONVERT ()
CONVERT (<data_ type>[length], <expression> [, Style])

1) data_type The data type defined for the SQL Server system, the user-defined data type cannot be used here.
2) length is used to specify how long the data is, and the default value is 30.
3) converts a char or varchar type to an integer type such as int or samllint, and the result must be a numeric value with a plus or minus sign.
4) The text type is converted to char or varchar type up to 8,000 characters, that is, the char or varchar data type is the maximum length.
5) The data stored by the image type is converted to binary or varbinary type, up to a maximum of 8,000 characters.
6) Convert integer value to Money or smallmoney type, processed in the currency unit of the defined country, such as RMB, USD, GBP, etc.
7) A bit type conversion converts a non-0 value to 1 and is still stored as a bit type.
8) attempts to convert to a different length of data type will truncate the conversion value and display "+" after the value is converted to identify the truncation occurred.
9) Use the style option of the CONVERT () function to display the date and time in a different format. The style is the conversion style number that is provided by the SQL Server system when converting Datatime and smalldatetime data to strings, and different style numbers have different output formats.

Money is an integer integer----> Char char (Money)
char-------> Integer integer (Trim (char))

Money is double (8,2) Double----->char char (CAST (Money as Decimal (8,2)))
Char------->double cast (CAST (char (A.money as Decimal (8,2)) as decimal (8,2) as Double)

Money is decimal (8,2) decimal------->char Digits (Money)
Char------->decimal cast (Digits (Money) as decimal (8,2))

Money is a date date------>char char (Money)
char------>date Date (Trim (char))

Money for bigint bigint---->char char (money)
Char----->bigint cast (char (money) as bigint)

DB2 Data type Conversions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.