Beruflich Dokumente
Kultur Dokumente
Copyright © 2006, Oracle. All rights reserved. 2-2 Copyright © 2006, Oracle. All rights reserved.
Limiting Rows Using a Selection Limiting the Rows That Are Selected
“retrieve all
employees in
department 90”
2-3 Copyright © 2006, Oracle. All rights reserved. 2-4 Copyright © 2006, Oracle. All rights reserved.
Using the WHERE Clause Character Strings and Dates
SELECT employee_id, last_name, job_id, department_id • Character strings and date values are enclosed in
FROM employees single quotation marks.
WHERE department_id = 90 ;
• Character values are case sensitive, and date values
are format sensitive.
• The default date format is DD-MON-RR.
2-5 Copyright © 2006, Oracle. All rights reserved. 2-6 Copyright © 2006, Oracle. All rights reserved.
2-7 Copyright © 2006, Oracle. All rights reserved. 2-8 Copyright © 2006, Oracle. All rights reserved.
Using the BETWEEN Condition Using the IN Condition
Use the BETWEEN condition to display rows based on a Use the IN membership condition to test for values in a
range of values: list:
SELECT last_name, salary SELECT employee_id, last_name, salary, manager_id
FROM employees FROM employees
WHERE salary BETWEEN 2500 AND 3500 ; WHERE manager_id IN (100, 101, 201) ;
2-9 Copyright © 2006, Oracle. All rights reserved. 2 - 10 Copyright © 2006, Oracle. All rights reserved.
• Use the LIKE condition to perform wildcard • You can combine pattern-matching characters:
searches of valid search string values. SELECT last_name
• Search conditions can contain either literal FROM employees
characters or numbers: WHERE last_name LIKE '_o%' ;
SELECT first_name
• You can use the ESCAPE identifier to search for the
FROM employees actual % and _ symbols.
WHERE first_name LIKE 'S%' ;
2 - 11 Copyright © 2006, Oracle. All rights reserved. 2 - 12 Copyright © 2006, Oracle. All rights reserved.
Using the NULL Conditions Logical Conditions
2 - 13 Copyright © 2006, Oracle. All rights reserved. 2 - 14 Copyright © 2006, Oracle. All rights reserved.
2 - 15 Copyright © 2006, Oracle. All rights reserved. 2 - 16 Copyright © 2006, Oracle. All rights reserved.
Using the NOT Operator Rules of Precedence
2 - 17 Copyright © 2006, Oracle. All rights reserved. 2 - 18 Copyright © 2006, Oracle. All rights reserved.
2 - 19 Copyright © 2006, Oracle. All rights reserved. 2 - 20 Copyright © 2006, Oracle. All rights reserved.
Sorting Substitution Variables
2 - 21 Copyright © 2006, Oracle. All rights reserved. 2 - 22 Copyright © 2006, Oracle. All rights reserved.
• Use iSQL*Plus substitution variables to: Use a variable prefixed with an ampersand (&) to prompt
– Temporarily store values with single-ampersand (&) the user for a value:
and double-ampersand (&&) substitution
SELECT employee_id, last_name, salary, department_id
• Use substitution variables to supplement the FROM employees
following: WHERE employee_id = &employee_num ;
– WHERE conditions
– ORDER BY clauses
– Column expressions
– Table names
– Entire SELECT statements
2 - 23 Copyright © 2006, Oracle. All rights reserved. 2 - 24 Copyright © 2006, Oracle. All rights reserved.
Using the & Substitution Variable Character and Date Values
with Substitution Variables
1
2
2 - 25 Copyright © 2006, Oracle. All rights reserved. 2 - 26 Copyright © 2006, Oracle. All rights reserved.
SELECT employee_id, last_name, job_id,&column_name Use the double ampersand (&&) if you want to reuse the
FROM employees variable value without prompting the user each time:
WHERE &condition
ORDER BY &order_column ; SELECT employee_id, last_name, job_id, &&column_name
FROM employees
ORDER BY &column_name ;
salary
last_name
…
2 - 27 Copyright © 2006, Oracle. All rights reserved. 2 - 28 Copyright © 2006, Oracle. All rights reserved.
Using the iSQL*Plus DEFINE Command Using the VERIFY Command
• Use the iSQL*Plus DEFINE command to create and Use the VERIFY command to toggle the display of the
assign a value to a variable. substitution variable, both before and after iSQL*Plus
• Use the iSQL*Plus UNDEFINE command to remove a replaces substitution variables with values:
variable.
SET VERIFY ON
SELECT employee_id, last_name, salary, department_id
DEFINE employee_num = 200
FROM employees
WHERE employee_id = &employee_num;
SELECT employee_id, last_name, salary, department_id
FROM employees
WHERE employee_id = &employee_num ;
2 - 29 Copyright © 2006, Oracle. All rights reserved. 2 - 30 Copyright © 2006, Oracle. All rights reserved.
In this lesson, you should have learned how to: This practice covers the following topics:
• Use the WHERE clause to restrict rows of output: • Selecting data and changing the order of
– Use the comparison conditions the rows that are displayed
– Use the BETWEEN, IN, LIKE, and NULL conditions • Restricting rows by using the WHERE clause
– Apply the logical AND, OR, and NOT operators • Sorting rows by using the ORDER BY clause
• Use the ORDER BY clause to sort rows of output: • Using substitution variables to add flexibility to
SELECT *|{[DISTINCT] column|expression [alias],...} your SQL SELECT statements
FROM table
[WHERE condition(s)]
[ORDER BY {column, expr, alias} [ASC|DESC]] ;
2 - 31 Copyright © 2006, Oracle. All rights reserved. 2 - 32 Copyright © 2006, Oracle. All rights reserved.
2 - 33 Copyright © 2006, Oracle. All rights reserved. 2 - 34 Copyright © 2006, Oracle. All rights reserved.
2 - 35 Copyright © 2006, Oracle. All rights reserved. 2 - 36 Copyright © 2006, Oracle. All rights reserved.
2 - 37 Copyright © 2006, Oracle. All rights reserved. 2 - 38 Copyright © 2006, Oracle. All rights reserved.