我写了以下存储过程。它工作得很好,并给出了正确的结果。但是在添加一些属性后,它会显示错误。如果我将上次检索的属性的名称更改为四个字母的单词,则它会正确运行。如果我将其作为存储过程运行,则会显示错误: “错误代码:1054。'字段列表'中的未知列'fiel'”
如果作为独立语句运行,则显示错误: “0行受影响,1警告:1260行69由GROUP_CONCAT()切断” “错误代码:1054。'字段列表'中的未知列'fiel'”
CREATE DEFINER=`root`@`localhost` PROCEDURE `getCases`()
BEGIN
SET @sql = CONCAT('SELECT ', (SELECT GROUP_CONCAT(COLUMN_NAME) FROM
information_schema.columns WHERE table_schema = 'xyz_data_base'
AND table_name = 'table1'
AND column_name NOT IN ('col_one', 'col_last')),
', table2.Name from xyz_data_base.table1, xyz_data_base.table2
where table1.col_last = table2.Id');
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
END
答案 0 :(得分:0)
在运行group_concat
之前,您必须更改系统参数group_concat_max_len
以防止结果被删除。
CREATE DEFINER=`root`@`localhost` PROCEDURE `getCases`()
BEGIN
SET @@session.group_concat_max_len = 10000;
SET @sql = CONCAT('SELECT ', (SELECT GROUP_CONCAT(COLUMN_NAME) FROM
information_schema.columns WHERE table_schema = 'xyz_data_base'
AND table_name = 'table1'
AND column_name NOT IN ('col_one', 'col_last')),
', table2.Name from xyz_data_base.table1, xyz_data_base.table2
where table1.col_last = table2.Id');
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
END