参数化 MySQL workbench 语句:如何定义变量

Parameterize MySQL workbench statements: How to define variables

我正在尝试参数化我 workbench 中的一组常用查询。

这个有效:

select * from providers where id='112233';

这个

WbVarDef var1=112233;

select * from providers where id='$[var1]';

给出错误

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from providers where id='112233'' at line 1

我的参考是 this

需要说明的是,这些在 MySQL workbench 中,而不是 workbench 脚本文件或 mysql 脚本文件中。

根据您的标签 mysql-workbench,我发现这只是引用的文档和使用与您使用的内容不相关的情况。

将层次结构从您的 link 备份到此 http://www.sql-workbench.net/

你会读到:

Please note that SQL Workbench/J has no relation to the product MySQL Workbench which is maintained and owned by Oracle. If you are looking for MySQL Workbench support please contact Oracle.

在MySQL中,设置变量的语法如下。

SET @var1 = '112233';

使用变量如下。

select * from providers where id=@var1;

查看 MySQL 文档以获取更多信息 Link to MySQL Documentation