Home > Database > Mysql Tutorial > body text

How to convert value to numeric type in mysql

青灯夜游
Release: 2022-03-01 15:15:53
Original
14536 people have browsed it

Conversion method: 1. Use CAST(), the syntax is "SELECT CAST('value' AS SIGNED);"; 2. Use CONVERT(), the syntax is "SELECT CONVERT('value', SIGNED);" ;3. Use the " " operator, the syntax is "SELECT 'value' 0;".

How to convert value to numeric type in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Mysql method of converting values ​​​​to numeric types

##Method 1: Use the CAST() function

CAST() function can convert a value (any type) to the specified data type

How to convert value to numeric type in mysql

Example:

SELECT CAST('123' AS SIGNED);
Copy after login

Method 2: Use CONVERT() function

The CONVERT() function converts a value to a specified data type or character set.

Example: How to convert value to numeric type in mysql

SELECT CONVERT('123',SIGNED);
Copy after login

Method 3: Use the " " operator

Example:

SELECT '123'+0;
Copy after login

[Related recommendations :

mysql video tutorial

The above is the detailed content of How to convert value to numeric type in mysql. 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