SQL CAST Function Convert Numeric to Decimal

Here is an SQL query on converting numeric column type to Decimal. If we talk at very low-level, cast function converts one column data type into another data-type.

SQL CAST 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 a numeric column, then CAST converts it into Decimal(10,2). This is the fundamental use of CAST.

  • There are limitations on converting data types.  
  • With CAST function , You can convert NULL as integer or Char etc.,
  • The data conversion CAST (NULL AS INTEGER). This is for single row value.

Keep Reading

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading