Is there a difference between @var := 0; and @var = 0; ?
@var:= 0之间有区别吗?和@var = 0; ?
With and without the colon? What does that do?
有没有结肠?那是做什么的?
1 个解决方案
#1
3
In the case of SET, they are synonymous:
在SET的情况下,它们是同义词:
SET @var := 1234;
SET @var = 1234;
But =
acts as a conditional operator when used in a SELECT
:
但是当在SELECT中使用时,=充当条件运算符:
SELECT @var := 1234; -- 1234
SELECT @var = 1234; -- 1
So it's generally best to stick to :=
for assignment to avoid confusion.
因此,通常最好坚持:=进行分配以避免混淆。
#1
3
In the case of SET, they are synonymous:
在SET的情况下,它们是同义词:
SET @var := 1234;
SET @var = 1234;
But =
acts as a conditional operator when used in a SELECT
:
但是当在SELECT中使用时,=充当条件运算符:
SELECT @var := 1234; -- 1234
SELECT @var = 1234; -- 1
So it's generally best to stick to :=
for assignment to avoid confusion.
因此,通常最好坚持:=进行分配以避免混淆。