background image
<< Selecting Data from a Table | Testing for a Single Condition >>
<< Selecting Data from a Table | Testing for a Single Condition >>

Using Column Aliases

Retrieving Data with Queries
2-8 Oracle Database 2 Day Developer's Guide
Using Column Aliases
To display a column with a new heading, you can rename a column within your
report by using an alias immediately after the correct name of the column. This alias
effectively renames the item for the duration of the query.
In
Example 2­3
, the
SELECT
statement returns the columns you request in your query,
but with the column headings that you specified as aliases:
name1
,
name2
, and
hired
.
Example 2­3 Using a Simple Column Alias
SELECT first_name name1, last_name name2, hire_date hired FROM employees;
The results of the query follow:
NAME1 NAME2 HIRED
--------------------- -------------------- -------------------------
Steven King 17-JUN-87
Neena Kochhar 21-SEP-89
Lex De Haan 13-JAN-93
...
107 rows selected
If the alias that you want to use contains uppercase and lowercase characters or
spaces, or a combination, you must use double quotation marks (").
Example 2­4
uses a
SELECT
statement to return the columns with column heading
aliases that you specify:
First
,
Last
, and
Date Started
.
Example 2­4 Using Quoted Alias Columns
SELECT first_name "First", last_name "Last", hire_date "Date Started"
FROM employees;
The results of the query follow.
First Last Date Started
---------------------- -------------------- -------------------------
Steven King 17-JUN-87
Neena Kochhar 21-SEP-89
Lex De Haan 13-JAN-93
...
107 rows selected
Restricting Data to Match Specific Conditions
In addition to the
SELECT
and
FROM
keywords, other common clauses are used in
queries. The
WHERE
clause uses comparison operators to select the rows that should be
retrieved, instead of returning all the rows in the tables.
This table lists the comparison operators that can be used in the
WHERE
clause.
Comparison Operator
Definition
=
Tests for equality
!=
,
<>
Tests for inequality
>
Tests for greater than
>=
Tests for greater than or equal