如何格式化Oracle 19C SQL Plus中的输出?
嗨,我正在尝试格式化此select的输出,看起来像一个表,看起来像一张列,每个列都不在每个上面另一个,但一个彼此相邻,值在正确的列下。
Hi I am trying to format this select's output to look like a table with columns not on on top of each other, but one next to each other and the values to be under the correct column.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于绝大多数情况,您最好使用SQL开发人员(例如SQL开发人员)运行查询,这将自动以视觉上令人愉悦的方式产生查询。
但是,在
sql*plus
中,您可以使用每列并确定要在输出中使用的字符数。我猜您的输出窗口是80个字符宽,因此您希望将所有列的总宽度分配给所有小于80个字符。这样的事情似乎可以工作(至少对于您显示的数据),但是如果您的值比我在某些列中猜测的更长的值,则可以包装。您可能会或可能不同意,例如,在两个行上显示一个更长的约束名称,请记住,
sql*plus
格式命令最初是设计为生产被载入物理打印机的报告的,充满了该可爱的物理打印机白色和绿色条形纸不适合运行随机临时查询的开发人员。这就是Guis的设计目的。For the vast majority of situations, you'd be better off using a GUI like SQL Developer to run your queries which will automatically format results in a visually pleasing manner.
In
SQL*Plus
, however, you can go for each column and identify the number of characters you want to be used in your output. I'm guessing your output window is 80 characters wide so you'd want the total width allocated to all the columns to be less than 80 characters. Something like this would appear to work (at least for the data you're showing) but would wrap if you have longer values than I've guessed in some columns. You might or might not be OK with, say, a longer constraint name being displayed across two rowsRemember that
SQL*Plus
formatting commands were originally designed to produce reports that were spooled to physical printers full of that lovely white and green bar paper not for developers running random ad hoc queries. That's what GUIs were designed for.