Introduction to Oracle SQL
Sara Billen
Curriculum Manager
SELECT BillingCountry
FROM Invoice
| BillingCountry |
|----------------|
| Germany |
| Germany |
| USA |
| Norway |
| ... |
* 412 rows selected
SELECT DISTINCT BillingCountry
FROM Invoice
| BillingCountry |
|----------------|
| Germany |
| Norway |
| USA |
| ... |
* 24 rows selected
SELECT FirstName || LastName
FROM Customer
| FirstName || LastName |
|-----------------------------|
| FrankHarris |
| HannahSchneider |
| LucasMancini |
| ... |
SELECT 'Full name: ' || FirstName || ' ' || LastName
FROM Customer
| 'Full name: ' || FirstName || ' ' || LastName |
|-----------------------------------------------|
| Full name: Frank Harris |
| Full name: Hannah Schneider |
| Full name: Lucas Mancini |
| ... |
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
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 |
| ... |
Create expressions with number and date values by using arithmetic operators.
Operator | Description |
---|---|
+ | Add |
- | Subtract |
* | Multiply |
/ | Divide |
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 |
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 |
Order in descending order:
SELECT LastName, Title, City, HireDate
FROM Employee
ORDER BY HireDate DESC
Order by multiple columns:
SELECT LastName, Title, City, HireDate
FROM Employee
ORDER BY City, HireDate
Introduction to Oracle SQL