SQL CAST real examples (2 of 2)

Refer my part-1 if you miss it. In my next example, I will give converting CHAR column to VARCHAR

Cast Function

Example-1

CAST(CHAR-CLMN  as VARCHAR(100));

In the second way, CREATE DISTINCT TYPE SAL_1 AS DECIMAL(9,2); This is equal to CAST function.

Example-2

CAST(SAL_1 AS DECIMAL(9,2));

Points to Remember

  • The function CAST helps you to change almost all data types into another data types.
  • Before casting we need to make sure that you understand the rules
  • Converting type may have an impact on the result
  • Few people asked that unable to convert INTEGER to STRING. Before doing read all the CAST function rules.  

Source: IBM

Refer here on possibility of data types and rules for CAST.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.