1. Concat function. Commonly used connection string: concat function. For example, the like query of sql query condition, AND c.name like concat(#{param.name},'%') The concat function is often used to convert Int to varchar, for example, concat(8,'0') gets the string '80' 2. Cast function; CONVERT function. Usage: CAST(expr AS type), CONVERT(expr,type) , CONVERT(expr USING transcoding_name). SELECT CONVERT('abc' USING utf8); Convert varchar to Int using cast(str as unsigned) str is a string of varchar type. For example, commonly used percentage conversion: select cast((1/3)*100 as UNSIGNED) as percent from dual;
MySQL type conversion function parameters: CAST(xxx AS type), CONVERT(xxx, type) Integer: SIGNED mysql> SELECT BINARY 'a' = 'A'; -> 0 3. IF function In mysql, if is a function rather than a command IF(expr1,expr2,expr3) mysql> SELECT IF(1>2,2,3); -> 3 mysql> SELECT IF(1<2,'yes','no'); -> 'yes' mysql> SELECT IF(STRCMP('test','test1'),'no','yes'); -> 'no' If expr2 or expr3 is explicitly NULL, the return type of the IF() function is the type of the non-NULL column. (This option is new in MySQL 4.0.3). expr1 is evaluated as an integer value, which means that if a floating point or string value is tested, a comparison must be performed: mysql> SELECT IF(0.1,1,0); -> 0 mysql> SELECT IF(0.1<>0,1,0); -> 1 In the first case above, IF(0.1) returns 0 because 0.1 is converted to an integer value, returning the result of the test of IF(0). This might not be what you expect. In the second case, the comparison tests whether the original floating-point number is a non-zero value. The result of the comparison is used as an integer. The default IF() return value type (which is important when the result is stored in a temporary table) is determined as follows in MySQL 3.23: The expression (expr2) or expression (expr3) returns a string string The expression (expr2) or expression (expr3) returns a floating-point value. The expression (expr2) or expression (expr3) returns an integer. If both expr2 and expr3 are strings, and both strings are case-insensitive, the return value is also case-insensitive (as of MySQL 3.23.51). The above is a summary of the commonly used MySQL type conversion functions that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: How to implement a password strength detector in react
>>: How to run Hadoop and create images in Docker
CSS CodeCopy content to clipboard .bottomTable{ b...
Table of contents Stabilization Introduction Anti...
The warehouse created using the official Docker R...
In the Linux system, there is a kind of file call...
As a software developer, you must have a complete...
Preface When operating and managing Linux servers...
Introduction The use of is null, is not null, and...
1. Installation process MySQL version: 5.7.18 1. ...
Communication between containers 1. Network shari...
This article shares with you the graphic tutorial...
mysql accidentally deleted data Using the delete ...
nvm nvm is responsible for managing multiple vers...
I have read countless my.cnf configurations on th...
Error description When we install Docker Desktop,...
background Recently, a leader wanted us to build ...