Parameterize MySQL workbench statements: How to define variables

放肆的年华 提交于 2019-12-10 13:53:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!