MySQL

MySQL CONVERT()

The SQL CONVERT() function, allows to convert a data of one type into another, similar to CAST(). For example, the function allows you to convert a FLOAT data type to INTEGER or a DATE to DATETIME.
 

Syntax:

This function can be used in SQL query with the following syntax:

CONVERT(expression, type);

The “expression” parameter refers to the data to be transtyped. The data type can be BINARY, CHAR, DATE, DATETIME, INTEGER, or TIME.
 

 

Example :

The following SQL queries are practical examples of data type conversion with MySQL:

SELECT CONVERT(9.4, SIGNED INTEGER); -- output: 9
SELECT CONVERT(9.6, SIGNED INTEGER); -- output: 10
SELECT CONVERT(-9.6, SIGNED INTEGER); -- output: -10
SELECT CONVERT(9.2, UNSIGNED INTEGER); -- output: 9
SELECT CONVERT('2022-12-01', DATETIME); -- output: 2022-12-01 00:00:00
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *