如何抑制单个 SQL 语句的列标题输出? [英] How can I suppress column header output for a single SQL statement?

查看:34
本文介绍了如何抑制单个 SQL 语句的列标题输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在批量执行一些 SQL 语句(使用 mysql 命令行二进制文件).我希望我的几个 SELECT 语句之一不打印列标题,只打印选定的记录.这可能吗?

I'm executing some SQL statements in batch (using the mysql command-line binary). I want one of my several SELECT statements to not print the column headers, just the selected records. Is this possible?

推荐答案

使用 -N 调用 mysql(-N 的别名是 --skip-column-names) 选项:

Invoke mysql with the -N (the alias for -N is --skip-column-names) option:

mysql -N ...
use testdb;
select * from names;

+------+-------+
|    1 | pete  |
|    2 | john  |
|    3 | mike  |
+------+-------+
3 rows in set (0.00 sec)

感谢 ErichBSchulz 指出 -N 别名.

Credit to ErichBSchulz for pointing out the -N alias.

要移除结果周围的网格(垂直线和水平线),请使用 -s (--silent).列用 TAB 字符分隔.

To remove the grid (the vertical and horizontal lines) around the results use -s (--silent). Columns are separated with a TAB character.

mysql -s ...
use testdb;
select * from names;

id  name
1   pete
2   john
3   mike

要输出没有标题和网格的数据,只需同时使用 -s-N.

To output the data with no headers and no grid just use both -s and -N.

mysql -sN ...

这篇关于如何抑制单个 SQL 语句的列标题输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆