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.
CAST(SAL_1 AS DECIMAL(9,2));
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.
Refer here on possibility of data types and rules for CAST.