Błędy podczas tworzenia funkcji w mysql

0

Usiłuję utworzyć funkcję w mysql. Kombinuję na różne sposoby, nawet jak wycinam różne fragmenty to i tak mi błędami sypie. Pytanie czy mam faktycznie błędy w sql czy mój DbVisualizer mi coś miesza?

CREATE FUNCTION has_any_priv_to_survey(user_id bigint(20) ,survey_id bigint(20)) RETURNS bool
BEGIN
    DECLARE has_privs bool;
    SET has_privs = 0;
    IF EXISTS (SELECT 1 FROM users u JOIN surveys s ON u.library_id = s.library_id WHERE u.id = @user_id AND s.id = @survey_id)    
    OR EXISTS (SELECT 1 FROM privs_all_view WHERE user_id = @user_id AND to_id = @survey_id and type_id=4)
        THEN SET has_privs = 1;
        ELSE SET has_privs = 0;
    END IF
    RETURN @has_privs;
END

Błędy:

 18:28:11  [CREATE - 0 row(s), 0.000 secs]  [Error Code: 1064, SQL State: 42000]  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 3
 18:28:11  [SET - 0 row(s), 0.000 secs]  [Error Code: 1193, SQL State: HY000]  Unknown system variable 'has_privs'
 18:28:11  [IF - 0 row(s), 0.000 secs]  [Error Code: 1064, SQL State: 42000]  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 'IF EXISTS (SELECT 1 FROM users u JOIN surveys s ON u.library_id = s.library_id W' at line 1
 18:28:11  [ELSE - 0 row(s), 0.000 secs]  [Error Code: 1064, SQL State: 42000]  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 'ELSE SET has_privs = 0' at line 1
 18:28:11  [END - 0 row(s), 0.000 secs]  [Error Code: 1064, SQL State: 42000]  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 'END IF
    RETURN @has_privs' at line 1
 18:28:11  [END - 0 row(s), 0.000 secs]  [Error Code: 1064, SQL State: 42000]  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 'END' at line 1
1

A tak:

CREATE FUNCTION has_any_priv_to_survey(user_id BIGINT(20) ,survey_id BIGINT(20)) RETURNS bool
READS SQL DATA
BEGIN
...

??

0

Dodałem READS SQL DATA i wyrzuciłem małpy. Rezultat bez zmian.
EDIT:
Nareszcie znalazłem gdzieś w zakamarkach internetu. Problem leżał po stronie klienta w moim przypadku DbVisualizer. Trzeba było dodać na początku i na końcu slash:

--/  <--tu
CREATE FUNCTION func()
BEGIN
(...)
END
/  <-- i tu

Dzięki za odpowiedź. Pozdrawiam.

1 użytkowników online, w tym zalogowanych: 0, gości: 1