How to perform data conversion and formatting operations in MySQL?
In MySQL, built-in functions can be used for data conversion and formatting operations. Here are some commonly used functions:
- Converts a value (of any type) into a specified datatype.
SELECT CAST('123' AS SIGNED);
- Change the data type
SELECT CONVERT('2022-01-01', DATE);
- Format the date
SELECT DATE_FORMAT('2022-01-01', '%Y/%m/%d');
- Combine()
SELECT CONCAT('Hello', 'World');
- convert all characters in the text to uppercase
- convert to lowercase
SELECT UPPER('hello');
SELECT LOWER('WORLD');
These functions can assist you in transforming and formatting data to better suit your needs.