2

Não percebo porquê mas o meu código SQL está a dar erro na linha do FETCH, mais concretamente: 'FETCH NEXT FROM c_cursor INTO @idC, @LIT, @LST, @LST, @LIT;' , e eu não percebo a razão deste erro. Estou a tentar fazer um cursor para percorrer a tabela cultura (já existente) e fazer uma verficação relacionada com os campos in do procedure, mas por alguma razão aparece-me este erro: 'The procedure 'Alerta (DBA)' could not be modified in the database. Syntax error near 'FETCH' on line 14'. Se alguém conseguisse ajudar agradecia.

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

1 Resposta 1

0

Faltou o ponto-e-vírgula em

OPEN c_cursor;

Veja um exemplo aqui.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .