Home >Database >Mysql Tutorial >mysql conversion function
As the amount of data continues to grow and business needs continue to become more complex, the data types in the database are becoming more and more diverse. In practical applications, we often need to convert between different data types, which inevitably requires the use of some conversion functions.
MySQL is a commonly used relational database management system that provides many built-in data types and conversion functions. This article will introduce the commonly used conversion functions in MySQL to facilitate readers to convert data types in practical applications.
1. Conversion function definition
The conversion function in MySQL is a set of functions that can convert different data types to each other. These functions convert one data type to another.
2. Classification of conversion functions
Conversion functions in MySQL can be divided into the following categories:
3. Conversion function usage
SELECT ROUND(123.456,2);
The result is: 123.46
SELECT TRUNCATE(123.456,2);
The result is: 123.45
SELECT CEILING(123.456);
The result is: 124
SELECT FLOOR(123.456);
The result is: 123
SELECT CONCAT('Hello', 'world');
The result is: Helloworld
SELECT SUBSTRING('Hello world', 1, 5);
The result is: Hello
SELECT REPLACE('Hello world', 'world', 'MySQL');
The result is: Hello MySQL
SELECT UPPER('Hello world');
The result is: HELLO WORLD
SELECT DATE_ADD('2021-01-01', INTERVAL 1 YEAR);
The result is: 2022-01-01
SELECT DATE_SUB('2021-01-01', INTERVAL 1 YEAR);
The result is: 2020-01-01
SELECT TO_DAYS('2021-01-01');
The result is: 737791
SELECT FROM_DAYS(737791);
The result is: 2021-01-01
SELECT IFNULL(NULL, 'MySQL');
The result is: MySQL
SELECT CAST('123' AS SIGNED);
The result is: 123
SELECT CONVERT('123.456', DECIMAL(6,2));
The result is: 123.46
4. Summary
MySQL It provides many built-in conversion functions, which can convert different data types to each other, making it convenient for readers to convert data types in practical applications. Proficient in the usage of these functions can improve our data processing efficiency and improve application performance.
The above is the detailed content of mysql conversion function. For more information, please follow other related articles on the PHP Chinese website!