MySQL 中 = 和 := 的区别 [英] Difference between = and := in MySQL
本文介绍了MySQL 中 = 和 := 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MySQL
中这两个命令有什么区别?
in MySQL
what is the difference between these two command?
它们工作得很好,结果总是一样的:
They work perfectly and the result is always the same:
set @numRecords = (select count(*) from config);
set @numRecords := (select count(*) from config);
谢谢大卫
推荐答案
引用 MySQL 5.7 参考手册,第 10.4 节用户定义的变量:
Quoting the MySQL 5.7 Reference Manual, section 10.4 User-Defined Variables:
对于 SET,可以使用 = 或 := 作为赋值运算符.
For SET, either = or := can be used as the assignment operator.
您还可以在其他语句中为用户变量赋值比SET.在这种情况下,赋值运算符必须是 := 而不是 =因为后者在非 SET 中被视为比较运算符 =声明
You can also assign a value to a user variable in statements other than SET. In this case, the assignment operator must be := and not = because the latter is treated as the comparison operator = in non-SET statements
这篇关于MySQL 中 = 和 := 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文