MySQL converts characters into numbers

Source: Internet
Author: User

In the operation of MySQL, often need to convert characters into numbers, this step is simple, but not commonly used words are easy to forget, now will be found on the Internet The method is recorded as follows:

1. Convert the number of characters to a number, such as ' 0 ' to 0 can be directly implemented with addition
For example: Sorting d in the Pony table can be defined as varchar, which can be resolved
SELECT * FROM Pony ORDER by (d+0)
2. In the case of ifnull processing, such as ifnull (A/b, ' 0 ') This causes A/b to become a string, so we need to change the ' 0 ' to 0 to solve this problem.
3. Compare numbers and varchar, such as a=11,b= "11DDDDD";
The Select 11= "11ddddd" is equal
If the absolute comparison can be this:
Select binary one =binary "11DDDDD"
4. Character Set conversion: convert (XXX USING gb2312)
Type conversions are just like SQL Server, where type parameters are a little different: CAST (xxx as type), convert (XXX, type), type must be of the following types:
Available types:
Binary, with binary prefix effect: binary
Character type, with parameters: CHAR ()
Date: Date
Time:
DateTime Date/Time type
Floating point number: DECIMAL
Integer: Signed
unsigned integer: UNSIGNED

http://blog.csdn.net/dengsilinming/article/details/8481417

MySQL converts characters into numbers

Related Article

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.