如何修复 MySQL CREATE FUNCTION 查询?

发布于 2024-09-04 06:12:45 字数 456 浏览 14 评论 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 行 '' 附近使用的正确语法

I want to add mysql function:

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

But get error:

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 '' at line 3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤浅笑 2024-09-11 06:12:45

尝试...

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$

Try...

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$
云淡月浅 2024-09-11 06:12:45
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$
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$
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文