How to convert function in Mysql numeric type

coldplay.xixi
Release: 2020-11-13 10:24:16
Original
2738 people have browsed it

Mysql numeric 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.

How to convert function in Mysql numeric type

More related free learning recommendations:mysql tutorial(video)

Mysql numeric type conversion function method:

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

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

2. Convert varchar to Int using cast(a as signed) a is a string of varchar type

Summary: Type conversion is the same as SQL Server, but the type parameters are a little different: CAST(xxx AS type ), CONVERT(xxx, type)

Available types

  • Binary, with the effect of binary prefix: BINARY

  • Character type, can take parameters: CHAR()

  • Date: DATE

  • Time: TIME

  • Date time type: DATETIME

  • Floating point: DECIMAL

  • Integer: SIGNED

  • Unsigned integer: UNSIGNED

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

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

3. When we need to frequently modify the sorting of a user list, we need to use the situation where 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 NUMBER 的mysql数据库类型为varchar。
Copy after login

The above is the detailed content of How to convert function in Mysql numeric type. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!