简体   繁体   English

MySQL中=和:=之间的区别

[英]Difference between = and := in MySQL

in MySQL what is the difference between these two command? MySQL这两个命令有什么区别?

They work perfectly and the result is always the same: 它们工作完美,结果始终相同:

set @numRecords = (select count(*) from config);

set @numRecords := (select count(*) from config);

Thanks Davide 谢谢戴维德

Quoting the MySQL 5.7 Reference Manual, section 10.4 User-Defined Variables : 引用《 MySQL 5.7参考手册》 第10.4节“用户定义的变量”

For SET, either = or := can be used as the assignment operator. 对于SET,可以将=或:=用作赋值运算符。

You can also assign a value to a user variable in statements other than SET. 您还可以在SET以外的语句中为用户变量分配值。 In this case, the assignment operator must be := and not = because the latter is treated as the comparison operator = in non-SET statements 在这种情况下,赋值运算符必须为:=而不是=,因为后者在非SET语句中被视为比较运算符=

"=" is ambiguous and could be a comparison operator. “ =”含糊不清,可能是比较运算符。 ":=" is always interpreted as an assignment operator. “:=”始终被解释为赋值运算符。 This information can be found at http://dev.mysql.com/doc/refman/5.7/en/assignment-operators.html . 可以在http://dev.mysql.com/doc/refman/5.7/en/assignment-operators.html上找到此信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM