iSQL*Plus User's Guide and Reference
Release 9.0.1

Part Number A88826-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Command Reference, 11 of 38


COLUMN

Syntax

COL[UMN] [{column|expr} [option ...]]

where option represents one of the following clauses:

Specifies display attributes for a given column, such as

Also lists the current display attributes for a single column or all columns.

Terms | Usage | Examples | Top

Enter COLUMN followed by column or expr and no other clauses to list the current display attributes for only the specified column or expression. Enter COLUMN with no clauses to list all current column display attributes.

Refer to the following list for a description of each term or clause:

{column|expr}

ALI[AS] alias

CLE[AR]

ENTMAP {ON|OFF}

FOLD_A[FTER]

FOLD_B[EFORE]

FOR[MAT] format

HEA[DING] text

JUS[TIFY] {L[EFT]|C[ENTER]|C[ENTRE]|R[IGHT]}

LIKE {expr|alias}

NEWL[INE]

NEW_V[ALUE] variable

NOPRI[NT]|PRI[NT]

NUL[L] text

OLD_V[ALUE] variable

ON|OFF

WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]

Usage | Terms | Examples | Top

You can enter any number of COLUMN commands for one or more columns. All column attributes set for each column remain in effect for the remainder of the session, until you turn the column OFF, or until you use the CLEAR COLUMN command. Thus, the COLUMN commands you enter can control a column's display attributes for multiple SQL SELECT commands.

When you enter multiple COLUMN commands for the same column, SQL*Plus applies their clauses collectively. If several COLUMN commands apply the same clause to the same column, the last one entered will control the output.

Examples | Terms | Usage | Top

To make the LAST_NAME column 20 characters wide and display EMPLOYEE NAME on two lines as the column heading, enter

Keyboard icon
COLUMN LAST_NAME FORMAT A20 HEADING 'EMPLOYEE|NAME'

To format the SALARY column so that it shows millions of dollars, rounds to cents, uses commas to separate thousands, and displays $0.00 when a value is zero, enter

Keyboard icon
COLUMN SALARY FORMAT $9,999,990.99

To assign the alias NET to a column containing a long expression, to display the result in a dollar format, and to display <NULL> for null values, you might enter


Keyboard icon
COLUMN SALARY+COMMISSION_PCT+BONUS-EXPENSES-INS-TAX ALIAS NET
COLUMN NET FORMAT $9,999,999.99 NULL '<NULL>'

Note that the example divides this column specification into two commands. The first defines the alias NET, and the second uses NET to define the format.

Also note that in the first command you must enter the expression exactly as you enter it in the SELECT command. Otherwise, SQL*Plus cannot match the COLUMN command to the appropriate column.

To wrap long values in a column named REMARKS, you can enter

Keyboard icon
COLUMN REMARKS FORMAT A20 WRAP

Screen icon
CUSTOMER   DATE        QUANTITY REMARKS
---------- ---------   -------- --------------------
123        25-AUG-2001      144 This order must be s
                                hipped by air freigh
                                t to ORD

If you replace WRAP with WORD_WRAP, REMARKS looks like this:

CUSTOMER   DATE        QUANTITY REMARKS
---------- ---------   -------- ---------------------
123        25-AUG-2001      144 This order must be
                                shipped by air freight
                                to ORD

If you specify TRUNCATE, REMARKS looks like this:

CUSTOMER   DATE        QUANTITY REMARKS
---------- ---------   -------- --------------------
123        25-AUG-2001      144 This order must be s

In order to print the current date and the name of each job in the top title, enter the following. Use the EMPLOYEES table of the HR schema in this case instead of EMP_DETAILS_VIEW as you have used up to now. (For details on creating a date variable, see "Displaying the Current Date in Titles" under "Defining Page and Report Titles and Dimensions" in Chapter 4.)

Keyboard icon
COLUMN JOB_ID NOPRINT NEW_VALUE JOBVAR
COLUMN TODAY  NOPRINT NEW_VALUE DATEVAR
BREAK ON JOB_ID SKIP PAGE ON TODAY
TTITLE CENTER 'Job Report' RIGHT DATEVAR  SKIP 2 -
LEFT 'Job:     ' JOBVAR SKIP 2
SELECT TO_CHAR(SYSDATE, 'MM/DD/YYYY') TODAY,
LAST_NAME, JOB_ID, MANAGER_ID, HIRE_DATE, SALARY, DEPARTMENT_ID
FROM EMPLOYEES WHERE JOB_ID IN ('MK_MAN', 'SA_MAN')
ORDER BY JOB_ID, LAST_NAME;

Your two page report would look similar to the following report, with "Job Report" centered within your current linesize:

Screen icon
                                      Job Report                           
04/19/01

Job:     MK_MAN

LAST
NAME                 MANAGER_ID HIRE_DATE         SALARY DEPARTMENT_ID
-------------------- ---------- --------- -------------- -------------
Hartstein                   100 17-FEB-96     $13,000.00            20
                                          --------------
                                              $13,000.00

                                   Job Report                           04/19/01

Job:     SA_MAN

LAST
NAME                 MANAGER_ID HIRE_DATE         SALARY DEPARTMENT_ID
-------------------- ---------- --------- -------------- -------------
Errazuriz                   100 10-MAR-97     $12,000.00            80
Zlotkey                     100 29-JAN-00     $10,500.00            80
Cambrault                   100 15-OCT-99     $11,000.00            80
Russell                     100 01-OCT-96     $14,000.00            80
Partners                    100 05-JAN-97     $13,500.00            80
                                          --------------

                                   Job Report                           04/19/01

Job:     SA_MAN

LAST
NAME                 MANAGER_ID HIRE_DATE         SALARY DEPARTMENT_ID
-------------------- ---------- --------- -------------- -------------
                                              $12,200.00

6 rows selected.

To change the default format of DATE columns to 'YYYY-MM-DD', you can enter

Keyboard icon
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';

Screen icon
Session altered.

To display the change, enter a SELECT statement, such as:

Keyboard icon
SELECT HIRE_DATE
FROM EMPLOYEES
WHERE EMPLOYEE_ID = 206;

Screen icon
                                   Job Report                           04/19/01

Job:     SA_MAN

HIRE_DATE
----------
1994-06-07

See the Oracle9i SQL Reference for information on the ALTER SESSION command.

Note that in a SELECT statement, some SQL calculations or functions, such as TO_CHAR, may cause a column to be very wide. In such cases, use the FORMAT option to alter the column width.


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback