In depth explanation of MYSQL character number conversion

  • 2020-05-17 06:49:39
  • OfStack

1. Converting a character's number to a number, such as '0' to zero, can be done directly by adding
For example, sorting d in the pony table can be solved by defining d as varchar
select * from pony order by (d+0)

2. When doing ifnull processing, such as ifnull(a/b,'0'), this will result in a/b becoming a string, so you need to change '0' to 0 to solve this problem

3. When comparing Numbers with varchar, for example, a=11, b="11ddddd";
Then select 11="11ddddd" is the same
If the absolute comparison can be like this:
select binary 11 =binary "11ddddd"

4. Character set conversion: CONVERT(xxx USING gb2312)
The type conversion is slightly different from SQL Server1 in that the type parameters are: CAST(xxx AS type), CONVERT(xxx, type), and the type must be of the following type:
Available types
Base 2, with the binary prefix: BINARY
Character type, with parameter: CHAR()
Date: DATE
Time: TIME
Date time type: DATETIME
Floating point number: DECIMAL
Integer: SIGNED
Unsigned integer: UNSIGNED

Related articles: