我可以连接结果值,然后将最终值作为输出发送。
WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
SET totalshipmentexpenseamount = CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount);
END;
END WHILE;
但是在结束时,总计的数量并没有任何价值。
答案 0 :(得分:1)
不知道您提供的代码之前是什么,但您可以尝试以下方法:
WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
SET totalshipmentexpenseamount = CONCAT(COALESCE(totalshipmentexpenseamount, ''),',',indshipmentexpenseamount);
END;
END WHILE;
这是因为totalshipmentexpenseamount
在第一次设置为null
,当您将null
与其他内容联系起来null
时。如果coalesce
为totalshipmentexpenseamount
null
将返回空
修改强>
更改为
WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
SET totalshipmentexpenseamount = COALESCE(CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount), indshipmentexpenseamount);
END;
WHILE;
由于您使用逗号连接,这将在第一次传递中设置indshipmentexpenseamount
的值,否则将使用逗号和totalshipmentexpenseamount
indshipmentexpenseamount