Home > Database > Mysql Tutorial > body text

What is the difference between = and := assignment operators?

王林
Release: 2023-09-17 22:57:07
forward
1105 people have browsed it

= 和 := 赋值运算符有什么区别?

Actually, they are both assignment operators, used to assign values, but the significant differences between them are as follows-

= operator assignment is Part of a SET statement or as part of the SET clause in an UPDATE statement, and in any other case the = operator is interpreted as a comparison operator. On the other hand, the := operator assigns a value and is never interpreted as a comparison operator.

mysql> Update estimated_cost1 SET Tender_value = '8570.000' where id = 2;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> Update estimated_cost1 SET Tender_value := '8575.000' where id = 2;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Copy after login

In the above two queries, we used the = operator and the := operator to update the table values.

mysql> Set @A = 100;
Query OK, 0 rows affected (0.01 sec)

mysql> Select @A;
+------+
| @A   |
+------+
| 100  |
+------+
1 row in set (0.00 sec)

mysql> Set @B := 100;
Query OK, 0 rows affected (0.00 sec)

mysql> Select @B;
+------+
| @B   |
+------+
| 100  |
+------+
1 row in set (0.00 sec)
Copy after login

In the above two queries, we use = operator and := operator to assign values ​​to user variables. We can see that = operator and := operator have the same usage and functionality in both cases. But in the following query = operator is used as comparison operator and gives the result as "TRUE" i.e. user variables @A and @B have the same value.

mysql> Select @A = @B;
+---------+
| @A = @B |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of What is the difference between = and := assignment operators?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template