0

I tried with various version but I am getting the same error message while creating user define functions like this

CREATE FUNCTION avg_month(shop INT) RETURNS DECIMAL
BEGIN
DECLARE
    avg_m_sales DECIMAL;
SET
    avg_m_sales = 1000; 
RETURN avg_m_sales;
END;  

The error message is:

Error SQL query:

CREATE FUNCTION avg_month(shop INT) RETURNS DECIMAL
BEGIN
DECLARE
    avg_m_sales DECIMAL

MySQL said: Documentation

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 '' at line 4

1 Answer 1

1

Delimiters other than the default ; are typically used when defining functions, stored procedures, and triggers wherein you must define multiple statements.

Try to create below way. "testdb" is you database name.

DELIMITER $$

CREATE

    FUNCTION `testdb`.`avg_month`(shop INT)
    RETURNS DECIMAL

    BEGIN
DECLARE
    avg_m_sales DECIMAL;
SET
    avg_m_sales = 1000; 
RETURN avg_m_sales;
    END$$

DELIMITER ;
Sign up to request clarification or add additional context in comments.

1 Comment

some explanation of why this works would help anyone else visiting this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.