About the Author |
|
xvii | |
About the Technical Reviewer |
|
xix | |
Acknowledgments |
|
xxi | |
Introduction |
|
xxiii | |
Part I: Setting Up |
|
1 | (50) |
|
Chapter 1 What is a Database? |
|
|
3 | (6) |
|
Alternatives to Databases |
|
|
4 | (1) |
|
|
4 | (1) |
|
|
5 | (1) |
|
|
5 | (1) |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (2) |
|
|
9 | (42) |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
10 | (6) |
|
Windows, Linux, and What About Mac? |
|
|
16 | (1) |
|
|
17 | (4) |
|
Download Oracle SQL Developer |
|
|
21 | (2) |
|
|
23 | (1) |
|
|
24 | (4) |
|
|
28 | (3) |
|
|
31 | (5) |
|
Create a Connection with New User |
|
|
36 | (1) |
|
|
37 | (3) |
|
|
40 | (4) |
|
|
44 | (5) |
|
|
49 | (2) |
Part II: Viewing Data |
|
51 | (130) |
|
Chapter 3 Retrieving Data |
|
|
53 | (12) |
|
How Can You See the Data? |
|
|
53 | (1) |
|
What Is the SELECT Statement? |
|
|
53 | (1) |
|
|
54 | (1) |
|
Our First SELECT Statement |
|
|
55 | (1) |
|
Running a Statement in SQL Developer |
|
|
56 | (4) |
|
|
60 | (1) |
|
|
61 | (1) |
|
|
62 | (2) |
|
|
62 | (1) |
|
|
63 | (1) |
|
|
64 | (1) |
|
Chapter 4 Selecting Specific Columns |
|
|
65 | (12) |
|
Selecting a Single Column |
|
|
66 | (5) |
|
Selecting Multiple Columns |
|
|
71 | (2) |
|
|
73 | (2) |
|
SELECT Columns or SELECT *? |
|
|
75 | (1) |
|
|
76 | (1) |
|
Chapter 5 Restricting the Results |
|
|
77 | (12) |
|
|
77 | (1) |
|
What is the WHERE Clause? |
|
|
78 | (1) |
|
Example with a Text Value |
|
|
78 | (3) |
|
Example with a Number Value |
|
|
81 | (1) |
|
Finding Rows Not Equal to a Value |
|
|
82 | (1) |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
85 | (1) |
|
|
86 | (1) |
|
|
87 | (1) |
|
Specify Columns on the Left |
|
|
87 | (1) |
|
Select Only What You Need |
|
|
87 | (1) |
|
|
88 | (1) |
|
|
89 | (10) |
|
|
89 | (1) |
|
|
90 | (1) |
|
The Percent Wildcard Character |
|
|
90 | (2) |
|
The Underscore Wildcard Character |
|
|
92 | (3) |
|
Searching for Wildcard Characters |
|
|
95 | (1) |
|
|
96 | (1) |
|
|
97 | (2) |
|
Chapter 7 Applying Multiple Filters |
|
|
99 | (10) |
|
Why Use Multiple Filters? |
|
|
99 | (1) |
|
|
100 | (2) |
|
Finding Records That Match a Last Name and a Salary |
|
|
100 | (1) |
|
Finding Records that Match Greater Than and Less Than on Two Columns |
|
|
101 | (1) |
|
|
102 | (2) |
|
Finding Records that Match a Last Name or a Salary |
|
|
102 | (1) |
|
Finding Records that Match Greater Than or Less Than on Two Columns |
|
|
103 | (1) |
|
|
104 | (4) |
|
|
104 | (1) |
|
|
105 | (1) |
|
Combining Multiple AND and OR Conditions |
|
|
105 | (1) |
|
Specifying the Order with Multiple Conditions |
|
|
106 | (2) |
|
|
108 | (1) |
|
Chapter 8 Working with Nulls |
|
|
109 | (18) |
|
|
109 | (2) |
|
|
111 | (1) |
|
How Should NULL Be Treated? |
|
|
111 | (1) |
|
Examples of Working with NULL |
|
|
112 | (11) |
|
|
112 | (6) |
|
|
118 | (2) |
|
Restricting the NULL Values |
|
|
120 | (2) |
|
|
122 | (1) |
|
Multiple Queries in One SQL Window |
|
|
123 | (2) |
|
|
125 | (2) |
|
Chapter 9 Removing Duplicate Results |
|
|
127 | (10) |
|
|
128 | (2) |
|
|
130 | (1) |
|
|
131 | (1) |
|
Finding Unique Last Name Values |
|
|
132 | (3) |
|
Finding Unique Salary Values |
|
|
133 | (1) |
|
Finding Unique Combinations of Values |
|
|
134 | (1) |
|
|
135 | (2) |
|
Chapter 10 Applying Filters on Lists and Ranges of Values |
|
|
137 | (14) |
|
|
137 | (2) |
|
|
139 | (3) |
|
|
139 | (1) |
|
|
140 | (1) |
|
Using IN with Text Values |
|
|
141 | (1) |
|
Using IN with Other Clauses |
|
|
142 | (1) |
|
|
142 | (1) |
|
|
143 | (1) |
|
Filtering on Ranges of Values |
|
|
144 | (1) |
|
|
145 | (4) |
|
Using Between with Two Salary Values |
|
|
146 | (1) |
|
Using BETWEEN When Values Don't Match |
|
|
147 | (1) |
|
Using BETWEEN with Text Values |
|
|
147 | (1) |
|
An Example of an Inclusive and Exclusive Check |
|
|
148 | (1) |
|
|
149 | (1) |
|
|
149 | (2) |
|
Chapter 11 Ordering Your Data |
|
|
151 | (12) |
|
|
151 | (1) |
|
Ordering Results with ORDER BY |
|
|
152 | (1) |
|
|
153 | (8) |
|
|
153 | (1) |
|
|
154 | (2) |
|
Order by a Column Not in the SELECT Clause |
|
|
156 | (1) |
|
|
156 | (2) |
|
|
158 | (1) |
|
Order by Multiple Columns |
|
|
159 | (2) |
|
Do You Really Need to Order Your Data? |
|
|
161 | (1) |
|
|
162 | (1) |
|
Chapter 12 Applying Table and Column Aliases |
|
|
163 | (18) |
|
|
163 | (1) |
|
|
164 | (1) |
|
Intellisense or AutoComplete |
|
|
165 | (2) |
|
|
167 | (1) |
|
What If I Don't Use a Table Alias? |
|
|
168 | (1) |
|
|
168 | (1) |
|
Example of a Column Alias |
|
|
169 | (2) |
|
|
171 | (1) |
|
Mathematical Operations and Column Aliases |
|
|
172 | (6) |
|
|
173 | (2) |
|
|
175 | (1) |
|
|
176 | (1) |
|
|
177 | (1) |
|
Column Aliases with Table Aliases |
|
|
178 | (1) |
|
|
179 | (2) |
Part III: Adding, Updating, Deleting Data |
|
181 | (70) |
|
Chapter 13 Understanding the Data Types |
|
|
183 | (14) |
|
|
183 | (1) |
|
Why Do We Have Different Data Types? |
|
|
184 | (1) |
|
What Are the Different Data Types? |
|
|
185 | (1) |
|
|
185 | (4) |
|
|
186 | (1) |
|
|
186 | (1) |
|
|
187 | (1) |
|
|
188 | (1) |
|
|
189 | (1) |
|
|
189 | (1) |
|
|
189 | (3) |
|
|
190 | (1) |
|
|
190 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
192 | (1) |
|
|
192 | (2) |
|
|
192 | (1) |
|
|
192 | (1) |
|
|
193 | (1) |
|
TIMESTAMP WITH LOCAL TIME ZONE |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
194 | (1) |
|
|
194 | (1) |
|
|
194 | (1) |
|
|
195 | (1) |
|
Data Type Recommendations |
|
|
195 | (1) |
|
|
195 | (2) |
|
Chapter 14 Creating a Table |
|
|
197 | (16) |
|
Creating Tables Using SQL Code |
|
|
197 | (1) |
|
The CREATE TABLE Statement |
|
|
198 | (1) |
|
|
199 | (1) |
|
|
200 | (3) |
|
|
203 | (3) |
|
|
206 | (1) |
|
|
206 | (3) |
|
Recording the Employee Again |
|
|
209 | (1) |
|
|
209 | (3) |
|
|
212 | (1) |
|
Chapter 15 Adding Data to a Table |
|
|
213 | (12) |
|
|
213 | (1) |
|
Running an INSERT Statement |
|
|
214 | (2) |
|
|
216 | (2) |
|
|
218 | (3) |
|
Saving and Undoing Changes |
|
|
221 | (2) |
|
Best Practices for Inserting Data |
|
|
223 | (1) |
|
|
224 | (1) |
|
Chapter 16 Updating and Removing Data |
|
|
225 | (14) |
|
|
225 | (1) |
|
|
226 | (2) |
|
Checking an Update Statement Before Running It |
|
|
228 | (1) |
|
|
229 | (1) |
|
Update Based on Existing Value |
|
|
230 | (1) |
|
|
231 | (1) |
|
Viewing and Updating the Date Format |
|
|
232 | (1) |
|
|
233 | (1) |
|
Update Without WHERE Clause |
|
|
234 | (1) |
|
Removing Data from a Table |
|
|
235 | (1) |
|
|
236 | (1) |
|
Check What Records Will Be Deleted |
|
|
237 | (1) |
|
Delete All Records in a Table |
|
|
238 | (1) |
|
|
238 | (1) |
|
Chapter 17 Updating or Deleting a Table |
|
|
239 | (12) |
|
Why Update the Structure of a Table? |
|
|
239 | (1) |
|
The ALTER TABLE Statement |
|
|
240 | (1) |
|
|
241 | (1) |
|
Example: Change a Data Type |
|
|
242 | (1) |
|
Example: Add a Primary Key |
|
|
243 | (2) |
|
Example: Add a Foreign Key |
|
|
245 | (1) |
|
|
246 | (1) |
|
|
247 | (1) |
|
|
248 | (1) |
|
Removing a Table with DROP TABLE |
|
|
249 | (1) |
|
|
250 | (1) |
Part IV: Joining Tables |
|
251 | (50) |
|
|
253 | (10) |
|
|
253 | (1) |
|
|
254 | (1) |
|
|
255 | (2) |
|
Joins, Formatting, and Table Aliases |
|
|
257 | (3) |
|
|
260 | (2) |
|
|
262 | (1) |
|
|
263 | (12) |
|
|
263 | (1) |
|
Writing a Left Outer Join |
|
|
264 | (2) |
|
Showing All Employees with a Left Outer Join |
|
|
266 | (2) |
|
Writing a Right Outer Join |
|
|
268 | (2) |
|
When Would You Use a Right Outer Join? |
|
|
270 | (1) |
|
Writing a Full Outer Join |
|
|
270 | (2) |
|
Using a Full Outer Join on Our Tables |
|
|
272 | (1) |
|
|
273 | (2) |
|
Chapter 20 Other Join Types |
|
|
275 | (16) |
|
|
275 | (1) |
|
Updating the Office Table |
|
|
276 | (1) |
|
Writing a Query with the USING Keyword |
|
|
277 | (3) |
|
|
280 | (1) |
|
Writing a Query with a Natural Join |
|
|
280 | (2) |
|
|
282 | (2) |
|
|
284 | (1) |
|
|
285 | (4) |
|
|
285 | (1) |
|
|
286 | (2) |
|
Why You Shouldn't Use the Alternative Join Syntax |
|
|
288 | (1) |
|
|
289 | (2) |
|
Chapter 21 Joining Many Tables |
|
|
291 | (10) |
|
|
291 | (2) |
|
Joining Our Tables Together |
|
|
293 | (1) |
|
|
294 | (2) |
|
|
296 | (1) |
|
Joining Four or More Tables |
|
|
297 | (2) |
|
|
299 | (2) |
Part V: Functions |
|
301 | (90) |
|
Chapter 22 Using functions in SQL |
|
|
303 | (28) |
|
|
303 | (1) |
|
Where Can You Use Functions? |
|
|
304 | (1) |
|
Simple Numeric Calculations |
|
|
304 | (4) |
|
|
308 | (3) |
|
|
311 | (3) |
|
|
314 | (3) |
|
|
317 | (6) |
|
|
317 | (2) |
|
Checking for Matches on the Same Case |
|
|
319 | (3) |
|
|
322 | (1) |
|
|
323 | (4) |
|
|
327 | (3) |
|
|
327 | (1) |
|
|
328 | (2) |
|
|
330 | (1) |
|
Chapter 23 Writing Conditional Logic |
|
|
331 | (16) |
|
|
331 | (2) |
|
|
333 | (4) |
|
|
337 | (5) |
|
|
342 | (2) |
|
|
344 | (1) |
|
|
345 | (2) |
|
Chapter 24 Understanding Aggregate Functions |
|
|
347 | (18) |
|
|
348 | (1) |
|
|
348 | (3) |
|
|
349 | (1) |
|
|
350 | (1) |
|
|
350 | (1) |
|
|
351 | (1) |
|
|
351 | (6) |
|
|
352 | (1) |
|
|
352 | (2) |
|
|
354 | (2) |
|
|
356 | (1) |
|
|
357 | (3) |
|
|
357 | (1) |
|
|
358 | (1) |
|
|
359 | (1) |
|
|
360 | (2) |
|
|
360 | (2) |
|
|
362 | (1) |
|
|
362 | (2) |
|
|
362 | (1) |
|
|
363 | (1) |
|
|
364 | (1) |
|
Chapter 25 Grouping Your Results |
|
|
365 | (14) |
|
|
365 | (2) |
|
|
367 | (3) |
|
|
370 | (1) |
|
|
370 | (1) |
|
|
371 | (1) |
|
Restricting Results After Grouping |
|
|
372 | (2) |
|
|
374 | (2) |
|
GROUP BY, HAVING, and SUM |
|
|
376 | (1) |
|
Finding Duplicate Records |
|
|
376 | (2) |
|
|
378 | (1) |
|
Chapter 26 What Are Indexes? |
|
|
379 | (12) |
|
|
379 | (1) |
|
|
380 | (1) |
|
Example of Creating an Index |
|
|
380 | (4) |
|
Why Is Performance Important? |
|
|
384 | (1) |
|
|
384 | (1) |
|
|
384 | (1) |
|
|
385 | (1) |
|
|
385 | (3) |
|
|
387 | (1) |
|
The Disadvantages of Indexes |
|
|
388 | (1) |
|
Best Practices for Creating Indexes |
|
|
388 | (1) |
|
|
389 | (2) |
Part VI: Command Line |
|
391 | (20) |
|
Chapter 27 Using the Command Line |
|
|
393 | (18) |
|
What is SQL*Plus and Why Would You Use It? |
|
|
394 | (1) |
|
|
394 | (1) |
|
|
394 | (1) |
|
It's Available on Every Oracle Database |
|
|
395 | (1) |
|
You Don't Always Have Access to SQL Developer |
|
|
395 | (1) |
|
|
395 | (2) |
|
|
397 | (2) |
|
|
397 | (1) |
|
|
398 | (1) |
|
Running a Query in SQL*Plus |
|
|
399 | (2) |
|
Formatting Output in SQL*Plus |
|
|
401 | (3) |
|
Copy and Paste into SQL*Plus |
|
|
404 | (1) |
|
The Forward Slash Character |
|
|
404 | (1) |
|
|
405 | (1) |
|
|
406 | (1) |
|
How to Download and Run SQLcI |
|
|
407 | (3) |
|
|
410 | (1) |
Part VII: Appendixes |
|
411 | (12) |
|
Appendix: How to Find and Navigate the Oracle SQL Reference |
|
|
413 | (10) |
|
Finding the Oracle SQL Reference |
|
|
413 | (2) |
|
|
415 | (2) |
|
Find What You Need Using Table of Contents |
|
|
417 | (2) |
|
Find What You Need Using Search |
|
|
419 | (4) |
Index |
|
423 | |