Home  >  Article  >  Database  >  How to convert mysql to int

How to convert mysql to int

藏色散人
藏色散人Original
2020-09-30 10:31:4711132browse

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

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;

3. Use MySQL function CONVERT:

Example:

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

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]

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!

Statement:
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