Restreindre les données

Introduction à Oracle SQL

Sara Billen

Curriculum Manager

Filtrer des lignes

Filtrer

 

  • Opérateurs de comparaison
  • Mots-clés de comparaison
  • Opérateurs logiques
Introduction à Oracle SQL

WHERE

SELECT FirstName, LastName, Country 
FROM Customer
WHERE Country = 'Portugal'
| FirstName | LastName  | Country  |
|-----------|-----------|----------|
| João      | Fernandes | Portugal |
| Madalena  | Sampaio   | Portugal |
Introduction à Oracle SQL

Opérateurs de comparaison

Opérateur Description
> Plus grand que
>= Plus grand ou égal à
< Plus petit que
<= Plus petit ou égal à
= Égal
<> Différent
SELECT UnitPrice
FROM Track
WHERE UnitPrice <> 0.99
Introduction à Oracle SQL

Mots-clés de comparaison

  Fonctionnalités additionnelles de WHERE

Introduction à Oracle SQL

Mots-clés de comparaison - BETWEEN

SELECT Name, Milliseconds 
FROM Track
WHERE Milliseconds BETWEEN 100000 AND 200000
| Name              | Milliseconds |
|-------------------|--------------|
| Perfect           | 188133       |
| Right Through You | 176117       |
| We Die Young      | 152084       |
| Put You Down      | 196231       |
| ...                              |
Introduction à Oracle SQL

Mots-clés de comparaison - IN

SELECT EmployeeId, LastName, Title
FROM Employee
WHERE EmployeeId IN (4, 5, 6)
| EmployeeId | LastName | Title               |
|------------|----------|---------------------|
| 4          | Park     | Sales Support Agent |
| 5          | Johnson  | Sales Support Agent |
| 6          | Mitchell | IT Manager          |
Introduction à Oracle SQL

Mots-clés de comparaison - LIKE

Sélectionnez les lignes correspondant à un motif de caractères avec LIKE

 

Symbole Description
% Représente toute suite de 0 caractère ou plus
_ Représente un seul caractère
Introduction à Oracle SQL

Mots-clés de comparaison - LIKE

SELECT LastName
FROM Employee
WHERE LastName LIKE '_a%'
| LastName |
|----------|
| Park     |
| Callahan |
Introduction à Oracle SQL

Opérateurs logiques

  Opérateurs logiques

Introduction à Oracle SQL

Opérateurs logiques - AND

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry = 'Australia' 
      AND Total > 4
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 66        | Australia      | 5.94  |
| 250       | Australia      | 13.86 |
| 305       | Australia      | 8.91  |
Introduction à Oracle SQL

Opérateurs logiques - OR

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry = 'Australia' 
      OR Total > 4
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 3         | Belgium        | 5.94  |
| 4         | Canada         | 8.91  |
| 5         | USA            | 13.86 |
| 10        | Ireland        | 5.94  |
| ...                                |
Introduction à Oracle SQL

Opérateurs logiques - NOT

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry NOT IN ('Australia', 'Canada', 'United Kingdom')
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 1         | Germany        | 1.98  |
| 2         | Norway         | 3.96  |
| 3         | Belgium        | 5.94  |
| 5         | USA            | 13.86 |
| ...                                |
Introduction à Oracle SQL

Récapitulatif

WHERE : filtrer les lignes selon une condition

  • Opérateurs de comparaison : =, <, >, <=, >=, <>
  • Mots-clés de comparaison : BETWEEN, IN, LIKE
  • Opérateurs logiques : AND, OR, NOT
Introduction à Oracle SQL

Passons à la pratique !

Introduction à Oracle SQL

Preparing Video For Download...