本文介绍了声明变量语法在MySQL Workbench中无效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建和设置变量:
I am trying to create and set a variable:
DECLARE myId INT;
SET myId = 5;
但是,我在MySQL Workbench中收到无效的语法投诉:
However, I am getting invalid syntax complaint in MySQL Workbench:
我尝试了以下变体:
DECLARE myId INT(4);
SET myId = 5;
DECLARE @myId INT;
SET @myId = 5;
DECLARE @myId INT(4);
SET @myId = 5;
怎么了?
推荐答案
正如评论中所说,声明仅对诸如过程,函数之类的存储程序有效.这里有一个存储过程及其调用的示例.
As in the comment says Declare is only valid into stored programs like procedures, functions.here you have an example of a store procedure and its call.
DELIMITER $$
CREATE PROCEDURE sp1 (x VARCHAR(5))
BEGIN
DECLARE xname VARCHAR(5) DEFAULT 'bob';
DECLARE myId INT;
SET myId = 5;
SELECT CONCAT(xname,' -- ',myId);
END;
$$
DELIMITER ;
call sp1('MY NAME');
这篇关于声明变量语法在MySQL Workbench中无效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!