Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameterize MySQL workbench statements: How to define variables

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.

like image 368
Kashyap Avatar asked Dec 15 '15 16:12

Kashyap


2 Answers

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

like image 175
cyber.sh Avatar answered Sep 18 '22 13:09

cyber.sh


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.

like image 42
Drew Avatar answered Sep 17 '22 13:09

Drew