Get the type of a variable in MySQL

后端 未结 3 1550
感情败类
感情败类 2021-01-01 22:32

If I define a variable like set @a = \"1\";. How can I see that @a is a string?

3条回答
  •  长情又很酷
    2021-01-01 23:01

    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    |       |
    +-------+----------+------+-----+---------+-------+
    

提交回复
热议问题