参数化MySQL工作台语句:如何定义变量 [英] Parameterize MySQL workbench statements: How to define variables

查看:110
本文介绍了参数化MySQL工作台语句:如何定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在工作台中设置一组常用查询的参数.

I'm trying to parameterize a set of frequently used queries in my workbench.

这有效:

select * from providers where id='112233';

WbVarDef var1=112233;

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

给出错误

错误代码:1064.您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第1行的'from provider where id ='112233''处使用

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

我的参考文献是.

请注意,它们位于MySQL工作台中,而不是工作台脚本文件或mysql脚本文件中.

Just to be clear, these are in the MySQL workbench and not a workbench script file or a mysql script file.

推荐答案

在MySQL中,用于设置变量的语法如下.

In MySQL, syntax for setting variable is below.

SET @var1 = '112233';

并使用变量如下.

select * from providers where id=@var1;

查看MySQL文档以获取更多信息链接到MySQL文档

Check out MySQL documentation for more information Link to MySQL Documentation

这篇关于参数化MySQL工作台语句:如何定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆