我使用以下代码在MySQL中创建了一个过程:
delimiter #
drop procedure if exists a03_strings #
create procedure a03_strings ()
begin
select concat(cl_id, ' ',cl_name_last, ', ', cl_name_first) as Client
, group_concat(coalesce(concat(an_name, ' (', an_type, ')'), 'no animals')) as Animals
from vt_clients
left join vt_animals using (cl_id)
group by cl_id\G;
end;
#我在第9行添加了\G,以获得以下输出:

因此,输出不是表,而是行。
当我将其作为select语句进行测试时,它适用于\G。但是,当我在过程中包含\G时,它告诉我错误,我不能将一个过程包含在另一个过程中。
有没有替代方案来实现我需要的输出?
谢谢!
发布于 2014-01-26 07:53:59
简短的回答是否定的:'\G‘是由mysql客户机处理的,而不是由DBMS (存储过程运行的地方)处理的。但您可以简单地:
mysql> create procedure a03_strings ()
-> begin
-> select concat(cl_id, ' ',cl_name_last, ', ', cl_name_first) as Client
-> , group_concat(coalesce(concat(an_name, ' (', an_type, ')'), 'no animals')) as Animals
-> from vt_clients
-> left join vt_animals using (cl_id)
-> group by cl_id\G;
-> end;
-> #
...
mysql-> call a03strings() \G#或者使用这个作为您的选择...
SELECT IF (rowselect='A',
CONCAT('Client: ', ilv.Client),
CONCAT('Animals', ilv.Animals)
FROM (
select concat(cl_id, ' ',cl_name_last, ', ', cl_name_first) as Client
, group_concat(coalesce(concat(an_name, ' (', an_type, ')'), 'no animals')) as Animals
from vt_clients
left join vt_animals using (cl_id)
group by cl_id
) ilv,
(SELECT 'A' AS rowselect UNION SELECT 'B') AS rowmultiplierhttps://stackoverflow.com/questions/21356998
复制相似问题