Come MySQL fix Crea query FUNZIONE?
-
24-10-2019 - |
Domanda
voglio aggiungere la funzione mysql:
CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT)
RETURNS text CHARSET utf8
BEGIN
DECLARE translation TEXT;
SELECT title
INTO translation
FROM chf_translations
WHERE key_id = translation_id
AND lang_id = site_lang;
RETURN translation;
END
Ma ottenere errore:
1064 - Hai un errore nella sintassi SQL; controllare il manuale che corrisponde alla vostra versione del server MySQL per la sintassi del diritto di utilizzare vicino a '' at line 3
Soluzione
Prova ...
DELIMITER $$
CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT)
RETURNS text CHARSET utf8
BEGIN
DECLARE translation TEXT;
SELECT title
INTO translation
FROM chf_translations
WHERE key_id = translation_id
AND lang_id = site_lang;
RETURN translation;
END$$
Altri suggerimenti
DELIMITER $
CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT)
RETURNS text CHARSET utf8
DETERMINISTIC
BEGIN
DECLARE translation TEXT;
SELECT title
INTO translation
FROM chf_translations
WHERE key_id = translation_id
AND lang_id = site_lang;
RETURN translation;
END$
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow