gpt4 book ai didi

mysql - MYSQL 中的空绑定(bind)变量

转载 作者:行者123 更新时间:2023-11-29 07:19:34 24 4
gpt4 key购买 nike

我有一个 SELECT 语句如下:

SELECT * FROM table1 WHERE column1=COALESCE(:col,column1)

当我在 MYSQL 中运行它并将 :col 绑定(bind)变量留空时,我得到一个错误。所以基本上,如果 :col 为空,查询将获取所有行,否则查询将仅获取与 :col 中的值匹配的行。

我在MYSQL窗口中运行。

The error is #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':col1,column1) LIMIT 0, 25' at line 1.

我知道这在 Oracle 中是可能的。由于我是 MYSQL 的新手,因此提出了这个问题。

最佳答案

我所要做的就是在查询之前将变量初始化为

set @col1 ='';

我再次运行查询,它返回了所需的结果。

关于mysql - MYSQL 中的空绑定(bind)变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57003350/

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