0

I'm trying to create a store procedure, but it throws me an error every time I try to run the code:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10

This is the store procedure I'm trying to create:

CREATE DEFINER=`root`@`localhost` PROCEDURE getMantencionByPlate(
    xParam char(10),
    xParam2 char(10)
)
BEGIN
    SELECT DISTINCT 
        *
    FROM mantenciones
    WHERE ifnull(estado,'')<>'ELIMINADO' and brainbox=xParam and patente=xParam2
    ORDER BY fecing desc;

END
DELIMITER ;
  • 2
    The default delimiter is `;`, your code ends after `ORDER BY fecing desc` and the [compound statement](https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-compound-statements.html) is incomplete. https://dev.mysql.com/doc/refman/5.7/en/stored-programs-defining.html – axiac Sep 04 '17 at 13:34
  • Thanks, solved it by adding **DELIMITER ;;** at the beginning and **END;;**. – Gabriel Alejandro Sep 04 '17 at 13:41

1 Answers1

0

Try to add DELIMITER $$ in top of query, like that:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE getMantencionByPlate(
    xParam char(10),
    xParam2 char(10)
)
BEGIN
    SELECT DISTINCT 
        *
    FROM mantenciones
    WHERE ifnull(estado,'')<>'ELIMINADO' and brainbox=xParam and patente=xParam2
    ORDER BY fecing desc;

END $$
DELIMITER ;