1024programmer Mysql How to convert function of Mysql number type

How to convert function of Mysql number type

Mysql number type conversion function method: 1. Use the function concat to convert Int to varchar; 2. Use [cast(a as signed) a] to convert varchar to Int.

More related free learning recommendation: mysql tutorial (video)

Mysql number type Method of conversion function:

1. Convert Int to varchar often use the concat function, such as concat(8,'0') to get the string '80& #39;

and MENU_NAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'  %')

2. Convert varchar to Int and use cast(a as signed) a to varchar type string

Summary: type conversion is the same as SQL Server, The type parameter is a bit different: CAST(xxx AS type), CONVERT(xxx, type)

Available types

  • Binary, same effect with binary prefix: BINARY

  • Character type, can take parameters: CHAR()

  • Date: DATE

  • Time: TIME

  • DateTime: DATETIME

  • Float: DECIMAL

  • Integer: SIGNED

  • Unsigned Integer: UNSIGNED

SELECT * from sys_menu where PARENT_ID='0' ORDER BY cast(MENU_NO as signed)

When MENU_NO is a letter or Chinese character, the converted number is 0.

3. When we want to modify the sorting of a user list frequently, we need It is used when the serial number is a decimal. Because if it is an integer, then after adjusting the first one, all subsequent numbers must be adjusted. So we use decimals to sort.

For example 3 3.1 3.2 3.201 3.9 4

In sql we need

order by u.NUMBER+  0
 The mysql database type of NUMBER is varchar.  

The above is the detailed content of how to convert the Mysql number type. For more information, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-to-convert-function-of-mysql-number-type/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索