Get the type of a variable in MySQL

后端 未结 3 1518
感情败类
感情败类 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:02

    In MySql, you cannot identify the Datatype of the variable. But there is a way to identify only the strings and Integer by using cast :

    set @a = "11";
    SELECT CAST(@a AS SIGNED); // Output : 11
    
    set @a = "text";
    SELECT CAST(@a AS SIGNED); // Output : 0
    
    
    set @a = "121212";
    SELECT CAST(@a AS SIGNED); // Output : 121212
    
    set @a = "Mysql is open source";
    SELECT CAST(@a AS SIGNED); // Output : 0
    

提交回复
热议问题