Problems with SQL and cursor

2

I do not understand why but my SQL code is giving error in the FETCH line, namely: 'FETCH NEXT FROM c_cursor INTO @idC, @LIT, @LST, @LST, @LIT;' , and I do not understand the reason for this error. I'm trying to make a cursor to go through the (already existing) culture table and do a check related to the in fields of the procedure, but for some reason this error appears to me: 'The DBA procedure' could not be modified in the database. Syntax error near 'FETCH' on line 14 '. If anyone could help, thank you.

ALTER PROCEDURE "DBA"."Alerta"(IN Temperatura DECIMAL, IN Humidade DECIMAL)
BEGIN

DECLARE @idC INTEGER;
DECLARE @LIT DECIMAL;
Declare @LST DECIMAL;
DECLARE @LSH DECIMAL;
DECLARE @LIH DECIMAL;


DECLARE c_cursor CURSOR FOR 
SELECT IDCultura, LimiteInferiorTemperatura, LimiteSuperiorTemperatura, LimiteSuperiorHumidade, LimiteInferiorHumidade FROM Cultura;
OPEN c_cursor 
FETCH NEXT FROM c_cursor INTO @idC, @LIT, @LST, @LST, @LIT;

WHILE @@FETCH_STATUS = 0
BEGIN;
    IF (@LST < new_temp.ValorMedicaoTemperatura OR new_temp.ValorMedicaoTemperatura > @LIT)
        INSERT INTO Alertas(IDAlerta, DataMedicao, ValorMedicao, NomeVariavel, IDCultura)
        VALUES 
        (now(), new_temp.ValorMedicaoTemperatura, 'Temp', @idC); 

    IF (@LSH < new_temp.ValorMedicaoHumidade OR new_temp.ValorMedicaoHumidade > @LIH)
        INSERT INTO Alertas(IDAlerta, DataMedicao, ValorMedicao, NomeVariavel, IDCultura)
        VALUES 
        (now(), new_temp.ValorMedicaoHumidade, 'Hum', @idC); 

    FETCH NEXT FROM c_cursor INTO @idC, @LIT, @LST, @LST, @LIT;

END;
CLOSE c_cursor;
DEALLOCATE c_cursor;

END

    
asked by anonymous 02.06.2018 / 19:10

1 answer

0

The semicolon was missing at

OPEN c_cursor;

See an example here .

    
02.06.2018 / 21:46