Skip to Main Content
Oracle SQL*Plus Pocket Reference
book

Oracle SQL*Plus Pocket Reference

by Jonathan Gennick
April 2000
Intermediate to advanced content levelIntermediate to advanced
94 pages
1h 52m
English
O'Reilly Media, Inc.
Content preview from Oracle SQL*Plus Pocket Reference

Selecting Data

The SELECT statement is the key to getting data out of an Oracle database. It’s also very likely the most commonly executed SQL statement from SQL*Plus.

The SELECT Statement

The basic form of the SELECT statement looks like this:

SELECT column_list
FROM table_list
WHERE conditions
GROUP BY column_list
HAVING conditions
ORDER BY column_list;

The lists in this syntax are comma-delimited. The column list, for example, is a comma-delimited list of column names or expressions identifying the data that you want the query to return.

Selecting columns from a table

To retrieve columns from a table, list the columns you want following the SELECT keyword, place the table name after the FROM keyword, and execute your statement. The following query returns a list of tables that you own together with the names of their assigned tablespaces:

SELECT table_name, tablespace_name
   FROM user_tables;

Ordering query results

You can use the ORDER BY clause to sort the results of a query. The following example sorts the results by table name:

SELECT table_name, tablespace_name
FROM user_tables
ORDER BY table_name;

The default is to sort in ascending order. You can specify descending order using the DESC keyword. For example:

ORDER BY table_name DESC;

While it’s redundant, ASC may be used to specify ascending order. The following example sorts the table list first by tablespace name in descending order and then within that by table name in ascending order:

SELECT table_name, tablespace_name FROM user_tables ...
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 Pocket Reference, 3rd Edition

Oracle SQL*Plus Pocket Reference, 3rd Edition

Jonathan Gennick
Expert Oracle Exadata

Expert Oracle Exadata

Kerry Osborne, Randy Johnson, Tanel Pöder

Publisher Resources

ISBN: 1565929411Catalog PageErrata