Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The cast() function is used to convert the data type of a value or expression to another data type. The proper way to utilize the cast() function is as follows:

  1. Specify the value or expression that needs to be converted.
  2. Add the keyword 'AS' followed by the target data type that the value should be converted to.
  3. Enclose the entire expression within parentheses.

For example, to convert the value of a column named 'Price' from a string data type to a decimal data type, the following SQL query can be used:

SELECT CAST(Price AS DECIMAL(10,2)) FROM products;

In this example, the value of the 'Price' column will be converted to a decimal data type with a precision of 10 and a scale of 2.