首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL:如何在过程中包含'\G‘

问MySQL:如何在过程中包含'\G‘
EN

Stack Overflow用户
提问于 2014-01-26 06:21:10
回答 1查看 205关注 0票数 0

我使用以下代码在MySQL中创建了一个过程:

代码语言:javascript
复制
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时,它告诉我错误,我不能将一个过程包含在另一个过程中。

有没有替代方案来实现我需要的输出?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-01-26 07:53:59

简短的回答是否定的:'\G‘是由mysql客户机处理的,而不是由DBMS (存储过程运行的地方)处理的。但您可以简单地:

代码语言:javascript
复制
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#

或者使用这个作为您的选择...

代码语言:javascript
复制
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 rowmultiplier
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21356998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档