在SQLPLUS中正确格式化表格 [英] Properly Formatting Tables in SQLPLUS

查看:55
本文介绍了在SQLPLUS中正确格式化表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将这个问题作为重复的问题投票之前,我在S.O上花了相当长的时间.试图解决这个问题.正如您在下面的屏幕快照中看到的那样,我的表看上去很乱.

Before this gets voted as a duplicate question, I have spent quite some time on S.O. trying to fix this. As you can see in the screenshot below, my tables are looking messy.

对于第一张和第二张表,您可以看到每个表如何有两组列标题.那么,例如,我如何才能将所有5条客户记录都包含在一张表中?

For the first and second table, you can see how there are 2 sets of column headings for each table. So how can I, for example, get all 5 customer records to be included in one table?

我不知道的另一件事是如何使列标题正确格式化(不被截断,并且都在同一行上).*我尝试更改行大小, SET WRAP OFF; 等.

The other thing I can't figure out is how to get the column headers to be properly formatted(not truncated and all on the same row). *I have tried changing the linesize, SET WRAP OFF; etc.

如果有人可以帮助解释此修复程序,将不胜感激!

If anyone could help explain this fix it would be greatly appreciated!

推荐答案

SQLPLUS布局主要取决于:

SQLPLUS layout mostly depends on :

  • 他认为您的终端的宽度是什么

  • what he thinks the width of your terminal is

您要显示的字段长度(在数据库结构中定义),或者字段名称的大小

either the length of the field that you ask it to display (as defined in the database structure), or the size of the field name

当字段长度的总和大于终端大小时,每行被分成2行或更多行...并且显示变得混乱.

When the sum of the field lenghts is greater than the terminal size, each row is splitted over 2 or more lines... and the display gets messy.

但是您确实可以控制这些参数.

But you do have control over these parameters.

要做的第一件事是定义适当的行大小,即适合您的终端屏幕的行大小.例如,让我们将其设为120个字符:

First thing to do is to define a proper line size, ie one that fits well in your terminal screen. For example let’s make it 120 chars :

set linesize 120

如果您对Oracle选择的长度不满意,则可以手动设置每个字段的长度.例如,对于varchar字段,您可以执行以下操作:

You may then manually set the length of each field, if you are not satisfy with the length chosen by Oracle. For example for a varchar field you can do :

column first_name format a10

,这将允许查询结果中名为FIRST_NAME的字段的最大长度为10.该设置将在会话的整个生命周期内应用到具有相同名称的所有列,即使在后续查询中也是如此.可以使用:

which allows a max length of 10 for the field called FIRST_NAME in the query result. The setting applies to all column with the same name, even in the subsequent queries, for the lifetime of the session. It can be removed with :

column first_name clear

您还可以选择格式化数据类型,这将应用于具有相关数据类型的所有列.

You also have the option of formatting data types, which will apply to all columns having the concerned data type.

有关更多信息,请参见 SQLPLUS文档.

For more information see the SQLPLUS documentation.

这篇关于在SQLPLUS中正确格式化表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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