gpt4 book ai didi

mysql - 在 MySQL 中使用 DECLARE 创建变量

转载 作者:行者123 更新时间:2023-11-29 02:23:13 25 4
gpt4 key购买 nike

我承认,我是 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 .

关于mysql - 在 MySQL 中使用 DECLARE 创建变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27846675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com