我有一个mysql函数,有两个参数,即user\u id和post\u id
我的职责是:
CREATE FUNCTION isliked(pid INT, uid INT)
RETURN TABLE
AS
RETURN (EXISTS (SELECT 1 FROM likedata ld WHERE post_id = pid AND user_id = uid
)) as is_liked
END
我试着用下面的问题来称呼它:
SELECT posts.id, posts.title, isliked(111,123)
FROM posts
它返回以下错误:
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 'RETURN TABLE
AS
RETURN (EXISTS (SELECT 1 FROM likedata ld WHERE post_id = pid AN' at line 2
应该是这样的返回结果http://sqlfiddle.com/#!9/91040/5我是sql新手,任何帮助都会很好,提前谢谢
1条答案
按热度按时间9rygscc11#
如果希望函数返回布尔值,请使用: