Difference between = and := in MySQL

萝らか妹 提交于 2020-01-05 04:58:37

问题


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);

Thanks Davide


回答1:


Quoting the MySQL 5.7 Reference Manual, section 10.4 User-Defined Variables:

For SET, either = or := can be used as the assignment operator.

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




回答2:


"=" 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 .



来源:https://stackoverflow.com/questions/37869719/difference-between-and-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!