Solved

Is it possible to make SQLPlus autofit column display lengths?

Posted on 2009-03-28
4
3,114 Views
Last Modified: 2013-12-07
I'm new to oracle and I would like to know if it's possible to set the following display options and if so how.

1) One record to one line (no line wrapping)

2) Have the display width of each column set to the length of the largest item in that column.
Example:
I have a column called description that can be 1000 characters long.  There are 15 rows returned in my query and the longest description is 35 characters.  Can I have the column display width set to 35?  I know I can set this manually, but I don't want to do it for every query...
0
Comment
Question by:abemiester
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24013881
1) You can set linesize to a really long size, before you spool it.

set line 500

2) I don't think so, I've never seen it. I only know the syntax to set a column format prior to running the query.

column DESCRIPTION a35

select DESCRIPTION from table


http://www.adp-gmbh.ch/ora/sqlplus/column.html
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 24015687
Regarding question 2,

there is no automated way to set the column legth to max length depending on your data in the table column.

We need to do it manually only in sql*plus. But in TOAD or SQL/PLSQL Developer etc, you should have some option for setting that automatically depending on your data.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 24015810
regading 1,

you can do as shown below :

SQL> set wrap off

for more information, refer to the below oracle documentation on sql*plus commands

http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12040.htm#sthref2952
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24019183
You can estimate the maximum length of a the column so

SELECT max(length(column_name)) INTO v_variable from my_table;

If you use this value possibly using 'execute immediate' statement it will be possible
to set the environment. But I am not sure about this.

The best choice is to set to a big value:

set linesize 10000

Normally every record is displayed in one line, so
I do not think you will face problems at all.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question