我正在尝试对某些变量使用 concat。这些变量已声明为字符:
declare v_order_date char(10);
declare v_quantity char(11);
declare v_plant char(100);
我有一个光标,我将这些设置为一些输出。为了调用结果,我将 v_msg 设置为
set v_msg := concat( v_msg, '\n', v_order_date, v_quantity, v_plant);
但是,当我选择 v_msg 时得到的结果是:
2012-01-222501008 Creeping Buttercup
但我想在我的选择中保持声明变量的长度,看起来像这样
2012-01-22 250 1008 Creeping Buttercup
有什么建议吗?谢谢。
最佳答案
使用 MySQL repeat()
和 char_length()
set v_msg := concat(v_msg, '\n', v_order_date, repeat(' ', 10-char_length(v_order_date)), '\n', v_quantity, repeat(' ', 11-char_length(v_quantity)), '\n' , v_plant);
关于mysql - 使用 concat 并保持变量的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12719829/