如何缩进mysql SELECT INTO OUTFILE的结果
我有一个 sql 表,我想将其转储到输出文件。问题是,有些结果是 1 位数字,即 1 或 2,而其他结果是长数字,即 1.2323523
这会导致输出文件看起来很糟糕,类似于这个
1 a bbb
1.21321342 aaaa bbbbb
意思,每列的开头未对齐。有谁知道sql中有没有办法解决这个问题?
谢谢!!!
I have an sql table that I want to dump to an outfile. The thing is, some of the results are 1 digit, i.e 1 or 2, while others are long numbers, i.e. 1.2323523
This causes the outfile to look terrible, something like this
1 a bbb
1.21321342 aaaa bbbbb
meaning, the beginning of each column is not aligned. Does anyone know if there is a way in sql to take care of that?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将列转换为 char(n),例如
这将输出固定宽度的列数据。然而,它们将被保留。
更好的解决方案是为所有数字提供相同的小数位数,1 将输出为“1.000000”等。具体做法如下:
选择所需的精度(位数 - 此处为 8)。
所有列都可以以这种方式处理,以生成良好的表格格式。
cast the columns as char(n), eg
This will be output fixed-width column data. They will however be left justified.
A better solution would be to give the same number of decimal places to all numbers, 1 would be output as "1.000000" etc. This is how to do that:
Chose the precision (number of places - here 8) you want.
All columns can be treated in this way to produce a nicely tabulated format.
像这样使用你会得到一个csv文件,所以在excel中它看起来很漂亮
use like this u get a csv file, so in excel its look pretty
您可以使用 mysql 中的字符串操作函数之一 。值得注意的是, LPAD 或 格式。
You can use one of the string manipulation functions in mysql. Notably, LPAD or FORMAT.