我試圖在一個過程中使用多個選擇,但我不斷收到第18行所述的錯誤,我對存儲過程有所瞭解,所以我可以使用一些幫助至於我做錯了什麼。在MySQL中使用多個選擇時出錯存儲過程
DROP PROCEDURE IF EXISTS `WeatherRecord`;
DELIMITER //
CREATE PROCEDURE WeatherRecord(IN ID INT)
BEGIN
DECLARE Rid INT UNSIGNED;
DECLARE Rdate DATE;
DECLARE Record DECIMAL(5,2);
DECLARE c CURSOR FOR select Date, City_id, High_temp
FROM Past_weather WHERE High_temp = (
SELECT MAX(High_temp) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '1', 'HH_Temp');
close c;
DECLARE c CURSOR FOR select Date, City_id, High_temp
FROM Past_weather WHERE High_temp = (
SELECT MIN(High_temp) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '2', 'LH_Temp');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_temp
FROM Past_weather WHERE Low_temp = (
SELECT MAX(Low_temp) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '3', 'HL_Temp');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_temp
FROM Past_weather WHERE Low_temp = (
SELECT MIN(Low_temp) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '4', 'LL_Temp');
close c;
DECLARE c CURSOR FOR select Date, City_id, High_hum
FROM Past_weather WHERE High_hum = (
SELECT MIN(High_hum) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '5', 'LH_Hum');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_hum
FROM Past_weather WHERE Low_hum = (
SELECT MIN(Low_hum) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '6', 'LL_Hum');
close c;
DECLARE c CURSOR FOR select Date, City_id, High_dew
FROM Past_weather WHERE High_dew = (
SELECT MAX(High_dew) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '7', 'HH_dew');
close c;
DECLARE c CURSOR FOR select Date, City_id, High_dew
FROM Past_weather WHERE High_dew = (
SELECT MIN(High_dew) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '8', 'LH_dew');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_dew
FROM Past_weather WHERE Low_dew = (
SELECT MAX(Low_dew) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '9', 'HL_dew');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_dew
FROM Past_weather WHERE Low_dew = (
SELECT MIN(Low_dew) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '10', 'LL_dew');
close c;
DECLARE c CURSOR FOR select Date, City_id, High_ pressure
FROM Past_weather WHERE High_ pressure = (
SELECT MAX(High_pressure) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '11', 'HH_pressure');
close c;
DECLARE c CURSOR FOR select Date, City_id, High_ pressure
FROM Past_weather WHERE High_ pressure = (
SELECT MIN(High_pressure) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '12', 'LH_pressure');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_ pressure
FROM Past_weather WHERE Low_ pressure = (
SELECT MAX(Low_pressure) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '13', 'HL_pressure');
close c;
DECLARE c CURSOR FOR select Date, City_id, Low_ pressure
FROM Past_weather WHERE Low_ pressure = (
SELECT MIN(Low_pressure) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '14', 'LL_pressure');
close c;
DECLARE c CURSOR FOR select Date, City_id, Wind_max
FROM Past_weather WHERE Wind_max = (
SELECT MAX(Wind_max) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '15', 'H_wind');
close c;
DECLARE c CURSOR FOR select Date, City_id, Wind_gust
FROM Past_weather WHERE Wind_gust = (
SELECT MAX(Wind_gust) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '16', 'H_gust');
close c;
DECLARE c CURSOR FOR select Date, City_id, Rainfall
FROM Past_weather WHERE Rainfall = (
SELECT MAX(Rainfall) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '17', 'H_rainfall');
close c;
DECLARE c CURSOR FOR select Date, City_id, Snowfall
FROM Past_weather WHERE Snowfall = (
SELECT MAX(Snowfall) FROM Past_weather WHERE City_id = ID) && City_id = ID;
open c;
fetch c INTO Rdate, Rid, Record;
Insert into Weather_records(Date, City_id, Record, Record_type, Record_name)
values(Rdate, Rid, Record, '18', 'H_snowfall');
close c;
END //
DELIMITER ;
做基本調試,刪除東西,直到開始工作,然後再開始添加東西。 –
是的,這將是一個好主意 –