Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

"#1064 - 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 'CREATE FUNCTION TavoliLiberi (dataora DATETIME) RETURN BOOL BEGIN DECLARE prese' at line 3" in this function:

DELIMITER $

DROP FUNCTION IF EXISTS TavoliLiberi;

CREATE FUNCTION TavoliLiberi (dataora DATETIME) RETURN BOOL
BEGIN
DECLARE presenti BOOL;
DECLARE numPrenotazioni INT;
DECLARE numTavoli INT;

SELECT COUNT(*) INTO numPrenotazioni
FROM Prenotazioni
WHERE DataOra = dataora;

SELECT COUNT(*) INTO numTavoli
FROM Tavoli;

IF (numPrenotazioni < numTavoli) THEN
    SET presenti = TRUE;
ELSE
    SET presenti = FALSE;
END IF;

RETURN presenti;
END $

DELIMITER ;

What's wrong?

share|improve this question

closed as too localized by Jocelyn, Ja͢ck, tereško, hakre, fancyPants Jun 12 '13 at 11:35

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

Looks like your delimiter preference is set in the wrong place. Try the following:

DROP FUNCTION IF EXISTS TavoliLiberi;

DELIMITER $

CREATE FUNCTION TavoliLiberi (dataora DATETIME) RETURN BOOL
....
....
share|improve this answer
    
In the function declaration is RETURNS not RETURN "CREATE FUNCTION TavoliLiberi (dataora DATETIME) RETURNS BOOL". –  Luis G. Costantini R. Jun 4 '13 at 18:04
    
[SOLVED] The problem was the "RETURN" instead of "RETURNS" like Luis G. Costantini R. suggest me, but only uploading it from terminal and not importing it with phpMyAdmin, it was processed correctly. –  Giacomo Jun 5 '13 at 8:11

Your delimiter changes try this instead

DELIMITER $

DROP FUNCTION IF EXISTS TavoliLiberi$

keep the rest the same

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.