5la*_*ava 18
您可以确定MySQL中变量的类型.通过选择变量创建表,然后检查列类型:
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 | |
+-------+----------+------+-----+---------+-------+
Run Code Online (Sandbox Code Playgroud)
MySQL 中无法确定变量的类型。
作为替代方案,您可以轻松地将CAST()
变量设置为您想要的类型:
@a = CAST(123 AS CHAR);
Run Code Online (Sandbox Code Playgroud)
有关强制转换的更多信息和示例,请参阅 MySQL 手册: