Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用DECLARE在MySQL中创建变量_Mysql_Variables - Fatal编程技术网

使用DECLARE在MySQL中创建变量

使用DECLARE在MySQL中创建变量,mysql,variables,Mysql,Variables,我承认,我是一个T-SQL的家伙,不是MySQL的家伙,但我不太明白为什么我会收到这个错误消息: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @UpdatedID VARCHAR(5)' at line 1 我的问题是: DECLARE

我承认,我是一个T-SQL的家伙,不是MySQL的家伙,但我不太明白为什么我会收到这个错误消息:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @UpdatedID VARCHAR(5)' at line 1 
我的问题是:

DECLARE @UpdatedID VARCHAR(5);

SET @UpdatedID = 63;

CREATE TABLE tmp_markers (SELECT * FROM tmp_markers2);

UPDATE tmp_markers
SET Id = Id+1
WHERE Id >= @UpdatedID;

UPDATE tmp_markers
SET Id = @UpdatedID
WHERE Id = MAX(Id);

DELETE from tmp_markers2;

INSERT INTO tmp_markers2
(SELECT * FROM tmp_markers ORDER BY id);

DROP TABLE tmp_markers

在MySQL中声明变量的操作与您使用的操作相同:

SET @UpdatedID = 63;
DECLARE
语句用于存储过程中。请参阅。

在没有存储例程/函数作用域的情况下,无法按照您指定的方式“声明”变量。