Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ugly formatting in SQL*Plus

Tags:

It is really annoying that when I run a select command in SQL*Plus such as:

SELECT * FROM books; 

The output is really badly formatted and unreadable (row cells are not in a row but separated by line breaks etc):

enter image description here

How can I configure it to show SELECT results in a nicer way?

EDIT:

This is my login.sql file contents:

SET ECHO OFF SET SERVEROUTPUT ON SIZE 1000000 SET PAGESIZE 999 SET LINESIZE 132 

EDIT2:

Affer increasing the LINESIZE:

SET LINESIZE 32000 

It now looks like this:

enter image description here

like image 346
Richard Knop Avatar asked Apr 24 '11 15:04

Richard Knop


People also ask

How do I format a SQL Plus?

The formatting commands include: BREAK – Set the formatting behavior for records that have the same values for some columns. BTITLE – Place a title on the bottom of each page in the printout from a SQL statement. COLUMN – Change the appearance of an output column from a query.

Which is an SQL*Plus command?

SQL*Plus is a command-line tool that provides access to the Oracle RDBMS. SQL*Plus enables you to: Enter SQL*Plus commands to configure the SQL*Plus environment. Startup and shutdown an Oracle database.

What is SQL*Plus and why would you want to use it?

SQL*Plus is an Oracle-developed tool that allows you to interactively enter and execute SQL commands and PL/SQL blocks. Because these three products all have “SQL” as part of their names, people occasionally get confused about the relationship between them and about which commands get executed where.

How do I clean my SQL Plus screen?

The Clear command clears the screen of the SQL*Plus application window and the screen buffer. Shift+Del is the keyboard shortcut for the Clear command.


2 Answers

Increase the linesize, e.g SET LINESIZE 32000

or use SET WRAP OFF (but this will truncate long values)

like image 116
a_horse_with_no_name Avatar answered Oct 02 '22 15:10

a_horse_with_no_name


SQLPlus is a simple command line tool. It's not really intended for pretty reporting. However, it does have some formatting commands, which are documented in the SQLPlus User's Guide. Find out more.

For instance you might choose to format the TITLE column to display only the first twenty characters and display the SUMMARY column in its entirety like this:

COLUMN title FORMAT a20 TRUNCATED  COLUMN summary FORMAT a4o WORD_WRAPPED 

This will allow you to see your query laid out more neatly without embedding formatting commands in its projection.

Alternatively, use an IDE such as Quest's TOAD or Oracle's own SQL Developer. These tools include a query browser which automagically displays our query results in a more pleasing grid. (Other similar tools are available).

like image 45
APC Avatar answered Oct 02 '22 15:10

APC