How to set values to variable using SET
in MySql
?
Asked
Active
Viewed 51 times
1 Answers
1
You don't need to declare the user defined variables, you can just SET
them as you have in your question.
Once variable is set you can refer to it in SELECT or other statements, for example:
SELECT @_achat_loc;
+-------------+
| @_achat_loc |
+-------------+
| achat |
+-------------+
1 row in set (0.00 sec)
or
UPDATE a SET b=@_achat_loc;

vhu
- 12,244
- 11
- 38
- 48
-
But is it correct how i have set to set values using SET ? – Mayur Patel Jun 30 '15 at 06:23
-
@Mayur, yes, see here for details: http://stackoverflow.com/questions/1009954/mysql-variable-vs-variable-whats-the-difference – vhu Jun 30 '15 at 06:26
-
Ok i am confused that where to use double Quot Single Quot or no Quot ? – Mayur Patel Jun 30 '15 at 06:29
-
You need to use single quotes if ANSI_QUOTES has been enabled. See here for more information regarding the quotes: https://dev.mysql.com/doc/refman/5.1/en/string-literals.html and http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks – vhu Jun 30 '15 at 06:34