0

我想在 MySQL 中创建一个存储函数。这个函数必须包含一个 group_concat 函数。

这是我当前的 SQL 查询:

DELIMITER $$
CREATE FUNCTION SprachenListe(
paramTable VARCHAR( 50 )
) RETURNS TEXT DETERMINISTIC BEGIN 
DECLARE Ausgabe TEXT;
SET @tableName = paramTable;
EXECUTE IMMEDIATE CONCAT('SELECT GROUP_CONCAT( DISTINCT ', @tableName.Sprache, ' ORDER
BY ',@tableName.Sprache,' SEPARATOR  ','/',' ) INTO ',Ausgabe,' FROM ',@tableName);
RETURN(Ausgabe);
END ;
$$
DELIMITER ;

这是错误消息:

#1064 - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 6 行的 'CONCAT('SELECT GROUP_CONCAT( DISTINCT ', @tableName.Sprache, ' ORDER BY ',@table' 附近使用正确的语法

有人有想法吗?

4

1 回答 1

0

You are trying to use dynamic SQL, which in MySQL is done using prepared statements, with PREPARE followed by EXECUTE.... however, in MySQL, these are only supported in stored procedures, not stored functions.

SQL syntax for prepared statements can be used within stored procedures, but not in stored functions or triggers.

http://dev.mysql.com/doc/refman/5.6/en/sql-syntax-prepared-statements.html

于 2013-09-26T19:42:23.290 回答