Database Reference
In-Depth Information
4.1.3
Some Simple Example SELECT Statements
The first example retrieves rows from an Oracle metadata view:
SELECT VIEW_NAME, TEXT FROM USER_VIEWS;
This statement has a list of two columns (VIEW_NAME and TEXT),
and the view queried is named USER_VIEWS. Tables and views are inter-
changeable in the SELECT command. No schema name is used because
the view in this case belongs to the user who is running the query. As a gen-
eral rule, any time you query a table or view that belongs to the user you log
in as, no schema name is required. Likewise, when you query a table or
view that is in another user's schema, you must use the schema name. For
example, if you log in as JOE and you want to query a table name CARS
owned by SAM, you would have to add the schema name CARS.
SELECT * FROM SAM.CARS;
Note:
The semicolon is technically not considered part of the SQL state-
ment's syntax. The semicolon marks the end of the statement and submis-
sion. A forward slash on a blank line following the SQL statement serves
the same purpose. Submission means submission to the SQL engine, in
other words “execute it!”
Now let's do some simple SELECT statement examples using the
MUSIC schema.
Note:
Diagrams and scripts for the MUSIC schema are in Chapter 1 and
Appendix A.
Let's begin with a query listing all the data in the MUSICCD table:
SELECT * FROM MUSICCD;
Figure 4.2 shows the result. Notice the blank spaces in certain columns.
This stands for a null value in the data. For example, the PLAYING_TIME
column for the first row (Soak Up the Sun) is NULL.
Search WWH ::




Custom Search