Recuperare i dati

Introduzione a Oracle SQL

Sara Billen

Curriculum Manager

Personalizzare l'output

Chiave inglese e cacciavite incrociati

  • Eliminare i duplicati
  • Manipolare stringhe
  • Espressioni aritmetiche
  • Ordinare i dati
Introduzione a Oracle SQL

DISTINCT

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

* 412 righe selezionate

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

* 24 righe selezionate

Introduzione a Oracle SQL

Manipolare stringhe - Operatore di concatenazione

SELECT FirstName || LastName
FROM Customer
| FirstName || LastName       |
|-----------------------------|
| FrankHarris                 |
| HannahSchneider             |
| LucasMancini                |
| ...                         |
Introduzione a Oracle SQL

Manipolare stringhe - Stringhe letterali

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

Manipolare stringhe - Operatore di virgolette alternativo

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
Introduzione a Oracle SQL

Manipolare stringhe - Operatore di virgolette alternativo

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               |
| ...                                                    |
Introduzione a Oracle SQL

Espressioni aritmetiche

Crea espressioni con valori numerici e di data usando gli operatori aritmetici.

Operator Description
+ Add
- Subtract
* Multiply
/ Divide
Introduzione a Oracle SQL

Espressioni aritmetiche

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             |
Introduzione a Oracle SQL

Ordinare le righe

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 |
Introduzione a Oracle SQL

Ordinare le righe

Ordina in ordine decrescente:

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

Ordina per più colonne:

SELECT LastName, Title, City, HireDate 
FROM Employee
ORDER BY City, HireDate
Introduzione a Oracle SQL

Esercitiamoci!

Introduzione a Oracle SQL

Preparing Video For Download...