'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.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pcsutar |
