限制 SELECT 结果中长文本字段的长度
我使用命令行界面(不是 GUI 客户端)对 MySQL 中的表执行 SELECT 查询:
从 blog_entry 中选择*;
blog_entry 的一个字段的类型为“longtext”,并且是一段很长的文本,因此当结果显示在我的终端中时,行的显示需要多行。这会导致显示混乱不堪,列不易可见。我可以在 SELECT 查询中使用什么技术来限制每个字段显示的字符数,以便打印的行结果不会溢出到新行?
I'm executing a SELECT query on a table in MySQL using the command-line interface (not a GUI client):
SELECT * FROM blog_entry;
One of blog_entry's fields is of type 'longtext' and is such a long piece of text that when the result is displayed in my terminal the display of rows takes more than one line. This causes an ugly mess of a display, where columns aren't easily visible. What technique can I use in my SELECT query that would limit the number of characters displayed for each field so that the printed row results don't overflow to new lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 MySQL 的 SUBSTRING 函数,如文档中所述< /a>. Like:
选择前 100 个字符。
Use MySQL's
SUBSTRING
function, as described in the documentation. Like:To select first 100 chars.
您可以使用
LEFT( )
函数仅获取第一个字符:You can use the
LEFT()
function to get only the first characters:清理终端窗口中查询结果的可读性的最佳方法是使用 mysql 分页器,而不是修改查询,因为这可能太麻烦了。
设置寻呼机:
<代码>mysql> pager less -S
执行您的查询:
<代码>mysql> SELECT * FROM ...
这将使您的结果采用更易读的格式。您可以使用箭头键上下左右翻页以查看完整表格。只需按
Q
即可退出该查询的寻呼机模式,然后如果需要,只需运行即可返回正常的输出流。
The best way to clean up the readability of the results from a query in your terminal window is to use the mysql pager, not modifying your query as that can be too cumbersome.
Set the pager:
mysql> pager less -S
Do your query:
mysql> SELECT * FROM ...
This will put your results in a more readable format. You can use your arrow keys to page up and down and left and right to see the full table. Just press
Q
to get out of pager mode for that query, and then just runto return to the normal output river if you want.