gpt4 book ai didi

mysql - := denote within the context of a placeholder 是什么

转载 作者:行者123 更新时间:2023-11-29 01:43:04 26 4
gpt4 key购买 nike

对于那些知道的人来说,这可能是一个愚蠢的问题,但这里是。

尝试在查询中使用占位符。我发现以下工作:

SELECT day, @dy:=CAST( CASE day
WHEN 'Su' THEN 1
WHEN 'Mo' THEN 2
WHEN 'Tu' THEN 3
WHEN 'Wed' THEN 4
WHEN 'Th' THEN 5
WHEN 'Fr' THEN 6
WHEN 'Sa' THEN 7
END AS UNSIGNED) as dayofweek
FROM `Schedule_Repetition` WHERE repetition_Key='426';

但这行不通

SELECT day, @dy=CAST( CASE day
WHEN 'Su' THEN 1
WHEN 'Mo' THEN 2
WHEN 'Tu' THEN 3
WHEN 'Wed' THEN 4
WHEN 'Th' THEN 5
WHEN 'Fr' THEN 6
WHEN 'Sa' THEN 7
END AS UNSIGNED) as dayofweek
FROM `Schedule_Repetition` WHERE repetition_Key='426';

我看到了各种各样的占位符示例,其中一些使用 @P=..... 和其他使用 @P:=...... code> 请有人解释一下 := 表示什么以及为什么语法不同,或者指出解释 := 使用的文档的方法。

最佳答案

:= 是一个 assignment operator .以下信息来自documentation在 dev.mysql.com 上。

Assignment operator. Causes the user variable on the left hand side of the operator to take on the value to its right. The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value).

=:=的区别:

= Assign a value (as part of a SET statement, or as part of the SET clause in an UPDATE statement) := Assign a value

Unlike =, the := operator is never interpreted as a comparison operator. This means you can use := in any valid SQL statement (not just in SET statements) to assign a value to a variable.

查看 full list of operators on dev.mysql.com .

关于mysql - := denote within the context of a placeholder 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14319149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com