SELECT
doc_detail.phenomena INTO sPhenomenaList,
doc_detail.fault_type INTO sFaultTypeList,
doc_detail.content INTO sContentList,
doc_detail.resolve INTO sResolveList,
doc_detail.carry_over INTO sCarryOverList,
doc_detail.result INTO sResultList 
FROM
doc_head
WHERE
doc_detail.report_id = 12;我想把查出来的结果集(可能有多条记录),concat成字符串输出,
out int sPhenomenaList,out int sFaultTypeList, out int sContentList.........
每个字段都传出一个字符串的值。
怎么做?不知道怎么写了,谢谢

解决方案 »

  1.   

    你这select....into 是什么意思?
      

  2.   

    不用存储过程SELECT 
    group_concat(phenomena),group_concat(fault_type),group_concat(content),group_concat(resolve),
    group_concat(carry_over),group_concat(result) 
    from doc_detail
    where report_id = 12
      

  3.   

    我刚才查了一下group_concat的用法,好像可以改分割符:
    MySQL中group_concat函数
    完整的语法如下:
    group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
      

  4.   

    GROUP_CONCAT(phenomena separator '|'),
      

  5.   

    SELECT 
    group_concat(phenomena separator '|'),group_concat(fault_type separator '|'),group_concat(content separator '|'),group_concat(resolve),
    group_concat(carry_over separator '|'),group_concat(result separator '|') 
    from doc_detail
    where report_id = 12
      

  6.   

    我最后一个字段:result 为tinyint类型,查出来的结果是BLOB,没有查出真正的值,为什么?改为char类型就可以了,为什么,可以用数字类型的字段吗?
      

  7.   

    tinyint可以查出来的。mysql> desc t;
    +-------+------------+------+-----+---------+-------+
    | Field | Type       | Null | Key | Default | Extra |
    +-------+------------+------+-----+---------+-------+
    | f1    | tinyint(4) | YES  |     | NULL    |       |
    +-------+------------+------+-----+---------+-------+
    1 row in set (0.02 sec)mysql> select group_concat(f1) from t;
    +------------------+
    | group_concat(f1) |
    +------------------+
    | 1,2,3,6          |
    +------------------+
    1 row in set (0.00 sec)mysql> select version();
    +---------------------+
    | version()           |
    +---------------------+
    | 5.0.45-community-nt |
    +---------------------+
    1 row in set (0.00 sec)
      

  8.   

    可以用数字类型的字段.mysql> create table xx (id int);
    Query OK, 0 rows affected (0.13 sec)mysql> insert into xx values (1),(2),(3);
    Query OK, 3 rows affected (0.02 sec)
    Records: 3  Duplicates: 0  Warnings: 0mysql> select group_concat(id) from xx;
    +------------------+
    | group_concat(id) |
    +------------------+
    | 1,2,3            |
    +------------------+
    1 row in set (0.06 sec)mysql>