If I define a variable like set @a = "1";
. How can I see that @a is a string?
views:
90answers:
2
+2
A:
Since variables have to declared up front with a specific type, you should already know that @a is a string. But obviously there is more going on here. What are you trying to accomplish with this?
Joel Coehoorn
2009-08-03 16:15:14
This is mostly for debugging purposes. There's a stored proc setting an out variable and I just want to ensure everything is being set accordingly. You're right though, the SP declares the data type up front. I guess I was confused by the ability to just say @this = "that" without specifying a type in the CLI client.
Adam B
2009-08-03 16:27:31
@Joel Coehoorn - I think there may be some confusion here. MySQL allows for variables to be set without an explicit type so there's no requirement to define the type up front. This is unlike TSQL where you declare variable stating the type. Maybe you assumed this was a TSQL question?
Ben Griswold
2009-08-03 17:13:24
+3
A:
You cannot determine the type of a variable in MySQL.
As an alternative, you can easily CAST()
your variable in the type you desire:
@a = CAST(123 AS CHAR);
More information and examples about casting in the MySQL Manual:
Andrew Moore
2009-08-03 16:21:50