0

我想添加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

但得到错误:

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的 '' 附近使用正确的语法

4

2 回答 2

5

尝试...

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$$
于 2010-06-03T15:39:00.330 回答
2
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$
于 2011-12-29T13:27:40.890 回答