Skip to Main Content
Oracle SQL*Plus: The Definitive Guide
book

Oracle SQL*Plus: The Definitive Guide

by Jonathan Gennick
March 1999
Intermediate to advanced content levelIntermediate to advanced
528 pages
14h 39m
English
O'Reilly Media, Inc.
Content preview from Oracle SQL*Plus: The Definitive Guide

Formatting Character Strings

SQL*Plus offers only one format element when it comes to character strings. That element is “A”. “A” is always followed by a number specifying the column width in characters. Character strings shorter than the column width are displayed left-justified within the column. Character strings that exceed the column width are either wrapped or truncated based on the option specified in the COLUMN command. The following example shows a text column that has been formatted wide enough to display the entire character string:

SQL> COLUMN a FORMAT A40
SQL> SELECT 'An apple a day keeps the doctor away.' A 
  2    FROM dual;

A
----------------------------------------
An apple a day keeps the doctor away.

You can format the column so that it is 18 characters wide, which results in the text being wrapped within that space:

SQL> COLUMN a FORMAT A18
SQL> SELECT 'An apple a day keeps the doctor away.' A 
  2    FROM dual;

A
------------------
An apple a day kee
ps the doctor away
.

By default, SQL*Plus wraps the text right in the middle of a word, if necessary. You can use the WORD_WRAPPED option of the COLUMN command to wrap text only at word boundaries.

SQL> COLUMN a FORMAT A18 WORD_WRAPPED
SQL> SELECT 'An apple a day keeps the doctor away.' A 
  2    FROM dual;

A
------------------
An apple a day
keeps the doctor
away.

You also have the ability to truncate text at the column boundary.

SQL> COLUMN a FORMAT A18 TRUNCATE
SQL> SELECT 'An apple a day keeps the doctor away.' A 
  2    FROM dual; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Oracle SQL*Plus: The Definitive Guide, 2nd Edition

Oracle SQL*Plus: The Definitive Guide, 2nd Edition

Jonathan Gennick
Oracle PL/SQL Programming, Third Edition

Oracle PL/SQL Programming, Third Edition

Steven Feuerstein, Bill Pribyl
Oracle SQL

Oracle SQL

Dan Hotka

Publisher Resources

ISBN: 1565925785Supplemental ContentCatalog PageErrata