使用 DECLARE 在 MySQL 中创建变量
Using DECLARE to create variable in MySQL
我承认,我是 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
语句用于存储过程中。参见 this。
我承认,我是 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
语句用于存储过程中。参见 this。