使用DECLARE在MySQL中创建变量

时间:2015-01-08 18:04:12

标签: 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 @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

1 个答案:

答案 0 :(得分:2)

在MySQL中声明一个变量是用你所做的:

完成的
SET @UpdatedID = 63;

DECLARE语句用于存储过程。请参阅this