Professional Documents
Culture Documents
After
After completing
completing thisthis lesson,
lesson, you
you should
should
be
be able
able to
to do
do the
the following:
following:
•• Limit
Limit the
the rows
rows retrieved
retrieved by
by aa query
query
•• Sort
Sort the
the rows
rows retrieved
retrieved by
by aa query
query
EMP
EMPNO ENAME JOB ... DEPTNO
•• The
The WHERE
WHERE clause
clause follows
follows the
the FROM
FROM
clause.
clause.
SQL>
SQL> SELECT
SELECT ename,
ename, job,
job, deptno
deptno
22 FROM
FROM emp
emp
33 WHERE
WHERE ename
ename == 'JAMES';
'JAMES';
Operator Meaning
= Equal to
Operator Meaning
ENAME SAL
---------- --------- Lower Higher
MARTIN 1250 limit limit
TURNER 1500
WARD 1250
ADAMS 1100
MILLER 1300
•• You
You can
can combine
combine pattern-matching
pattern-matching
characters.
characters.
SQL> SELECT ename
2 FROM emp
3 WHERE ename LIKE '_A%';
ENAME
----------
MARTIN
JAMES
WARD
•• You
You can
can use
use the
the ESCAPE
ESCAPE identifier
identifier to
to
search
search for
for "%"
"%" or
or "_".
"_".
2-13 Copyright Oracle Corporation, 1998. All rights reserved.
Using the IS NULL Operator
Test
Test for
for null
null values
values with
with the
the IS
IS NULL
NULL
operator.
operator.
ENAME MGR
---------- ---------
KING
Operator Meaning
ENAME JOB
---------- ---------
KING PRESIDENT
MARTIN SALESMAN
ALLEN SALESMAN
TURNER SALESMAN
WARD SALESMAN
Override
Override rules
rules of
of precedence
precedence by
by using
using
parentheses.
parentheses.
ENAME
ENAME JOB
JOB SAL
SAL
----------
---------- ---------
--------- ---------
---------
KING
KING PRESIDENT
PRESIDENT 5000
5000
MARTIN
MARTIN SALESMAN
SALESMAN 1250
1250
ALLEN
ALLEN SALESMAN
SALESMAN 1600
1600
TURNER
TURNER SALESMAN
SALESMAN 1500
1500
WARD
WARD SALESMAN
SALESMAN 1250
1250
ENAME
ENAME JOB
JOB SAL
SAL
----------
---------- ---------
--------- ---------
---------
KING
KING PRESIDENT
PRESIDENT 5000
5000
ALLEN
ALLEN SALESMAN
SALESMAN 1600
1600
•• You
You can
can sort
sort by by aa column
column that that is is not
not in
in the
the
SELECT
SELECT list.
list.
2-25 Copyright Oracle Corporation, 1998. All rights reserved.
Summary