Data Type Conversion in SQL

Last Updated : 13 Oct, 2026

SQL data type conversion is used to convert a value from one data type to another. It helps ensure that data is compatible with SQL operations and produces the required results.

  • Converts values between data types such as numeric, character and date types.
  • Helps perform operations on compatible data types.
  • Allows values to be displayed or processed in the required format.

Types of Data Type Conversion

There are two main types of data type conversion in SQL:

  • Implicit Data Type Conversion: The database automatically converts a value from one data type to another when compatible types are used.
  • Explicit Data Type Conversion: The user explicitly converts a value from one data type to another using a conversion function or operator.

Implicit Data Type Conversion

Implicit conversion occurs automatically when the database can convert compatible data types without requiring the user to specify a conversion.

For example, when compatible numeric values are used in an SQL expression, the database may automatically convert them to a suitable type.

Note: Implicit conversion rules can vary between SQL database systems.

Consider the following query:

SELECT 10 + 5.5 AS result;

Output:

Screenshot-2026-09-29-102528

Explicit Data Type Conversion

Explicit conversion is performed manually when a specific data type is required. The commonly used SQL syntax is CAST().

CAST() Function

The CAST() function converts an expression from one data type to another.

Syntax:

CAST(expression AS data_type)

Where:

  • expression: The value or column to be converted.
  • data_type: The target data type.

Example 1: Convert String to Integer

SELECT CAST('15000' AS INTEGER) AS salary;

Output:

sql1
  • The string value is explicitly converted into an integer.

Example 2: Convert Integer to Character

SELECT CAST(15000 AS VARCHAR(20)) AS salary;

Output:

sql1
  • The integer value is explicitly converted into a character value.

Example 3: Convert String to Date

SELECT CAST('2026-09-29' AS DATE) AS joining_date;

Output:

pic2sql
  • The string value is explicitly converted into a date.
Comment