Datasheet

38
Chapter 1
Introducing SQL
FIRST_NAME LAST_NAME
-------------------- -------------------------
Sundar Ande
Sundita Kumar
Susan Mavris
The following example looks for all JOB_ID values that begin with AC_. Since _ is a
pattern-matching character, you must qualify it with an escape character. Oracle does not
have a default escape character.
SELECT job_id, job_title
FROM jobs
WHERE job_id like ‘AC\_%’ ESCAPE ‘\’;
JOB_ID JOB_TITLE
---------- -----------------------------------
AC_MGR Accounting Manager
AC_ACCOUNT Public Accountant
Table 1.10 shows more examples of pattern matching.
TABLE 1.10 Pattern-Matching Examples
Pattern Matches Does Not Match
%SONI_1 SONIC1, ULTRASONI21 SONICS1, SONI315
_IME TIME
, LIME IME, CRIME
\%SONI_1 ESCAPE ‘\’ %SONIC1
, %SONI91 SONIC1, ULTRASONIC1
%ME\_ _ _LE ESCAPE ‘\’ CRIME_FILE
, TIME_POLE CRIMESPILE, CRIME_ALE
Sorting Rows
The SELECT statement may include the ORDER BY clause to sort the resulting rows in a specic
order based on the data in the columns. Without the
ORDER BY clause, there is no guarantee
that the rows will be returned in any specific order. If an
ORDER BY clause is specied, by
default the rows are returned by ascending order of the columns specified. If you need to
sort the rows in descending order, use the keyword
DESC next to the column name. You
can specify the keyword
ASC to explicitly state to sort in ascending order, although it is the
95127c01.indd 38 2/18/09 6:37:10 AM