I’ve made this function but no matter what I add (delimiters) it’s still throwing the same error.
CREATE FUNCTION getNumberOfBuyers(IN userId INT) RETURNS INT
BEGIN
DECLARE numberOfBuyers INT DEFAULT 0;
SELECT COUNT(*) INTO numberOfBuyers FROM buyers WHERE id = userId;
RETURN numberOfBuyers;
END;
The error is:
[42000][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 ‘IN userId INT) RETURNS INT BEGIN DECLARE numberOfBuyers
INT DEFAULT 0; …’ at line 1
>Solution :
There is no possibility to mark parameter as input parameter in mariadb. So remove the IN in the declaration:
CREATE FUNCTION getNumberOfBuyers(userId INT) RETURNS INT
BEGIN
DECLARE numberOfBuyers INT DEFAULT 0;
SELECT COUNT(*) INTO numberOfBuyers FROM buyers WHERE id = userId;
RETURN numberOfBuyers;
END;
The general syntax declaration looks like:
CREATE FUNCTION function_name [ (parameter datatype [, parameter datatype]) ]
RETURNS return_datatype
BEGIN
declaration_section
executable_section
END;