0% found this document useful (0 votes)
0 views

CourseNotes_Oracle Database 19c Basic SQL

The course 'Oracle Database 19c: Basic SQL' teaches fundamental SQL skills necessary for working with Oracle databases, including data retrieval, modification, and querying the Oracle data dictionary. Key topics include SELECT statements, filtering rows, string manipulation, and joining tables, along with practical applications of single-row and multiple-row functions. By the end of the course, participants will have the essential skills to effectively use SQL in Oracle 19c environments.

Uploaded by

20cse0129
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

CourseNotes_Oracle Database 19c Basic SQL

The course 'Oracle Database 19c: Basic SQL' teaches fundamental SQL skills necessary for working with Oracle databases, including data retrieval, modification, and querying the Oracle data dictionary. Key topics include SELECT statements, filtering rows, string manipulation, and joining tables, along with practical applications of single-row and multiple-row functions. By the end of the course, participants will have the essential skills to effectively use SQL in Oracle 19c environments.

Uploaded by

20cse0129
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 12

Course Title: 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:

0:00:02 To run a SELECT statement or any statement in SQL Developer, put


the cursor on the statement itself, then either press F9, Control + Enter.

-----------------------------------------------
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:

0:01:50 Concatenating expressions or columns that evaluate to a number


or date, are implicitly converted to a string
***********************************************
Chapter: 5. Filtering Rows
***********************************************

-----------------------------------------------
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:

0:00:57 Single-Row Functions return a Single-Row or Column Value for


every row of the query. These functions can appear in five places, the SELECT
clause, WHERE clause, the START WITH/CONNECT BY clause, the GROUP BY clause and the
HAVING clause. Notice that some of these are conditional.

-----------------------------------------------
Video: Character functions returning character values
-----------------------------------------------
Note Time: Note Text:

0:00:00 Any operations on NULL returns NULL

0:01:09 The SELECT clause, WHERE clause, the START WITH/CONNECT BY


clause, the GROUP BY clause and the HAVING clause.

0:01:09 the character functions that return a character string. Single-


row functions return a single-row or column value for every row of the query.

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.

Steps to Create a Report:

Open SQL Developer: Start the application.


Run a Query: Use a specific query to list all functions, including details like the
number of arguments and if it's an analytic or aggregate function.
Create a New Report: Right-click on the user-defined reports section, select "New
Report," and name it.
Save and Run the Report: Save the report so you can easily run it in the future
without retyping the query.

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.

0:01:18 What Are General Functions?


These are versatile tools in SQL that can handle various types of data, including
text, numbers, and complex data like XML and JSON.

Key Points:
Categories of General Functions:

Comparison Operations: Compare different values.


Large Object Operations: Work with large data types like XML and JSON.
Collection Management: Manage sets of data.
Encoding/Decoding: Convert data to different formats.

Where to Use Them:

SELECT Clause: To show the results of the function.


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.
Handling NULL Values:

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.

By understanding these functions, you can perform a wide range of operations on


different types of data in your database, making your SQL queries more powerful and
flexible.

0:01:18 Purpose:

Convert one data type to another (e.g., text to number, text to date).

Common Conversion Functions:

TO_NUMBER(): Converts text to a number.


TO_CHAR(): Converts numbers or dates to text.
TO_DATE(): Converts text to a date.

Where You Can Use Them:

SELECT Clause: To show the converted data in your results.


WHERE Clause: To filter rows based on the converted data.
GROUP BY and HAVING Clauses: To group data and apply conditions on the grouped
data.

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.

Handling NULL Values:


If the input is NULL, the function returns NULL. For example, TO_NUMBER(NULL)
returns NULL.

Practical Use:
Data Cleaning: Convert inconsistent data types to a standard format.
Data Analysis: Perform calculations and comparisons on converted data

0:01:18 Datetime Functions:

These functions help you work with date and time values in SQL.

Types of Datetime Columns:


Date Columns: Store dates to the nearest second and always take up 7 bytes.
Timestamp Columns: More flexible, can store dates to the nearest nanosecond (9
digits of precision) and can include timezone information. They can take up to 13
bytes depending on the precision and timezone data.

Common Datetime Functions:

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.

Time Interval Functions:

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.

Miscellaneous Date Functions:

LAST_DAY(date): Returns the last day of the month for the given date.
ADD_MONTHS(date, n): Adds n months to a date.

Using Datetime Functions in SQL Clauses:

SELECT Clause: To display date-related calculations.


WHERE Clause: To filter rows based on date conditions.
GROUP BY and HAVING Clauses: To group data and apply conditions on grouped data.

Example:
If you want to find the date 100 months after an employee's hire date, you can use
ADD_MONTHS(hire_date, 100).

Handling NULL Values:


If a datetime function operates on a NULL value, it returns NULL. For example,
EXTRACT(MINUTE FROM NULL) returns NULL.

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.

0:01:18 Character Functions Returning Numeric Values from the video:

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.

Where to Use Them:

SELECT Clause: To display the result of the function.


WHERE Clause: To filter rows based on the result.
GROUP BY and HAVING Clauses: To group data and apply conditions on the grouped
data.

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.

Handling NULL Values:


If the input string is NULL, the function returns NULL. For example, searching for
"Y" in a NULL state/province field will return NULL.

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.

0:01:18 Character Functions Returning Character Values:

What Are They?


These are special tools in SQL that work with text data and return a modified text.

Types of Character Functions:


General String Manipulation:

INITCAP(): Changes the first letter of each word to uppercase.


UPPER(): Converts all letters to uppercase.

Pattern Matching:

SOUNDEX(): Finds words that sound similar, even if spelled differently.


REGEXP_REPLACE(): Uses patterns to find and replace parts of a string.

Returning Found Values:

SUBSTR(): Extracts a part of the string. For example, taking the first 5 characters
of a name.

Where to Use Them:


SELECT Clause: To show the modified text in your results.
WHERE Clause: To filter rows based on the modified text.
GROUP BY and HAVING Clauses: To group data and apply conditions on the grouped
data.

Handling NULL Values:


If the input text is NULL, the function returns NULL. For example, UPPER(NULL)
returns NULL.

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.

Common Numeric Functions:

SUM(): Adds up all the numbers in a column.


AVG(): Calculates the average of the numbers.
MOD(): Finds the remainder when one number is divided by another.

Where You Can Use Them:

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.

Handling NULL Values:

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

0:02:04 NULL ignored except for COUNT(*)

0:02:58 COUNT(*) --> total no of rows that satisfy where condition

-----------------------------------------------
Video: Using DISTINCT
-----------------------------------------------
Note Time: Note Text:

0:00:55 unique and distinct are same


0:01:36 distinct removes duplicates

***********************************************
Chapter: 9. Joining Tables
***********************************************

-----------------------------------------------
Video: ANSI joins versus Oracle join syntax
-----------------------------------------------
Note Time: Note Text:

0:00:32 ANSI Syntax:

Uses keywords like NATURAL JOIN, USING, and ON.


All the join logic (how tables are combined) is in the FROM clause.
Filtering (which rows to keep) is in the WHERE clause.
Easier to read and write because it separates joining and filtering.

Oracle Syntax:

Uses the + sign for outer joins.


Both join and filtering logic are in the WHERE clause.
Can mix both syntaxes, but it's not recommended for clarity.

Recommendation: It's better to use ANSI syntax because it's more readable and works
well across different databases.

0:00:55 ANSI Syntax:

Uses keywords like NATURAL JOIN, USING, and ON.


All the join logic (how tables are combined) is in the FROM clause.
Filtering (which rows to keep) is in the WHERE clause.
Easier to read and write because it separates joining and filtering.

Oracle Syntax:

Uses the + sign for outer joins.


Both join and filtering logic are in the WHERE clause.
Can mix both syntaxes, but it's not recommended for clarity.

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:

0:00:02 Placement of join :


In ANSI --> places in FROM clause
In Oracle --> places in WHERE clause

-----------------------------------------------
Video: CROSS JOIN
-----------------------------------------------
Note Time: Note Text:

0:02:30 cross join


ANSI ---> A cross join B
Oracle ---> A, B

***********************************************
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.

0:04:35 Basic Syntax:INSERT INTO table_name (column1, column2) VALUES


(value1, value2);

-----------------------------------------------
Video: UPDATE table rows
-----------------------------------------------
Note Time: Note Text:

0:01:35 INSERT Using Subquery


This method inserts multiple rows from another table.

Syntax:
sql
INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;

0:01:40 INSERT Using Subquery


This method inserts multiple rows from another table.

Syntax:
sql
INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;

0:01:42 INSERT Using Subquery


This method inserts multiple rows from another table.

Syntax:
sql
INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;

0:02:00 INSERT ALL


This method inserts multiple rows into multiple tables.

Syntax:
sql
INSERT ALL
INTO table1 (column1, column2, ...) VALUES (value1, value2, ...)
INTO table2 (column1, column2, ...) VALUES (value1, value2, ...)
SELECT column1, column2, ...
FROM source_table;

0:02:24 CREATE TABLE AS SELECT (CTAS)


This method creates a new table and populates it with rows from an existing table.

Syntax:
sql
CREATE TABLE new_table AS
SELECT column1, column2, ...
FROM source_table
WHERE condition;

0:03:42 Issue: Arithmetic operations with NULL result in NULL

-----------------------------------------------
Video: DELETE rows with or without WHERE
-----------------------------------------------
Note Time: Note Text:

0:02:00 DELETE FROM jobs;

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:

0:00:09 Truncate - DDL


Delete - DML

0:00:28 The table's data is stored in a specific area of the database


called a tablespace.

0:00:28 Basic syntax:


sql
CREATE TABLE table_name (
column1_name data_type,
column2_name data_type
);

-----------------------------------------------
Video: Creating indexes
-----------------------------------------------
Note Time: Note Text:

0:01:45 What is an Index?


An index is a database object that helps speed up the retrieval of rows from a
table.

0:05:05 CREATE INDEX index_name ON table_name (column1, column2, ...);

0:05:05 Bitmap Index:

Stores a series of bit strings based on the number of unique values in a column.

0:05:05 Bitmap Index:

Stores a series of bit strings based on the number of unique values in a column.

0:05:05 Types of Indexes


B-Tree Index:

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.

0:05:27 CREATE INDEX index_name ON table_name (column1, column2, ...);

***********************************************
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.

0:02:01 Primary Key Constraint: A unique B-Tree index can enforce a


primary key constraint

0:04:30 Types of Indexes


B-Tree Index: Balanced Tree,Unique or Non-Unique,Primary Key Constraint
Bitmap Index: Compact and Fast, Overhead.

-----------------------------------------------
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:

0:00:25 Use the DROP INDEX command to permanently remove an index.

You might also like