Home > Enterprise >  I Have an error in MySQL. Show me a syntaxt error in my query
I Have an error in MySQL. Show me a syntaxt error in my query

Time:04-23

I have this query in MySQL

create function is_prime(num int) returns boolean
begin
    declare cont;
    set cont = 2;

    while(cont != num) do
        if (num % cont = 0) then
            return false;
        end if;
        cont = cont   1;
    end while;

    return true;
end//

VSCode show a syntaxt error. I have checked each line but i dont look the error. Thanks and sorry for my english.

CodePudding user response:

Declaration has to have a datatype

Also you forgot to Set the increase

DELIMITER //
create function is_prime(num int) returns boolean
begin
    declare cont INTEGER;
    set cont = 2;

    while(cont != num) do
        if (num % cont = 0) then
            return false;
        end if;
        SET cont := cont   1;
    end while;

    return true;
end//
  • Related