MySQL 查询中输入参数的语法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7324560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:01:07  来源:igfitidea点击:

Syntax for input parameters in a MySQL query

mysqlsql

提问by Simon

We recently switched a database from MSSQL to MySQL and the queries that uses parameters does'nt work anymore.

我们最近将数据库从 MSSQL 切换到 MySQL,并且使用参数的查询不再有效。

Here's an example of a query in MSSQL:

以下是 MSSQL 中的查询示例:

SELECT * FROM users u WHERE u.ID = :id

Normally, the parameter browser would popup and ask me for a value for :id, but in MySQL I get this error :

通常,参数浏览器会弹出并要求我输入 :id 的值,但在 MySQL 中我收到此错误:

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 ':id'

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 ':id' 附近使用的正确语法

I tried using a @ or ? instead of : and it does'nt work.

我尝试使用 @ 或 ? 而不是 : 它不起作用。

Thanks in advance for the help.

在此先感谢您的帮助。

回答by ajreal

syntax is not the same

语法不一样

set @id:=123;
SELECT * FROM users u WHERE u.ID = @id;

Docs for User defined variables

用户定义变量的文档