In-depth explanation of MYSQL character and digit Conversion

Source: Internet
Author: User

1.Convert the number of a character to a number. For example, convert '0' to 0, which can be directly implemented by addition.
For example, sort d in the pony table and define d as varchar.
Select * from pony order by (d + 0)

2. when performing ifnull processing, for example, ifnull (a/B, '0') will cause a/B to become a string. Therefore, you need to change '0' to 0 to solve this problem.

3. When comparing numbers and varchar, such as a = 11, B = "11 ddddd ";
Select 11 = "11 ddddd" is equal
The comparison can be as follows:
Select binary 11 = binary "11 ddddd"

4. Character Set conversion: CONVERT (xxx USING gb2312)
Type conversion is similar to SQL Server, that is, the type parameters are a little different: CAST (xxx AS type), CONVERT (xxx, type), The type must use the following types:
Available types
Binary, with a BINARY Prefix: binary
Character type, with parameters: CHAR ()
DATE: DATE
TIME: TIME
DATETIME type
Floating Point: DECIMAL
Integer: SIGNED
UNSIGNED integer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.