Recuperando dados

Introdução ao Oracle SQL

Sara Billen

Curriculum Manager

Personalizando a saída

Chave inglesa e chave de fenda cruzadas

  • Suprimir duplicatas
  • Manipular strings
  • Expressões aritméticas
  • Ordenar dados
Introdução ao Oracle SQL

DISTINCT

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

* 412 linhas selecionadas

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

* 24 linhas selecionadas

Introdução ao Oracle SQL

Manipulando strings - Operador de concatenação

SELECT FirstName || LastName
FROM Customer
| FirstName || LastName       |
|-----------------------------|
| FrankHarris                 |
| HannahSchneider             |
| LucasMancini                |
| ...                         |
Introdução ao Oracle SQL

Manipulando strings - Strings literais

SELECT 'Full name: ' || FirstName || ' ' || LastName
FROM Customer
| 'Full name: ' || FirstName || ' ' || LastName |
|-----------------------------------------------|
| Full name: Frank Harris                       |
| Full name: Hannah Schneider                   |
| Full name: Lucas Mancini                      |
| ...                                           |
Introdução ao Oracle SQL

Manipulando strings - Operador de aspas 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
Introdução ao Oracle SQL

Manipulando strings - Operador de aspas 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               |
| ...                                                    |
Introdução ao Oracle SQL

Expressões aritméticas

Crie expressões com valores de número e data usando operadores aritméticos.

Operator Description
+ Adição
- Subtração
* Multiplicação
/ Divisão
Introdução ao Oracle SQL

Expressões aritméticas

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             |
Introdução ao Oracle SQL

Ordenando linhas

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 |
Introdução ao Oracle SQL

Ordenando linhas

Ordenar em ordem decrescente:

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

Ordenar por várias colunas:

SELECT LastName, Title, City, HireDate 
FROM Employee
ORDER BY City, HireDate
Introdução ao Oracle SQL

Vamos praticar!

Introdução ao Oracle SQL

Preparing Video For Download...