Gegevens ophalen

Introductie tot Oracle SQL

Sara Billen

Curriculum Manager

Uitvoer aanpassen

Gekruiste moersleutel en schroevendraaier

  • Duplicaten onderdrukken
  • Strings bewerken
  • Rekenkundige expressies
  • Gegevens sorteren
Introductie tot Oracle SQL

DISTINCT

SELECT BillingCountry
FROM Invoice
| BillingCountry |
|----------------|
| Germany        |
| Germany        |
| USA            |
| Norway         |
| ...            |

* 412 rijen geselecteerd

SELECT DISTINCT BillingCountry
FROM Invoice
| BillingCountry |
|----------------|
| Germany        |
| Norway         |
| USA            |
| ...            |

* 24 rijen geselecteerd

Introductie tot Oracle SQL

Strings bewerken - Concatenatie-operator

SELECT FirstName || LastName
FROM Customer
| FirstName || LastName       |
|-----------------------------|
| FrankHarris                 |
| HannahSchneider             |
| LucasMancini                |
| ...                         |
Introductie tot Oracle SQL

Strings bewerken - Letterlijke tekenreeksen

SELECT 'Full name: ' || FirstName || ' ' || LastName
FROM Customer
| 'Full name: ' || FirstName || ' ' || LastName |
|-----------------------------------------------|
| Full name: Frank Harris                       |
| Full name: Hannah Schneider                   |
| Full name: Lucas Mancini                      |
| ...                                           |
Introductie tot Oracle SQL

Strings bewerken - Alternatieve aanhaaloperator

SELECT LastName || ': This employee's title is: ' || Title
FROM Employee
syntax error at or near "title"
LINE 1: SELECT LastName || ': This employee's title is: ' || Title
Introductie tot Oracle SQL

Strings bewerken - Alternatieve aanhaaloperator

SELECT LastName || q'[: This employee's title is: ]' || Title
FROM Employee
| LastName || q'[, this employee's title is: ]' || Title |
|--------------------------------------------------------|
| Adams: This employee's title is: General Manager       |
| Edwards: This employee's title is: Sales Manager       |
| Park: This employee's title is: Sales Support Agent    |
| King: This employee's title is: IT Staff               |
| ...                                                    |
Introductie tot Oracle SQL

Rekenkundige expressies

Maak expressies met getal- en datumwaarden met rekenkundige operatoren.

Operator Beschrijving
+ Optellen
- Aftrekken
* Vermenigv.
/ Delen
Introductie tot Oracle SQL

Rekenkundige expressies

SELECT TrackName, Milliseconds, Milliseconds / 1000
FROM Track
| TrackName                | Milliseconds | Milliseconds / 1000 |
|--------------------------|--------------|---------------------|
| Killer Queen             | 182099       | 182.099             |
| Smells Like Teen Spirit  | 301296       | 301.296             |
| The Star Spangled Banner | 43232        | 43.232              |
| With Or Without You      | 299023       | 299.023             |
Introductie tot Oracle SQL

Rijen sorteren

SELECT LastName, Title, City, HireDate 
FROM Employee
ORDER BY HireDate
| LastName | Title                 | City       | HireDate            |
|----------|-----------------------|------------|---------------------|
| Peacock  | Sales Support Agent   | Calgary    | 2002-04-01 00:00:00 |
| Edwards  | Sales Manager         | Calgary    | 2002-05-01 00:00:00 |
| Adams    | General Manager       | Edmonton   | 2002-08-14 00:00:00 |
| Park     | Sales Support Manager | Calgary    | 2003-05-03 00:00:00 |
| Johnson  | Sales Support Agent   | Calgary    | 2003-10-17 00:00:00 |
| Mitchell | IT Manager            | Calgary    | 2003-10-17 00:00:00 |
| King     | IT Staff              | Lethbridge | 2004-01-02 00:00:00 |
| Callahan | IT Staff              | Lethbridge | 2004-03-04 00:00:00 |
Introductie tot Oracle SQL

Rijen sorteren

Sorteer aflopend:

SELECT LastName, Title, City, HireDate 
FROM Employee
ORDER BY HireDate DESC

Sorteer op meerdere kolommen:

SELECT LastName, Title, City, HireDate 
FROM Employee
ORDER BY City, HireDate
Introductie tot Oracle SQL

Laten we oefenen!

Introductie tot Oracle SQL

Preparing Video For Download...