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

If we talk at very low-level, cast function converts one column data type into another data-type.

For example:

SELECT DEPT_NAME, CAST(DEPT_AMT AS DECIMAL(10,2))

FROM DEPT_TABLE;

It is very clear from the above example that, DEPT_AMT is numeric column, then CAST converts it into Decimal(10,2). This is the fundamental use of CAST.

  • There are limitations on converting data types. I will cover in my next post.
  • With CAST function , even NULL we convert it into integer or Char etc.,
  • The data conversion CAST (NULL AS INTEGER). This is for single row value. I will cover more CAST usages in my next lot.
Advertisements

Author: Srini

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

Comments are closed.