Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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//
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading