Oracle SQL - SQL Plus COLUMN

Introduction

We can change the way a column displays by using the COLUMN command.

The COLUMN command has the syntax:

COLUMN column-name FORMAT format-specification 

where column-name is the column heading one wishes to format.

The format-specification uses a's for text and 9's for numbers, like this:

  • an - text format for a field width of n
  • 9n - numeric format with no decimals for a field width of numbers of size n

For example, to see the complete column name for REGION, we can execute the COLUMN command prior to executing the SQL statement:

COLUMN region FORMAT a6 

We can shorten the ename field because the names are shorter than 20 characters.

COLUMN ename FORMAT a11 

In the case of alphanumeric columns, if the column is too short to fit the data, it will be displayed on multiple lines.

For example, if the COLUMN format for ename were too short:

Demo

COLUMN ename FORMAT a7 

SELECT * FROM employee

Related Topics