D
D
DenVilmont2021-09-29 11:00:52
MySQL
DenVilmont, 2021-09-29 11:00:52

The procedure is not created, what causes the error?

I am learning MySQL. I cannot create procedure and I do not understand why. Tell me please.

create procedure SumarNumerosParesConsecutivosHastaMaximo (IN maximo int)
BEGIN
  declare i int;
  declare suma int;
  set i = 2;
  set suma = 0;
  IF (maximo < 0) THEN
    select concat('ERROR') Mensaje;
  ELSE
    while (i <= maximo) do
      if (mod(maximo,2) = 0) then 
        set suma = suma + i;
        set i = i + 2;
        select concat('El resultado de suma es ', suma) Resultado;
      esleif (mod(maximo,2) <> 0) then
        set suma = suma + i;
        set i = i + 2;
        select concat('El resultado de suma es ', suma) Resultado;
      end if;
    end while;
  end if;
end

61541d1603318318260198.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-09-29
@DenVilmont

Since you are not redefining the delimiter, your query ends at the first semicolon encountered.

DELIMITER $$
CREATE PROCEDURE ...
...
END$$
DELIMITER ;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question