CourseNotes_Oracle Database 19c Basic SQL
CourseNotes_Oracle Database 19c Basic SQL
Description: Mastering SQL is an essential skill for any Oracle professional and
the first step in becoming a true Oracle expert. In this course, Bob Bryla covers
the basics required to code using SQL in an Oracle 19c Database environment. Bob
covers what you need to know to get data in and out of your database tables, as
well as how to modify data. He explains how to leverage SELECT statements, filter
and sort rows, use both single- and multiple-row functions, and join tables. He
delves into the Oracle data dictionary—a set of tables that provide information
about a database—and shows how to query it. Plus, he demonstrates how to
efficiently delete data using DML statements. Upon wrapping up this course, you'll
have the fundamental skills you need to work with SQL in this popular relational
database management system.
***********************************************
Chapter: 2. SELECT Statements
***********************************************
-----------------------------------------------
Video: SELECT statement clauses
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Column aliases
-----------------------------------------------
Note Time: Note Text:
0:03:44 Aliases are like synonyms and they can be used for columns or
expressions containing columns or even for expressions that don't reference a
column. They enhance the readability of query output. You can reference them in the
ORDER BY clause but not in the WHERE clause. Finally the one case where you must
use a column alias is when you use the Create Table As Select feature and the query
you're using to create the table has an expression.
0:03:44 creating a table that contains the result that from a query this
is know as CTAS or Create Table As Select. Explaination: column alias so that the
destination table has legal column names. When I use a query that is properly
aliased the table creates with no problems.
***********************************************
Chapter: 4. String Manipulation
***********************************************
-----------------------------------------------
Video: Concatenation
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: WHERE clause syntax
-----------------------------------------------
Note Time: Note Text:
0:04:06 BETWEEN is a shortcut for greater than or equal to, and less
than or equal to
-----------------------------------------------
Video: Subqueries in the WHERE clause
-----------------------------------------------
Note Time: Note Text:
0:00:55 Here are the two general types of subqueries, EXISTS and IN.
Both can be correlated as we'll see, but the biggest difference is that EXISTS
checks for at least one value. IN will check for the existence of one or more
column values in the subquery provided
***********************************************
Chapter: 7. Single-Row Functions
***********************************************
-----------------------------------------------
Video: Numeric functions
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Character functions returning character values
-----------------------------------------------
Note Time: Note Text:
0:01:09 They fall into five basic categories; character, numeric, date,
and date arithmetic, conversion, and general.
***********************************************
Chapter: 8. Aggregation and Multiple-Row Functions
***********************************************
-----------------------------------------------
Video: GROUP BY clause
-----------------------------------------------
Note Time: Note Text:
0:01:18 Use SQL Developer to list all the built-in functions available
in Oracle.
Benefits:
Time-Saving: Quickly access a list of functions without running the query each
time.
Filter and Search: Easily filter and search through the list of functions to find
what you need.
Example:
Imagine you frequently need to find functions related to text manipulation. By
creating this report, you can quickly search for functions like UPPER() or LOWER()
without manually looking them up each time.
Practical Use:
Efficiency: Saves time and effort when working with SQL functions.
Convenience: Keeps all function details in one easily accessible place.
Key Points:
Categories of General Functions:
If the input is NULL, the function returns NULL. For example, if you try to hash a
NULL value, you get NULL.
Example:
If you want to see the internal storage of a date, you can use a function to get a
binary or hexadecimal representation of it.
Practical Use:
Data Analysis: Extract specific information from complex data types.
Data Management: Handle and manipulate large and varied data sets.
0:01:18 Purpose:
Convert one data type to another (e.g., text to number, text to date).
Example:
If you have a column with dates stored as text, you can use TO_DATE('2023-10-01',
'YYYY-MM-DD') to convert it to a date format.
Handling Errors:
If the data can't be converted (e.g., trying to convert "abc" to a number), you can
use the DEFAULT option to handle errors gracefully. For example, TO_NUMBER('abc'
DEFAULT -1 ON CONVERSION ERROR) will return -1 instead of an error.
Practical Use:
Data Cleaning: Convert inconsistent data types to a standard format.
Data Analysis: Perform calculations and comparisons on converted data
These functions help you work with date and time values in SQL.
ROUND() and TRUNC(): Can be used on dates to round or truncate to a specific unit
(like day, month, etc.).
SYSDATE and SYSTIMESTAMP: Return the current system date and time.
These functions deal with periods of time, like years and months or days and
seconds.
Example: MONTHS_BETWEEN(date1, date2) returns the number of months between two
dates.
LAST_DAY(date): Returns the last day of the month for the given date.
ADD_MONTHS(date, n): Adds n months to a date.
Example:
If you want to find the date 100 months after an employee's hire date, you can use
ADD_MONTHS(hire_date, 100).
Practical Use:
Data Analysis: Calculate durations, filter data based on date ranges, and perform
other date-related operations.
Reporting: Generate reports that require date calculations, like monthly sales or
employee tenure.
By understanding these functions, you can effectively manage and analyze date and
time data in your database, making your SQL queries more powerful and precise.
Key Concepts:
What Are Character Functions Returning Numeric Values?
These are functions in SQL that take text (character strings) as input and return a
number.
Types of Functions:
INSTR(): Finds the position of a substring within a string. For example, finding
where "ing" appears in "learning".
REGEXP_INSTR(): Similar to INSTR(), but uses regular expressions for more complex
searches.
Example:
Imagine you have a list of addresses and you want to find those that contain the
letter "V". You can use INSTR() to get the position of "V" in each address. If the
function returns a number greater than 0, it means "V" is present in that address.
Practical Use:
Data Cleaning: Use these functions to find and correct errors in text data.
Data Analysis: Extract specific patterns or information from text data for
analysis.
By understanding these functions, you can perform more advanced text searches and
manipulations in your database, making your data analysis more powerful and
accurate.
Pattern Matching:
SUBSTR(): Extracts a part of the string. For example, taking the first 5 characters
of a name.
Example:
If you have a column with names in lowercase, you can use UPPER(name) to convert
all names to uppercase.
By understanding these functions, you can clean and format your text data more
effectively.
0:01:18 They take numbers as input and return a single number as output.
Examples include calculating sums, averages, or other mathematical operations.
SELECT Clause: To show the result of the function in your query results.
WHERE Clause: To filter rows based on the function’s result.
GROUP BY and HAVING Clauses: To group data and apply conditions on the grouped
data.
If the input is NULL, the function returns NULL. For example, SUM(NULL) returns
NULL.
Example:
If you want to find the total salary of all employees in a department, you can use
SUM(salary) to get that number.
By using these functions, you can perform powerful calculations and analyses on
your data.
0:01:18 don't have a group by clause, it's implied. Here are some of the
most common group functions many of which you'll use every day. The average
function calculates the numeric average, count returns the number of rows per
group, min and max return the minimum and maximum results respectively. The
standard deviation and variance are familiar to anyone who has to do any
statistical analysis. When you get to functions like listagg, it becomes more
database specific. Listagg takes all the strings within a group and concatenates
them together
-----------------------------------------------
Video: Using DISTINCT
-----------------------------------------------
Note Time: Note Text:
***********************************************
Chapter: 9. Joining Tables
***********************************************
-----------------------------------------------
Video: ANSI joins versus Oracle join syntax
-----------------------------------------------
Note Time: Note Text:
Oracle Syntax:
Recommendation: It's better to use ANSI syntax because it's more readable and works
well across different databases.
Oracle Syntax:
Recommendation: It's better to use ANSI syntax because it's more readable and works
well across different databases.
0:02:10 Oracle's proprietary syntax uses the plus sign as short hand to
indicate an outer join.
-----------------------------------------------
Video: (INNER) JOIN
-----------------------------------------------
Note Time: Note Text:
0:00:36 An INNER JOIN or just JOIN in the from clause joins two or more
tables and returns rows in the JOIN from those tables only where that value exists
in both tables.
-----------------------------------------------
Video: RIGHT (OUTER) JOIN
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: CROSS JOIN
-----------------------------------------------
Note Time: Note Text:
***********************************************
Chapter: 11. DML: INSERT
***********************************************
-----------------------------------------------
Video: Inserting multiple rows
-----------------------------------------------
Note Time: Note Text:
0:03:52 Rules:
If you don't list all columns, the ones you leave out must be able to be empty
(NULL).
If you don't specify the column names, you must provide values for all columns in
the correct order.
-----------------------------------------------
Video: UPDATE table rows
-----------------------------------------------
Note Time: Note Text:
Syntax:
sql
INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;
Syntax:
sql
INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;
Syntax:
sql
INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;
Syntax:
sql
INSERT ALL
INTO table1 (column1, column2, ...) VALUES (value1, value2, ...)
INTO table2 (column1, column2, ...) VALUES (value1, value2, ...)
SELECT column1, column2, ...
FROM source_table;
Syntax:
sql
CREATE TABLE new_table AS
SELECT column1, column2, ...
FROM source_table
WHERE condition;
-----------------------------------------------
Video: DELETE rows with or without WHERE
-----------------------------------------------
Note Time: Note Text:
This deletes all rows in the jobs table. Use with caution!
0:02:23 Purpose: The TRUNCATE command quickly removes all rows from a
table.
Syntax:
sql
TRUNCATE TABLE table_name;
0:03:08 Rollback: TRUNCATE cannot be rolled back, unlike DELETE.
***********************************************
Chapter: 12. DDL: Creating Objects
***********************************************
-----------------------------------------------
Video: Creating tables
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Creating indexes
-----------------------------------------------
Note Time: Note Text:
Stores a series of bit strings based on the number of unique values in a column.
Stores a series of bit strings based on the number of unique values in a column.
Balanced Tree: Ensures that any access to an index entry won't be more than two or
three levels deep.
Unique or Non-Unique:
Unique: No duplicate values are allowed in the indexed column(s).
Non-Unique: Duplicate values are allowed.
***********************************************
Chapter: 13. Dropping Objects
***********************************************
-----------------------------------------------
Video: Dropping tables
-----------------------------------------------
Note Time: Note Text:
0:00:54 we really needed it back? It usually takes two steps, first, you
use SHOW RECYCLEBIN or quote the Recycle Bin daily dictionary view, Recycle Bin.
Step two, you might think that it will be the RECOVER or RESTORE command, but to
get a table out of the Recycle Bin, you us the FLASHBACK TABLE command.
0:00:54 "How long will objects reside in the Recycle Bin?" They'll stay
there indefinitely, given unto an explicit PURGE command by the user or DBA.
0:00:54 you can add the PURGE key word if you want to free up space
occupied by the table and disc.
-----------------------------------------------
Video: Dropping indexes
-----------------------------------------------
Note Time: Note Text:
0:01:24 Use the DROP INDEX command with the index name and optionally
the schema name.
The ONLINE keyword allows DML operations on the table while the index is being
dropped.
0:01:26 Dropped indexes and tables can be restored from the recycle bin
using the FLASHBACK TABLE command.
0:03:19 Finally, you won't be able to drop an index with the online
keyword if it's a special index, like a domain index or a cluster index.
-----------------------------------------------
Video: Drop Oracle specific tables
-----------------------------------------------
Note Time: Note Text: