Previous Topic: Exercise 3-3Next Topic: Exercise 3-4


Renaming Column Headings

In your results, each column has a heading. The heading is the name of the column as it was specified in the table definition.

 EMP_FNAME   EMP_LNAME     STREET                   CITY  ---------   ---------     ------                   ----  Samuel      Spade         47 London St             Canton  Catherine   Williams      566 Lincoln St           Boston  Janice      Dexter        399 Pine St              Medford  Cora        Parker        2 Spring St              Boston  Mark        White         560 Camden St            Canton                         .                         .                         . 55 rows processed

How It's Done

To make a column heading more meaningful, you can rename it. To do this, add AS and the name you want to use after each column name:

select emp_fname as "First Name",
       emp_lname as "Last Name",
       street as "Street",
       city as "City"
       from employee;

Enclose new heading names in double quotation marks.

Don't forget the commas between column names.

This is the same SELECT statement you used to retrieve selected columns. However, in this case, the headings will have a more meaningful appearance.

These new column headings assigned using AS are temporary names and appear only in the display.

The result looks like this:

 First Name          Last Name           Street                 City  ----------          ---------           ------                 ----  Samuel              Spade               47 London St           Canton  Catherine           Williams            566 Lincoln St         Boston  Janice              Dexter              399 Pine St            Medford  Cora                Parker              2 Spring St            Boston  Mark                White               560 Camden St          Canton  Marylou             Hamel               11 Main St             Medford  James               Gallway             12 East Speen St       Stoneham  Ronald              Wilder              30 Heron Ave           Natick  Frank               Lowe                25 Rutland St          Natick  Mary                Umidy               895A Braintree Circle  Medford  Cynthia             Taylor              201 Washington St      Concord  John                Brooks              129 Bedford St         Camden  Carl                Smith               18 South St            Newton  Martin              Loren               401 Cross St           Grover  Bruce               MacGregor           254 Waterside Rd       Camden  Michael             Smith               201 Summer St          Brookline  William             Griffin             390 Sherman St         Taunton  Jason               Thompson            3 Flintlock St         Natick  Stephen             Wills               34 Avon Dr             Canton  David               Alexander           18 Cross St            Grover                         .                         .                         . 55 rows processed