
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get the type of a variable in MySQL?
You cannot get the type of variable in MySQL. Cast the type of variable into another using CAST operator. The syntax is as follows −
SET @yourVariableName:=’anyValue’
Use the CAST operator to cast to another type. The syntax is as follows −
SELECT CAST( @yourVariableName AS SIGNED);
To understand the above syntax, let us cast to another type.
Case 1: String to unsigned −
mysql> set @StringToInt:='12345'; Query OK, 0 rows affected (0.00 sec)
The query is as follows to another type −
mysql> select CAST(@StringToInt as UNSIGNED);
The following is the output −
+--------------------------------+ | CAST(@StringToInt as UNSIGNED) | +--------------------------------+ | 12345 | +--------------------------------+ 1 row in set (0.00 sec)
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)
The query is as follows −
mysql> select @IntTochar;
The following is the output −
+------------+ | @IntTochar | +------------+ | 65 | +------------+ 1 row in set (0.00 sec)
- Related Articles
- How to get the variable data type in PowerShell?
- Get number of users of different type in MySQL?
- Creating a variable with dynamic variable type in SAP ABAP
- How to check the type of a variable or object in JavaScript?
- Get the name of a primitive type in Java
- Set the result of a query to a variable in MySQL?
- Get a specific type nested within the current Type in C#
- Get the Contents of a Web Page in a Shell Variable on Linux
- Get the underlying type of the current enumeration type C#
- How to check if type of a variable is string in Python?
- Get count of zeros for columns values declared with INT type in MySQL
- Get a specific field of the current type C#
- Get the index of the nth item of a type in a JavaScript array
- How to get the data type of a tensor in PyTorch?
- How to get the value of environment variable in Postman?

Advertisements