How to convert functions correctly using the MySQL numeric type

Source: Internet
Author: User

The following article mainly introduces how to use the MySQL numeric type to correctly convert the function (concat/cast) to the actual operation process, and the projects in the actual operation are worth noting, the following is a description of the specific content. I hope it will be helpful for your future study.

1. The concat function is often used to convert Int to varchar. For example, concat (8, '0') gets the string '80 ′

2. Convert varchar into an Int string of the varchar type using cast (a as signed).

Summary: type conversion is similar to SQL Server, that is, the type parameters are slightly different: CAST (xxx AS type), CONVERT (xxx, type)

Available types in the MySQL numeric type conversion function (concat/cast)

Binary, with a BINARY Prefix: binary

Character type, with parameters: CHAR ()

DATE: DATE

TIME: TIME

DATETIME type

Floating Point: DECIMAL

Integer: SIGNED

UNSIGNED integer

Cast function running example

 
 
  1. mysql> select cast(‘125e342.83′ as signed) as clm1, cast(‘foo seo 589′ as signed) as clm2,cast(‘3.35′ as signed) as clm3;  
  2. +——+——+——+  
  3. | clm1 | clm2 | clm3 |  
  4. +——+——+——+  
  5. | 125 | 0 | 3 |  
  6. +——+——+——+  
  7. 1 row in set, 3 warnings (0.00 sec)  
  8. mysql> 

The above content is an introduction to the MySQL numeric type conversion function (concat/cast). I hope you will get some benefits.
 

 

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.