The SQL conversion functions, also known as type conversion functions, are helpful for converting data between different data types. These functions are useful for changing the data type of a column value in SQL queries.
In other words, you can convert a SQL function as per your needs into a different type of data type.
SQL CAST Function:
The CAST function is used to convert one data type to another data type.
SELECT CAST(‘123’ AS INT) AS numeric_value;
SQL CONVERT Function:
The CONVERT function is similar to CAST function and is used for data type conversion.
SELECT CONVERT(DATE, ‘2023-09-13’) AS converted_date;
SQL TO_NUMBER Function (Oracle):
The TO_NUMBER function converts a character string to a number in Oracle SQL.
SELECT TO_NUMBER(‘45.67’, ‘999.99’) AS converted_number FROM dual;
SQL TO_DATE Function (Oracle):
In Oracle SQL, the TO_DATE function converts a character string to a date.
SELECT TO_DATE(‘2023-09-13’, ‘YYYY-MM-DD’) AS converted_date FROM dual;
SQL PARSE Function (SQL Server):
In SQL Server, the PARSE function converts a character string to a specific data type.
SELECT PARSE(‘2023-09-13’ AS DATE USING ‘en-US’) AS converted_date;
SQL TO_CHAR Function (Oracle, PostgreSQL):
SELECT TO_CHAR(12345.6789, ‘99999.999’) AS formatted_number FROM dual;
These SQL conversion functions are useful for changing the data type of values in your queries, ensuring compatibility with other functions or
conditions.
Read More…
Difference Between DROP, DELETE, and TRUNCATE: DROP vs DELETE vs TRUNCATE
What are SQL string functions?