SlideShare a Scribd company logo
Copyright © 2004, Oracle. All rights reserved.
Restricting and Sorting Data
Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to do
the following:
• Limit the rows that are retrieved by a query
• Sort the rows that are retrieved by a query
• Use ampersand substitution in iSQL*Plus to
restrict and sort output at run time
Copyright © 2004, Oracle. All rights reserved.
Limiting Rows Using a Selection
“retrieve all
employees in
department 90”
EMPLOYEES
…
Copyright © 2004, Oracle. All rights reserved.
Limiting the Rows That Are Selected
• Restrict the rows that are returned by using the
WHERE clause:
• The WHERE clause follows the FROM clause.
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table
[WHERE condition(s)];
Copyright © 2004, Oracle. All rights reserved.
SELECT employee_id, last_name, job_id, department_id
FROM employees
WHERE department_id = 90 ;
Using the WHERE Clause
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, job_id, department_id
FROM employees
WHERE last_name = 'Whalen' ;
Character Strings and Dates
• Character strings and date values are enclosed by
single quotation marks.
• Character values are case-sensitive, and date
values are format-sensitive.
• The default date format is DD-MON-RR.
Copyright © 2004, Oracle. All rights reserved.
Comparison Conditions
Not equal to<>
Between two values
(inclusive)
BETWEEN
...AND...
Match any of a list of valuesIN(set)
Match a character patternLIKE
Is a null valueIS NULL
Less than<
Less than or equal to<=
Greater than or equal to>=
Greater than>
Equal to=
MeaningOperator
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, salary
FROM employees
WHERE salary <= 3000 ;
Using Comparison Conditions
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, salary
FROM employees
WHERE salary BETWEEN 2500 AND 3500 ;
Using the BETWEEN Condition
Use the BETWEEN condition to display rows based on a
range of values:
Lower limit Upper limit
Copyright © 2004, Oracle. All rights reserved.
SELECT employee_id, last_name, salary, manager_id
FROM employees
WHERE manager_id IN (100, 101, 201) ;
Using the IN Condition
Use the IN membership condition to test for values in
a list:
Copyright © 2004, Oracle. All rights reserved.
SELECT first_name
FROM employees
WHERE first_name LIKE 'S%' ;
Using the LIKE Condition
• Use the LIKE condition to perform wildcard
searches of valid search string values.
• Search conditions can contain either literal
characters or numbers:
– % denotes zero or many characters.
– _ denotes one character.
Copyright © 2004, Oracle. All rights reserved.
• You can combine pattern-matching characters:
• You can use the ESCAPE identifier to search for the
actual % and _ symbols.
SELECT last_name
FROM employees
WHERE last_name LIKE '_o%' ;
Using the LIKE Condition
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, manager_id
FROM employees
WHERE manager_id IS NULL ;
Using the NULL Conditions
Test for nulls with the IS NULL operator.
Copyright © 2004, Oracle. All rights reserved.
Logical Conditions
Returns TRUE if the following
condition is false
NOT
Returns TRUE if either component
condition is true
OR
Returns TRUE if both component
conditions are true
AND
MeaningOperator
Copyright © 2004, Oracle. All rights reserved.
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary >=10000
AND job_id LIKE '%MAN%' ;
Using the AND Operator
AND requires both conditions to be true:
Copyright © 2004, Oracle. All rights reserved.
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary >= 10000
OR job_id LIKE '%MAN%' ;
Using the OR Operator
OR requires either condition to be true:
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, job_id
FROM employees
WHERE job_id
NOT IN ('IT_PROG', 'ST_CLERK', 'SA_REP') ;
Using the NOT Operator
Copyright © 2004, Oracle. All rights reserved.
Rules of Precedence
You can use parentheses to override rules of precedence.
Not equal to6
NOT logical condition7
AND logical condition8
OR logical condition9
IS [NOT] NULL, LIKE, [NOT] IN4
[NOT] BETWEEN5
Comparison conditions3
Concatenation operator2
Arithmetic operators1
MeaningOperator
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, job_id, salary
FROM employees
WHERE job_id = 'SA_REP'
OR job_id = 'AD_PRES'
AND salary > 15000;
Rules of Precedence
SELECT last_name, job_id, salary
FROM employees
WHERE (job_id = 'SA_REP'
OR job_id = 'AD_PRES')
AND salary > 15000;
1
2
Copyright © 2004, Oracle. All rights reserved.
Using the ORDER BY Clause
• Sort retrieved rows with the ORDER BY clause:
– ASC: ascending order, default
– DESC: descending order
• The ORDER BY clause comes last in the SELECT
statement:
SELECT last_name, job_id, department_id, hire_date
FROM employees
ORDER BY hire_date ;
…
Copyright © 2004, Oracle. All rights reserved.
Sorting
• Sorting in descending order:
• Sorting by column alias:
• Sorting by multiple columns:
SELECT last_name, job_id, department_id, hire_date
FROM employees
ORDER BY hire_date DESC ; 1
SELECT employee_id, last_name, salary*12 annsal
FROM employees
ORDER BY annsal ;
2
SELECT last_name, department_id, salary
FROM employees
ORDER BY department_id, salary DESC;
3
Copyright © 2004, Oracle. All rights reserved.
Substitution Variables
... salary = ? …
… department_id = ? …
... last_name = ? ...
I want
to query
different
values.
Copyright © 2004, Oracle. All rights reserved.
Substitution Variables
• Use iSQL*Plus substitution variables to:
– Temporarily store values with single-ampersand (&)
and double-ampersand (&&) substitution
• Use substitution variables to supplement the
following:
– WHERE conditions
– ORDER BY clauses
– Column expressions
– Table names
– Entire SELECT statements
Copyright © 2004, Oracle. All rights reserved.
SELECT employee_id, last_name, salary, department_id
FROM employees
WHERE employee_id = &employee_num ;
Using the & Substitution Variable
Use a variable prefixed with an ampersand (&) to
prompt the user for a value:
Copyright © 2004, Oracle. All rights reserved.
Using the & Substitution Variable
101
1
2
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, department_id, salary*12
FROM employees
WHERE job_id = '&job_title' ;
Character and Date Values
with Substitution Variables
Use single quotation marks for date and character
values:
Copyright © 2004, Oracle. All rights reserved.
Specifying Column Names,
Expressions, and Text
SELECT employee_id, last_name, job_id,&column_name
FROM employees
WHERE &condition
ORDER BY &order_column ;
salary
salary > 15000
last_name
Copyright © 2004, Oracle. All rights reserved.
SELECT employee_id, last_name, job_id, &&column_name
FROM employees
ORDER BY &column_name ;
…
Using the && Substitution Variable
Use the double ampersand (&&) if you want to reuse
the variable value without prompting the user each
time:
Copyright © 2004, Oracle. All rights reserved.
Using the iSQL*Plus DEFINE Command
• Use the iSQL*Plus DEFINE command to create and
assign a value to a variable.
• Use the iSQL*Plus UNDEFINE command to remove
a variable.
DEFINE employee_num = 200
SELECT employee_id, last_name, salary, department_id
FROM employees
WHERE employee_id = &employee_num ;
UNDEFINE employee_num
Copyright © 2004, Oracle. All rights reserved.
old 3: WHERE employee_id = &employee_num
new 3: WHERE employee_id = 200
SET VERIFY ON
SELECT employee_id, last_name, salary, department_id
FROM employees
WHERE employee_id = &employee_num;
Using the VERIFY Command
Use the VERIFY command to toggle the display of the
substitution variable, both before and after iSQL*Plus
replaces substitution variables with values:
Copyright © 2004, Oracle. All rights reserved.
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table
[WHERE condition(s)]
[ORDER BY {column, expr, alias} [ASC|DESC]] ;
Summary
In this lesson, you should have learned how to:
• Use the WHERE clause to restrict rows of output:
– Use the comparison conditions
– Use the BETWEEN, IN, LIKE, and NULL conditions
– Apply the logical AND, OR, and NOT operators
• Use the ORDER BY clause to sort rows of output:
• Use ampersand substitution in iSQL*Plus to
restrict and sort output at run time
Copyright © 2004, Oracle. All rights reserved.
Practice 2: Overview
This practice covers the following topics:
• Selecting data and changing the order of
the rows that are displayed
• Restricting rows by using the WHERE clause
• Sorting rows by using the ORDER BY clause
• Using substitution variables to add flexibility to
your SQL SELECT statements

More Related Content

What's hot

【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲
【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲
【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲
アシアル株式会社
 
Haskell aula3 listas
Haskell aula3 listasHaskell aula3 listas
Haskell aula3 listas
CRISLANIO MACEDO
 
C# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesC# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data Types
Micheal Ogundero
 
TQC+ 程式語言 Python 09:檔案處理
TQC+ 程式語言 Python 09:檔案處理TQC+ 程式語言 Python 09:檔案處理
TQC+ 程式語言 Python 09:檔案處理
neochen2701
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Burhan Ahmed
 
TQC+ 程式語言 Python 07:數組、字典、集合
TQC+ 程式語言 Python 07:數組、字典、集合TQC+ 程式語言 Python 07:數組、字典、集合
TQC+ 程式語言 Python 07:數組、字典、集合
neochen2701
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
0927 sas實習課
0927 sas實習課0927 sas實習課
0927 sas實習課景淳 許
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
Pointers In C
Pointers In CPointers In C
Pointers In C
Simplilearn
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 

What's hot (13)

SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲
【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲
【アシアル塾】PHPオブジェクト指向再入門・第二回クラスの継承と委譲
 
Haskell aula3 listas
Haskell aula3 listasHaskell aula3 listas
Haskell aula3 listas
 
C# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesC# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data Types
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
TQC+ 程式語言 Python 09:檔案處理
TQC+ 程式語言 Python 09:檔案處理TQC+ 程式語言 Python 09:檔案處理
TQC+ 程式語言 Python 09:檔案處理
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
TQC+ 程式語言 Python 07:數組、字典、集合
TQC+ 程式語言 Python 07:數組、字典、集合TQC+ 程式語言 Python 07:數組、字典、集合
TQC+ 程式語言 Python 07:數組、字典、集合
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
0927 sas實習課
0927 sas實習課0927 sas實習課
0927 sas實習課
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
Pointers In C
Pointers In CPointers In C
Pointers In C
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 

Viewers also liked

Tupen 8 1235010002
Tupen 8   1235010002Tupen 8   1235010002
Tupen 8 1235010002
Abrianto Nugraha
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
ux singapore
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
Kirsty Hulse
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Stanford GSB Corporate Governance Research Initiative
 

Viewers also liked (8)

Les01
Les01Les01
Les01
 
Les02
Les02Les02
Les02
 
Tupen 8 1235010002
Tupen 8   1235010002Tupen 8   1235010002
Tupen 8 1235010002
 
Les02
Les02Les02
Les02
 
Les02
Les02Les02
Les02
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar to Les02

Les02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.pptLes02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.ppt
DrZeeshanBhatti
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data Base
Salman Memon
 
Subqueries -Oracle DataBase
Subqueries -Oracle DataBaseSubqueries -Oracle DataBase
Subqueries -Oracle DataBase
Salman Memon
 
Lesson02 学会使用WHERE、ORDER BY子句
Lesson02 学会使用WHERE、ORDER BY子句Lesson02 学会使用WHERE、ORDER BY子句
Lesson02 学会使用WHERE、ORDER BY子句
renguzi
 
Les02
Les02Les02
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Achmad Solichin
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
Syed Zaid Irshad
 
Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)
Achmad Solichin
 
Les06
Les06Les06
e computer notes - Restricting and sorting data
e computer notes -  Restricting and sorting datae computer notes -  Restricting and sorting data
e computer notes - Restricting and sorting dataecomputernotes
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
newrforce
 
Oracle examples
Oracle examplesOracle examples
Oracle examples
MaRwa Samih AL-Amri
 

Similar to Les02 (20)

Les06
Les06Les06
Les06
 
Les02.ppt
Les02.pptLes02.ppt
Les02.ppt
 
Les02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.pptLes02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.ppt
 
Les02
Les02Les02
Les02
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data Base
 
Subqueries -Oracle DataBase
Subqueries -Oracle DataBaseSubqueries -Oracle DataBase
Subqueries -Oracle DataBase
 
Lesson02 学会使用WHERE、ORDER BY子句
Lesson02 学会使用WHERE、ORDER BY子句Lesson02 学会使用WHERE、ORDER BY子句
Lesson02 学会使用WHERE、ORDER BY子句
 
Les02
Les02Les02
Les02
 
Les07
Les07Les07
Les07
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
 
Les06
Les06Les06
Les06
 
Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)
 
Les06
Les06Les06
Les06
 
Les06
Les06Les06
Les06
 
Les01
Les01Les01
Les01
 
e computer notes - Restricting and sorting data
e computer notes -  Restricting and sorting datae computer notes -  Restricting and sorting data
e computer notes - Restricting and sorting data
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
Oracle examples
Oracle examplesOracle examples
Oracle examples
 
Les08
Les08Les08
Les08
 

More from Abrianto Nugraha

Ds sn is-02
Ds sn is-02Ds sn is-02
Ds sn is-02
Abrianto Nugraha
 
Ds sn is-01
Ds sn is-01Ds sn is-01
Ds sn is-01
Abrianto Nugraha
 
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkapPertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Abrianto Nugraha
 
04 pemodelan spk
04 pemodelan spk04 pemodelan spk
04 pemodelan spk
Abrianto Nugraha
 
02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised
Abrianto Nugraha
 
01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan
Abrianto Nugraha
 
Pertemuan 7
Pertemuan 7Pertemuan 7
Pertemuan 7
Abrianto Nugraha
 
Pertemuan 7 dan_8
Pertemuan 7 dan_8Pertemuan 7 dan_8
Pertemuan 7 dan_8
Abrianto Nugraha
 
Pertemuan 5
Pertemuan 5Pertemuan 5
Pertemuan 5
Abrianto Nugraha
 
Pertemuan 6
Pertemuan 6Pertemuan 6
Pertemuan 6
Abrianto Nugraha
 
Pertemuan 4
Pertemuan 4Pertemuan 4
Pertemuan 4
Abrianto Nugraha
 
Pertemuan 3
Pertemuan 3Pertemuan 3
Pertemuan 3
Abrianto Nugraha
 
Pertemuan 2
Pertemuan 2Pertemuan 2
Pertemuan 2
Abrianto Nugraha
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
Abrianto Nugraha
 
Modul 1 mengambil nilai parameter
Modul 1   mengambil nilai parameterModul 1   mengambil nilai parameter
Modul 1 mengambil nilai parameter
Abrianto Nugraha
 
Modul 3 object oriented programming dalam php
Modul 3   object oriented programming dalam phpModul 3   object oriented programming dalam php
Modul 3 object oriented programming dalam php
Abrianto Nugraha
 
Modul 2 menyimpan ke database
Modul 2  menyimpan ke databaseModul 2  menyimpan ke database
Modul 2 menyimpan ke database
Abrianto Nugraha
 

More from Abrianto Nugraha (20)

Ds sn is-02
Ds sn is-02Ds sn is-02
Ds sn is-02
 
Ds sn is-01
Ds sn is-01Ds sn is-01
Ds sn is-01
 
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkapPertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
 
04 pemodelan spk
04 pemodelan spk04 pemodelan spk
04 pemodelan spk
 
02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised
 
01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan
 
Pertemuan 7
Pertemuan 7Pertemuan 7
Pertemuan 7
 
Pertemuan 7 dan_8
Pertemuan 7 dan_8Pertemuan 7 dan_8
Pertemuan 7 dan_8
 
Pertemuan 5
Pertemuan 5Pertemuan 5
Pertemuan 5
 
Pertemuan 6
Pertemuan 6Pertemuan 6
Pertemuan 6
 
Pertemuan 4
Pertemuan 4Pertemuan 4
Pertemuan 4
 
Pertemuan 3
Pertemuan 3Pertemuan 3
Pertemuan 3
 
Pertemuan 2
Pertemuan 2Pertemuan 2
Pertemuan 2
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
 
Modul 1 mengambil nilai parameter
Modul 1   mengambil nilai parameterModul 1   mengambil nilai parameter
Modul 1 mengambil nilai parameter
 
Modul 3 object oriented programming dalam php
Modul 3   object oriented programming dalam phpModul 3   object oriented programming dalam php
Modul 3 object oriented programming dalam php
 
Modul 2 menyimpan ke database
Modul 2  menyimpan ke databaseModul 2  menyimpan ke database
Modul 2 menyimpan ke database
 
Pbo 7
Pbo 7Pbo 7
Pbo 7
 
Pbo 6
Pbo 6Pbo 6
Pbo 6
 
Pbo 4
Pbo 4Pbo 4
Pbo 4
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

Les02

  • 1. Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data
  • 2. Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: • Limit the rows that are retrieved by a query • Sort the rows that are retrieved by a query • Use ampersand substitution in iSQL*Plus to restrict and sort output at run time
  • 3. Copyright © 2004, Oracle. All rights reserved. Limiting Rows Using a Selection “retrieve all employees in department 90” EMPLOYEES …
  • 4. Copyright © 2004, Oracle. All rights reserved. Limiting the Rows That Are Selected • Restrict the rows that are returned by using the WHERE clause: • The WHERE clause follows the FROM clause. SELECT *|{[DISTINCT] column|expression [alias],...} FROM table [WHERE condition(s)];
  • 5. Copyright © 2004, Oracle. All rights reserved. SELECT employee_id, last_name, job_id, department_id FROM employees WHERE department_id = 90 ; Using the WHERE Clause
  • 6. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, job_id, department_id FROM employees WHERE last_name = 'Whalen' ; Character Strings and Dates • Character strings and date values are enclosed by single quotation marks. • Character values are case-sensitive, and date values are format-sensitive. • The default date format is DD-MON-RR.
  • 7. Copyright © 2004, Oracle. All rights reserved. Comparison Conditions Not equal to<> Between two values (inclusive) BETWEEN ...AND... Match any of a list of valuesIN(set) Match a character patternLIKE Is a null valueIS NULL Less than< Less than or equal to<= Greater than or equal to>= Greater than> Equal to= MeaningOperator
  • 8. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, salary FROM employees WHERE salary <= 3000 ; Using Comparison Conditions
  • 9. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, salary FROM employees WHERE salary BETWEEN 2500 AND 3500 ; Using the BETWEEN Condition Use the BETWEEN condition to display rows based on a range of values: Lower limit Upper limit
  • 10. Copyright © 2004, Oracle. All rights reserved. SELECT employee_id, last_name, salary, manager_id FROM employees WHERE manager_id IN (100, 101, 201) ; Using the IN Condition Use the IN membership condition to test for values in a list:
  • 11. Copyright © 2004, Oracle. All rights reserved. SELECT first_name FROM employees WHERE first_name LIKE 'S%' ; Using the LIKE Condition • Use the LIKE condition to perform wildcard searches of valid search string values. • Search conditions can contain either literal characters or numbers: – % denotes zero or many characters. – _ denotes one character.
  • 12. Copyright © 2004, Oracle. All rights reserved. • You can combine pattern-matching characters: • You can use the ESCAPE identifier to search for the actual % and _ symbols. SELECT last_name FROM employees WHERE last_name LIKE '_o%' ; Using the LIKE Condition
  • 13. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, manager_id FROM employees WHERE manager_id IS NULL ; Using the NULL Conditions Test for nulls with the IS NULL operator.
  • 14. Copyright © 2004, Oracle. All rights reserved. Logical Conditions Returns TRUE if the following condition is false NOT Returns TRUE if either component condition is true OR Returns TRUE if both component conditions are true AND MeaningOperator
  • 15. Copyright © 2004, Oracle. All rights reserved. SELECT employee_id, last_name, job_id, salary FROM employees WHERE salary >=10000 AND job_id LIKE '%MAN%' ; Using the AND Operator AND requires both conditions to be true:
  • 16. Copyright © 2004, Oracle. All rights reserved. SELECT employee_id, last_name, job_id, salary FROM employees WHERE salary >= 10000 OR job_id LIKE '%MAN%' ; Using the OR Operator OR requires either condition to be true:
  • 17. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, job_id FROM employees WHERE job_id NOT IN ('IT_PROG', 'ST_CLERK', 'SA_REP') ; Using the NOT Operator
  • 18. Copyright © 2004, Oracle. All rights reserved. Rules of Precedence You can use parentheses to override rules of precedence. Not equal to6 NOT logical condition7 AND logical condition8 OR logical condition9 IS [NOT] NULL, LIKE, [NOT] IN4 [NOT] BETWEEN5 Comparison conditions3 Concatenation operator2 Arithmetic operators1 MeaningOperator
  • 19. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, job_id, salary FROM employees WHERE job_id = 'SA_REP' OR job_id = 'AD_PRES' AND salary > 15000; Rules of Precedence SELECT last_name, job_id, salary FROM employees WHERE (job_id = 'SA_REP' OR job_id = 'AD_PRES') AND salary > 15000; 1 2
  • 20. Copyright © 2004, Oracle. All rights reserved. Using the ORDER BY Clause • Sort retrieved rows with the ORDER BY clause: – ASC: ascending order, default – DESC: descending order • The ORDER BY clause comes last in the SELECT statement: SELECT last_name, job_id, department_id, hire_date FROM employees ORDER BY hire_date ; …
  • 21. Copyright © 2004, Oracle. All rights reserved. Sorting • Sorting in descending order: • Sorting by column alias: • Sorting by multiple columns: SELECT last_name, job_id, department_id, hire_date FROM employees ORDER BY hire_date DESC ; 1 SELECT employee_id, last_name, salary*12 annsal FROM employees ORDER BY annsal ; 2 SELECT last_name, department_id, salary FROM employees ORDER BY department_id, salary DESC; 3
  • 22. Copyright © 2004, Oracle. All rights reserved. Substitution Variables ... salary = ? … … department_id = ? … ... last_name = ? ... I want to query different values.
  • 23. Copyright © 2004, Oracle. All rights reserved. Substitution Variables • Use iSQL*Plus substitution variables to: – Temporarily store values with single-ampersand (&) and double-ampersand (&&) substitution • Use substitution variables to supplement the following: – WHERE conditions – ORDER BY clauses – Column expressions – Table names – Entire SELECT statements
  • 24. Copyright © 2004, Oracle. All rights reserved. SELECT employee_id, last_name, salary, department_id FROM employees WHERE employee_id = &employee_num ; Using the & Substitution Variable Use a variable prefixed with an ampersand (&) to prompt the user for a value:
  • 25. Copyright © 2004, Oracle. All rights reserved. Using the & Substitution Variable 101 1 2
  • 26. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, department_id, salary*12 FROM employees WHERE job_id = '&job_title' ; Character and Date Values with Substitution Variables Use single quotation marks for date and character values:
  • 27. Copyright © 2004, Oracle. All rights reserved. Specifying Column Names, Expressions, and Text SELECT employee_id, last_name, job_id,&column_name FROM employees WHERE &condition ORDER BY &order_column ; salary salary > 15000 last_name
  • 28. Copyright © 2004, Oracle. All rights reserved. SELECT employee_id, last_name, job_id, &&column_name FROM employees ORDER BY &column_name ; … Using the && Substitution Variable Use the double ampersand (&&) if you want to reuse the variable value without prompting the user each time:
  • 29. Copyright © 2004, Oracle. All rights reserved. Using the iSQL*Plus DEFINE Command • Use the iSQL*Plus DEFINE command to create and assign a value to a variable. • Use the iSQL*Plus UNDEFINE command to remove a variable. DEFINE employee_num = 200 SELECT employee_id, last_name, salary, department_id FROM employees WHERE employee_id = &employee_num ; UNDEFINE employee_num
  • 30. Copyright © 2004, Oracle. All rights reserved. old 3: WHERE employee_id = &employee_num new 3: WHERE employee_id = 200 SET VERIFY ON SELECT employee_id, last_name, salary, department_id FROM employees WHERE employee_id = &employee_num; Using the VERIFY Command Use the VERIFY command to toggle the display of the substitution variable, both before and after iSQL*Plus replaces substitution variables with values:
  • 31. Copyright © 2004, Oracle. All rights reserved. SELECT *|{[DISTINCT] column|expression [alias],...} FROM table [WHERE condition(s)] [ORDER BY {column, expr, alias} [ASC|DESC]] ; Summary In this lesson, you should have learned how to: • Use the WHERE clause to restrict rows of output: – Use the comparison conditions – Use the BETWEEN, IN, LIKE, and NULL conditions – Apply the logical AND, OR, and NOT operators • Use the ORDER BY clause to sort rows of output: • Use ampersand substitution in iSQL*Plus to restrict and sort output at run time
  • 32. Copyright © 2004, Oracle. All rights reserved. Practice 2: Overview This practice covers the following topics: • Selecting data and changing the order of the rows that are displayed • Restricting rows by using the WHERE clause • Sorting rows by using the ORDER BY clause • Using substitution variables to add flexibility to your SQL SELECT statements