Home > Database > Mysql Tutorial > Get the type of variable in MySQL?

Get the type of variable in MySQL?

PHPz
Release: 2023-09-07 14:45:03
forward
981 people have browsed it

Get the type of variable in MySQL?

Unable to get the type of variable in MySQL. Use the CAST operator to convert a variable's type to another type. The syntax is as follows -

SET @yourVariableName:=’anyValue’
Copy after login

Convert to another type using the CAST operator. The syntax is as follows -

SELECT CAST( @yourVariableName AS SIGNED);
Copy after login

To understand the above syntax, let us convert to another type.

Case 1: String converted to unsigned -

mysql> set @StringToInt:='12345';
Query OK, 0 rows affected (0.00 sec)
Copy after login

Another type of query is as follows-

mysql> select CAST(@StringToInt as UNSIGNED);
Copy after login

The following is the output-

+--------------------------------+
| CAST(@StringToInt as UNSIGNED) |
+--------------------------------+
| 12345                          |
+--------------------------------+
1 row in set (0.00 sec)
Copy after login

Case 2: Int to char

The query is as follows-

mysql> set @IntTochar:=CAST(65 as CHAR);
Query OK, 0 rows affected (0.00 sec)
Copy after login

The query is as follows-

mysql> select @IntTochar;
Copy after login

The following is the output-

+------------+
| @IntTochar |
+------------+
| 65         |
+------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of Get the type of variable in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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