Common DB2 functions-type Conversion Function Inventory

Source: Internet
Author: User
Tags db2 functions

The following articles mainly describe the type conversion functions of common DB2 functions. If you are interested in the type conversion functions described in common DB2 functions, you can click the following articles to view them, the following is a detailed description of the article.

Keywords: DB2, type conversion, Function

CAST expression used for Conversion Type

SQL code

 
 
  1. SELECT CAST(CURRENT TIME AS CHAR(8) ) FROM SYSIBM.SYSDUMMY1  
  2. SELECT CAST(CURRENT TIME AS CHAR(8) ) FROM SYSIBM.SYSDUMMY1  

Common DB2 functions: type conversion function 1. Convert to string type:

CHAR Function

Syntax: CHAR (ARG)

The CHAR function returns a string representation of a datetime, String, integer, decimal, or double-precision floating point number.

SQL code

 
 
  1. eg:   
  2. SELECT CHAR(SALARY) FROM TEST  
  3. eg:  
  4. SELECT CHAR(SALARY) FROM TEST 

CHR Function

Syntax: CHR (ARG)

The CHR function returns the ASCII code specified by the parameter. The parameter can be INTEGER or SMALLINT.

SQL code

 
 
  1. eg:   
  2. SELECT CHR(167) FROM TEST  
  3. eg:  
  4. SELECT CHR(167) FROM TEST 

Common DB2 functions-type conversion functions: VARCHAR Functions

Syntax: VARCHAR (ARG, LENGTH)

The VARCHAR function returns the variable-length string representation of the string, date type, and graphic string.

SQL code

 
 
  1. eg:   
  2. SELECT VARCHAR(NAME,50) FROM TEST  

-- 50 indicates the truncation length. If the length of the name string is greater than 50, "SQL0445W value has been truncated" is returned. SQLSTATE = 01004 ".

Eg:

 
 
  1. SELECT VARCHAR(NAME,50) FROM TEST 

-- 50 indicates the truncation length. If the length of the name string is greater than 50, "SQL0445W value has been truncated" is returned. SQLSTATE = 01004 ".

DIGITS Function

Syntax: DIGITS ()

The DIGITS function returns the string values of the SMALLINT, INTEGER, BIGIT, or DECIMAL parameters. SQL code

 
 
  1. eg:   
  2. SELECT DIGITS(ID) FROM TEST   
  3. eg:  
  4. SELECT DIGITS(ID) FROM TEST  

The above content is an introduction to the type conversion functions described in the common functions of DB2.

Related Article

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.