gpt4 book ai didi

mysql - 创建临时表后缺少 'end'错误

转载 作者:行者123 更新时间:2023-11-29 17:41:19 25 4
gpt4 key购买 nike

我正在创建一个存储过程,在其中我应该创建一个临时表来插入数据并在最后显示(这是一个作业,所以我必须按照指令创建临时表)。

我应该在此存储过程中使用游标。我正在创建临时表,然后创建游标。但创建表后我收到错误missing 'end'

CREATE DEFINER=`root`@`localhost` PROCEDURE `walkerMasterSummary`()

开始

DECLARE rowCount INT Default 0;
DECLARE counter INT Default 0;
DECLARE WID char(6);
DECLARE WType_WTID varchar(15);
DECLARE WUID char(6);
DECLARE BattleGroup char(5);
DECLARE CubicAreaWeight decimal(10,2);
DECLARE FuelCapacity decimal(10,2);
DECLARE FuelExpenditure_Mile decimal(10,2);
DECLARE ArmorWeight decimal(10,2);
DECLARE StructureWeight decimal(10,2);
DECLARE Status VARCHAR(20);
DECLARE CostToRepair int(10);


DROP temporary table walker_master;

CREATE temporary table walker_master(
WID char(6),
WType_WTID varchar(15),
WUID char(6),
BattleGroup char(5),
CubicAreaWeight decimal(10,2),
FuelCapacity decimal(10,2),
FuelExpenditure_Mile decimal(10,2),
ArmorWeight decimal(10,2),
StructureWeight decimal(10,2),
Status VARCHAR(20),
CostToRepair int(10)
);

DECLARE walkerMaster CURSOR FOR
SELECT IWA.WID, concat(IWA.WalkerType, " - ", IWT.WTypeID) AS WType_WTID
, IWA.WUID, WU.BattleGroup, walkerCubicAreaWeight(IWA.WalkerType) AS
CubicAreaWeight, walkerFuelCapacity(IWA.WalkerType) AS FuelCapacity
,walkerFuelExpenditure(IWA.WalkerType) AS FuelExpenditure_Mile,
walkerArmorWeight(IWA.WalkerType) AS ArmorWeight
,walkerStructureWeight(IWA.WalkerType) AS StructureWeight, IWA.Status
, CASE WHEN IWA.Status = 'Damaged' AND IWA.WalkerType = 'AT-AT' THEN 122
* IWT.Weight
WHEN IWA.Status = 'Damaged' AND IWA.WalkerType = 'AT-ST' THEN 89 *
IWT.Weight
ELSE 0 END AS CostToRepair
FROM imperial_walkers_assign IWA
LEFT JOIN imperial_walker_type IWT ON IWA.WalkerType = IWT.WType
LEFT JOIN walker_units WU ON IWA.WUID=WU.WUID
ORDER BY IWA.WID;

OPEN walkerMaster;
BEGIN
SELECT Found_Rows() INTO rowCount;
process_loop : loop
IF counter < rowCount THEN
FETCH walkerMaster INTO WID ,WType_WTID, WUID, BattleGroup,
CubicAreaWeight, FuelCapacity,
FuelExpenditure_Mile, ArmorWeight, StructureWeight,Status, CostToRepair;
/* DROP temporary table walker_summary;
CREATE temporary table walker_summary AS SELECT WID ,WType_WTID,WUID,
BattleGroup, CubicAreaWeight, FuelCapacity,
FuelExpenditure_Mile, ArmorWeight, StructureWeight,Status, CostToRepair;*/
SELECT WID ,WType_WTID, WUID, BattleGroup, CubicAreaWeight, FuelCapacity,
FuelExpenditure_Mile, ArmorWeight, StructureWeight,Status, CostToRepair;
SET counter = counter +1;
ELSE
leave process_loop;
END IF;
END loop process_loop;
END;
CLOSE walkerMaster;

END

我没有删除临时表或游标的选项。我应该如何修复这个错误?

最佳答案

游标的声明应该在创建临时表之前

我还取消了插入临时表的代码的注释

DECLARE rowCount INT Default 0;
DECLARE counter INT Default 0;
DECLARE WID char(6);
DECLARE WType_WTID varchar(15);
DECLARE WUID char(6);
DECLARE BattleGroup char(5);
DECLARE CubicAreaWeight decimal(10,2);
DECLARE FuelCapacity decimal(10,2);
DECLARE FuelExpenditure_Mile decimal(10,2);
DECLARE ArmorWeight decimal(10,2);
DECLARE StructureWeight decimal(10,2);
DECLARE Status VARCHAR(20);
DECLARE CostToRepair int(10);

DECLARE walkerMaster CURSOR FOR
SELECT IWA.WID, concat(IWA.WalkerType, " - ", IWT.WTypeID) AS WType_WTID
, IWA.WUID, WU.BattleGroup, walkerCubicAreaWeight(IWA.WalkerType) AS
CubicAreaWeight, walkerFuelCapacity(IWA.WalkerType) AS FuelCapacity
,walkerFuelExpenditure(IWA.WalkerType) AS FuelExpenditure_Mile,
walkerArmorWeight(IWA.WalkerType) AS ArmorWeight
,walkerStructureWeight(IWA.WalkerType) AS StructureWeight, IWA.Status
, CASE WHEN IWA.Status = 'Damaged' AND IWA.WalkerType = 'AT-AT' THEN 122
* IWT.Weight
WHEN IWA.Status = 'Damaged' AND IWA.WalkerType = 'AT-ST' THEN 89 *
IWT.Weight
ELSE 0 END AS CostToRepair
FROM imperial_walkers_assign IWA
LEFT JOIN imperial_walker_type IWT ON IWA.WalkerType = IWT.WType
LEFT JOIN walker_units WU ON IWA.WUID=WU.WUID
ORDER BY IWA.WID;

DROP temporary table walker_master;

CREATE temporary table walker_master(
WID char(6),
WType_WTID varchar(15),
WUID char(6),
BattleGroup char(5),
CubicAreaWeight decimal(10,2),
FuelCapacity decimal(10,2),
FuelExpenditure_Mile decimal(10,2),
ArmorWeight decimal(10,2),
StructureWeight decimal(10,2),
Status VARCHAR(20),
CostToRepair int(10)
);



OPEN walkerMaster;
BEGIN
SELECT Found_Rows() INTO rowCount;
process_loop : loop
IF counter < rowCount THEN
FETCH walkerMaster INTO WID ,WType_WTID, WUID, BattleGroup,
CubicAreaWeight, FuelCapacity,
FuelExpenditure_Mile, ArmorWeight, StructureWeight,Status, CostToRepair;

insert into walker_summary (WID,WType_WTID,WUID,BattleGroup,CubicAreaWeight,FuelCapacity,FuelExpenditure_Mile,ArmorWeight,StructureWeight,
StructureWeight,Status,CostToRepair)
SELECT WID ,WType_WTID,WUID,
BattleGroup, CubicAreaWeight, FuelCapacity,
FuelExpenditure_Mile, ArmorWeight, StructureWeight,Status, CostToRepair;
SELECT WID ,WType_WTID, WUID, BattleGroup, CubicAreaWeight, FuelCapacity,
FuelExpenditure_Mile, ArmorWeight, StructureWeight,Status, CostToRepair;
SET counter = counter +1;
ELSE
leave process_loop;
END IF;
END loop process_loop;
END;
CLOSE walkerMaster;

END

关于mysql - 创建临时表后缺少 'end'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49993881/

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