concat在mysql中产生的值

时间:2013-09-18 08:03:28

标签: mysql

我可以连接结果值,然后将最终值作为输出发送。

WHILE(LENGTH(totalexpenseamount )>0) DO
        BEGIN
              SET totalshipmentexpenseamount = CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount);
END;
    END WHILE;

但是在结束时,总计的数量并没有任何价值。

1 个答案:

答案 0 :(得分:1)

不知道您提供的代码之前是什么,但您可以尝试以下方法:

WHILE(LENGTH(totalexpenseamount )>0) DO
        BEGIN
              SET totalshipmentexpenseamount = CONCAT(COALESCE(totalshipmentexpenseamount, ''),',',indshipmentexpenseamount);
END;
    END WHILE;

这是因为totalshipmentexpenseamount在第一次设置为null,当您将null与其他内容联系起来null时。如果coalescetotalshipmentexpenseamount

null将返回空

修改

更改为

WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
    SET totalshipmentexpenseamount = COALESCE(CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount), indshipmentexpenseamount);
END;
WHILE;

由于您使用逗号连接,这将在第一次传递中设置indshipmentexpenseamount的值,否则将使用逗号和totalshipmentexpenseamount

连接indshipmentexpenseamount