Home > Database > Mysql Tutorial > How to convert mysql to int

How to convert mysql to int

藏色散人
Release: 2020-09-30 10:31:47
Original
11197 people have browsed it

Mysql conversion method to int: 1. Convert the type manually; 2. Use the MySQL function CAST to achieve conversion; 3. Use the MySQL function CONVERT to achieve the conversion.

How to convert mysql to int

Recommended: "PHP Video Tutorial"

MySQL varchar to int

1. Manual conversion type (direct 0)

Example:

select server_id from cardserver where game_id = 1 order by server_id+0 desclimit 10
Copy after login

2. Use MySQL function CAST:

Example:

select server_id from cardserver where game_id = 1 order by CAST(server_id as SIGNED) desc limit 10;
Copy after login

3. Use MySQL function CONVERT:

Example:

select server_id from cardserver where game_id = 1 order by CONVERT(server_id,SIGNED)desc limit 10;
Copy after login

Note:

CAST function, CONVERT usage

CAST(expr AS type), CONVERT( expr,type) , CONVERT(expr USING transcoding_name)

CAST() and CONVERT() functions can be used to obtain a value of one type and produce a value of another type.

This type can be one of the following values:

BINARY[(N)]  
CHAR[(N)]  
DATE  
DATETIME  
DECIMAL  
SIGNED   [INTEGER]  
TIME  
UNSIGNED   [INTEGER]
Copy after login

The above is the detailed content of How to convert mysql to int. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template