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

MariaDB syntax error when using IF statements

I’m trying to create a stored procedure in MariaDB using the code below.

DELIMITER //
CREATE PROCEDURE P5();
BEGIN
IF 1=1 THEN
    SELECT 1;
END IF;
END//

When I run the code, I receive a syntax error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ';

BEGIN
IF 1=1 THEN
    SELECT 1;
END IF;
END' at line 1

I realise that I could use an IF () function in this case, but I need to be able to use IF statements.

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 :

No need of adding semicolon after procedure name.

DELIMITER //
CREATE PROCEDURE P5()
BEGIN
IF 1=1 THEN
    SELECT 1;
END IF;
END//

Check db fiddle

Refer: MySQL Docs

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