Properly Formatting Tables in SQLPLUS

北城以北 提交于 2019-12-24 10:26:35

问题


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.

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?

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!


回答1:


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

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.

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

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

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.

For more information see the SQLPLUS documentation.



来源:https://stackoverflow.com/questions/53576681/properly-formatting-tables-in-sqlplus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!