问题
I'm trying to parameterize a set of frequently used queries in my workbench.
This works:
select * from providers where id='112233';
This
WbVarDef var1=112233;
select * from providers where id='$[var1]';
gives error
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
My reference was this.
Just to be clear, these are in the MySQL workbench and not a workbench script file or a mysql script file.
回答1:
In MySQL, syntax for setting variable is below.
SET @var1 = '112233';
and using the variable would be as below.
select * from providers where id=@var1;
Check out MySQL documentation for more information Link to MySQL Documentation
回答2:
Based on your tag mysql-workbench
, I find it simply to be a case where the referenced documentation and use is not relevant to what you are using.
Back up the hierarchy from your link to this http://www.sql-workbench.net/
and you will read:
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.
来源:https://stackoverflow.com/questions/34294844/parameterize-mysql-workbench-statements-how-to-define-variables