If I define a variable like set @a = "1";
. How can I see that @a is a string?
You can also use the describe statement to check the datatypes of all the columns of the table as follows: DESCRIBE table_name; If you are interested in SQL, then check out this SQL Course by Intellipaat that offers instructor-led training, certification, and job assistance.
SHOW VARIABLES accepts an optional GLOBAL or SESSION variable scope modifier: With a GLOBAL modifier, the statement displays global system variable values. These are the values used to initialize the corresponding session variables for new connections to MySQL. If a variable has no global value, no value is displayed.
The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data. In MySQL there are three main data types: string, numeric, and date and time.
@@ - System Variable @@ is used for system variables. Using different suffix with @@ , you can get either session or global value of the system variable.
You CAN determine the type of a variable in MySQL. Create a table by selecting your variable and then check the column type:
set @a:="1"; -- your variable
drop temporary table if exists foo;
create temporary table foo select @a; -- dirty magic
desc foo;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| @a | longtext | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With