DB2- Why CAST Function Needed? (2 of 2)

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


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


Before casting, DB2 developer has to remember these points:

  • The function CAST helps to change almost all data types into another data types.
  • Second one is, before casting we need to make sure that you understand the rules
  • Converting type will have some impact on the result
  • I have seen there are many questions, like, I am unable to convert INTEGER to STRING. Solution is, just read the 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.