1
DELIMITER // 

CREATE FUNCTION total_cost_for_customer (
    custNumber INT
)
RETURNS INT
DETERMINISTIC
READS SQL DATA
BEGIN
    DECLARE total INT;

    SELECT SUM(unitPrice)
    INTO total
    FROM OrderLine
    WHERE orderNo IN (
        SELECT orderNo
        FROM FoodOrder
        WHERE custNo = custNumber
    );

    RETURN total;
END //

DELIMITER ;

SQL Error [1064] [42000]: (conn=18) 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 8

Line 8 would be the DECLARE statement.

New contributor
Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
10
  • hmm, this looks correct to me, and I could even run it. Are you mixing up error-messages of different functions? Are you running some old version of your script because it is somehow not saved? Commented 2 days ago
  • maybe whatever it is you use to run this doesn't correctly send the DELIMITER // ? Commented 2 days ago
  • Yea its super weird. I just made a new sql script and tried to run it with the function as the only thing in the file, but it still throws the error. I just tried to change it but throws an error at the end of the return ); DELIMITER // CREATE FUNCTION total_cost_for_customer ( custNumber INT ) RETURNS INT DETERMINISTIC READS SQL DATA BEGIN RETURN ( SELECT SUM(unitPrice) FROM OrderLine WHERE orderNo IN ( SELECT orderNo FROM FoodOrder WHERE custNo = custNumber ) ); END // DELIMITER ; Commented 2 days ago
  • 2
    Please take a look here: stackoverflow.com/questions/63850520/… Commented 2 days ago
  • 2
    No need to feel like that. You have struggled with a technicality and needed help. This is what SO is for. You will need to keep in mind that the more details you give, the earlier we can help you. Commented 2 days ago

1 Answer 1

1

The problem was not running the entire script with DBeaver. You have to click the "Execute SQL Script" (The third form the top) button. The "Execute SQL Query" (top button) is not sufficient enough.

enter image description here

Another fix i found is to select the appropriate queries you would like to run and pressing ALT + X. This will run all the queries you have marked. (Got this method from https://stackoverflow.com/a/66975906/16506006 )

enter image description here

New contributor
Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.