SlideShare a Scribd company logo
Introduction to
Oracle DB
By Siddhant Bhardwaj
Important Terms to Remember
In the simplest terms, a database is a collection of
information, that is being stored in a systematic manner.
This information is stored in a database is known as data
Data is a collection of facts, such as numbers, words,
measurements, observations or just descriptions of things.
Data can be Qualitative or Quantitative.
Important Terms to Remember
Qualitative Data is Descriptive Data, i.e., it describes something in
words.
Quantitative Data is Numerical Data, i.e. it describes something in
terms of Numbers.
What Is A Table ?
A table is a database object which is comprised of rows and columns in
SQL.
Simplifying it more we can say that it’s a collection of related data held
in a table format.
What Are Fields In A Table
Fields are basically columns in a table with specific information about
the data.
They are attributes of a real-world object that we are interested in,
which we will be storing as a column in a table.
What Are Records In A Table
A record is basically an individual entry that exists in a table.
Records give the complete information of a single entry or entity.
Thus, records equate to an individual row in a table.
What Is A Schema In A Database
A Schema is a collection of various logical data structures. The database
user owns the schema and it has the same name as that of the user.
The main aim of Schema in SQL is to aid in security management.
It helps in defining which users have the authority to access which
database objects.
Installing Oracle in Windows
Google Oracle Database Downloads
Click on the link to Oracle Database Express
Installing Oracle in Windows
Download the latest version of Oracle Database Express Edition for
Windows x64 machine.
Installing Oracle in Windows
Once it has been downloaded, extract the files from the downloaded
folder.
Next click the setup.exe file, which will initiate the installation folder.
Accept the terms and conditions
Keep clicking on the Next button.
Set up your password and confirm it.
Installing Oracle in Windows
Next, navigate to the C Drive and oracleexe folder inside it.
Go to app -> oracle -> product -> folder bearing version number ->
server -> Get Started shortcut file.
Here, edit the properties by right-clicking on the file and change the
URL to 8080.
Installing Oracle in Windows
Installing Oracle in Windows
Now launch localhost:8080 on your browser and click on Application
Express.
Enter your user login credentials to log in (username - sys and your
password)
Installing Oracle in Windows
Create a session in application express and then log into it. If you search
for sql command line in start menu, you will be able to access your
database from CLI also.
Installing Oracle in Windows
Download the latest Windows 64 bit version of Oracle Developer on your device
from the Oracle Website.
You will have to create an account with Oracle in order to download it
Extract the files from downloaded zipped file and copy the extracted folder to the
C Drive.
Enter the folder and now create a shortcut for the SQL Developer in order to run
and use the Oracle Developer.
You can use your Application Express username and password to log into the
developer.
Installing Oracle On A Mac
Install and run Docker Desktop for Mac from here -
https://docs.docker.com/desktop/install/mac-install/
Install Docker Toolbox from Toolbox Releases and download the latest
.pkg file - https://github.com/docker-archive/toolbox/releases
Open terminal and run following command to install the oracle-11g-xe -
docker pull xrdj6c/oracle-11g-xedocker pull xrdj6c/oracle-11g-xe
docker run -d -p 49160:22 -p 1521:1521 -p 8080:8080 xrdj6c/oracle-11g-xe
Installing Oracle On A Mac
Install SQL Developer to connect the Oracle Database —
https://www.oracle.com/database/sqldeveloper/technologies/d
ownload/
Now we can create a new connection in SQL Developer with
given details and Test, It will show status Success -
workspace: oracle-11g-xe , username: system, connection type:
Basic, hostname: localhost, port: 1521, SID: xe
Data Types in SQL
Data type in SQL basically defines the kind of data that will go into a
particular column. All entries of one particular column will be of the
same data type. They are -
Character Data-types - CHAR. NCHAR. VARCHAR2, VARCHAR. CLOB.
NCLOB. LONG
NUMBER Datatype
DATE Data-type
Binary Data-types - BLOB, BFILE, RAW, LONG RAW
Creating a Table
In order to create a Table in Oracle, we need to execute the CREATE query in
the following syntax -
CREATE TABLE schema_name.table_name (
column_1 data_type column_constraint,
column_2 data_type column_constraint,
...
table_constraint
);
Creating a Table
An example query to create a table in a schema named City would be
as follows -
CREATE TABLE city..persons(
person_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
first_name VARCHAR2(50) NOT NULL,
last_name VARCHAR2(50) NOT NULL,
PRIMARY KEY(person_id) );
Altering a Table
To modify the structure of an existing table, you use the ALTER TABLE
statement. The following illustrates the syntax:
ALTER TABLE table_name action;
The ALTER TABLE statement allows you to add one or more columns,
modify column definitions, drop one or more columns, rename
columns and rename tables.
Altering a Table
In case you want to add more than one column, you use the following
syntax:
ALTER TABLE table_name ADD ( column_name_1 data_type constraint,
column_name_2 data_type constraint, ... );
To change the definition of a column in a table, you use the ALTER
TABLE MODIFY column syntax as follows:
ALTER TABLE table_name MODIFY column_name action;
Dropping Columns
The process of dropping a column from a big table can be time and
resource consuming. Therefore, we typically make the column no
longer visible for accessing.
ALTER TABLE table_name SET UNUSED COLUMN column_name;
We can drop the unused columns physically using the following
statement:
ALTER TABLE table_name DROP UNUSED COLUMNS;
Dropping Tables
To move a table to the recycle bin or remove it entirely from the
database, you use the DROP TABLE statement:
DROP TABLE schema_name.table_name [CASCADE CONSTRAINTS |
PURGE];
We specify CASCADE CONSTRAINTS clause to remove all referential
integrity constraints which refer to primary and unique keys in the
table. If we don’t use this clause, Oracle returns an error and stops
removing the table.
We specify PURGE clause if you want to drop the table and release the
space associated with it at once. The PURGE clause does not allow you
to roll back or recover the table that you dropped.
Truncating a Table
For a table with a small number of rows, the DELETE statement does a
good job. However, when you have a table with a large number of rows,
using the DELETE statement to remove all data is not efficient.
Oracle introduced the TRUNCATE TABLE statement that allows you to
delete all rows from a big table.
TRUNCATE TABLE schema_name.table_name [CASCADE] [[ PRESERVE
| PURGE] MATERIALIZED VIEW LOG ]] [[ DROP | REUSE]] STORAGE ]
Truncating a Table
By default, to remove all rows from a table, you specify the name of the
table that you want to truncate in the TRUNCATE TABLE clause:
TRUNCATE TABLE table_name;
Because we don’t specify the schema name explicitly, Oracle assumes
that we truncate the table from our own schema.
If a table has relationships with other tables via the foreign key
constraints, you need to use the CASCADE clause:
TRUNCATE TABLE table_name CASCADE;
Truncating a Table
The MATERIALIZED VIEW LOG clause allows you to specify whether a
materialized view log defined on the table is to be preserved or purged
when the table is truncated.
The STORAGE clause allows you to choose either drop or reuse storage
freed by the truncated rows and associated indexes if any. By default,
the storage is dropped.
Renaming a Table
To rename a table, you use the following Oracle RENAME table
statement as follows:
RENAME table_name TO new_name;
Oracle Constraints - Primary Key
A primary key is a column of a combination of columns in a table that
uniquely identifies a row in the table.
To create a primary key in a table, you use the PRIMARY KEY constraint.
Typically, you create a primary key for a table when you create that
table. In addition, you can add a primary key to a table after the fact by
using the ALTER TABLE statement.
Oracle Constraints - Primary Key
Creating a Primary Key with CREATE TABLE query -
CREATE TABLE vendors ( vendor_id NUMBER PRIMARY KEY,
vendor_name VARCHAR2(255) NOT NULL, address VARCHAR2(255) NOT
NULL );
Creating a Primary Key with ALTER query -
ALTER TABLE vendors ADD CONSTRAINT pk_vendors PRIMARY KEY
(vendor_id);
Oracle Constraints - Foreign Key
A FOREIGN KEY is a field (or collection of fields) in one table, that refers
to the PRIMARY KEY in another table.
ALTER TABLE child_table ADD CONSTRAINT fk_name FOREIGN KEY
(col1,col2) REFERENCES parent_table(col1,col2);
CREATE TABLE child_table ( ... CONSTRAINT fk_name FOREIGN
KEY(col1, col2,...) REFERENCES parent_table(col1,col2) ON DELETE [
CASCADE | SET NULL ] );
Oracle Constraints - Unique
A unique constraint is an integrity constraint that ensures the data
stored in a column, or a group of columns, is unique among the rows in
a table.
CREATE TABLE table_name ( ... column_name data_type UNIQUE ... );
ALTER TABLE table_name ADD CONSTRAINT unique_constraint_name
UNIQUE(column_name1, column_nam2);
Oracle Constraints - NOT NULL
In Oracle, NOT NULL constraint specifies that a column cannot contain
NULL values.
CREATE TABLE table_name ( ... column_name data_type NOT NULL ... );
ALTER TABLE table_name MODIFY ( column_name NOT NULL);
SELECT Query
To retrieve data from one or more columns of a table, you use the
SELECT statement with the following syntax:
SELECT column_1,column_2,...FROM table_name;
To make it handy, you can use the shorthand asterisk (*) to instruct
Oracle to return data from all columns of a table as follows:
SELECT * FROM table_name;
DUAL Table
The Oracle DUAL table which is a special table used for evaluating
expressions or calling functions.
The DUAL table has one column named DUMMY whose data type is
VARCHAR2() and contains one row with a value X.
By using the DUAL table, you can execute queries that contain
functions that do not involve any table like the UPPER() function as
follows or perform mathematical operations:
SELECT UPPER('This is a string') FROM dual;
SELECT 5 + 5 AS SUM1 FROM DUAL;
DISTINCT Clause
The DISTINCT clause is used in a SELECT statement to filter duplicate
rows in the result set. It ensures that rows returned are unique for the
column or columns specified in the SELECT clause.
SELECT DISTINCT column_1 FROM table;
ORDER BY Clause
To query rows in either ascending or descending order by a column,
you add the ORDER BY clause to the SELECT statement as follows:
SELECT column_1, column_2, column_3, ... FROM table_name ORDER
BY column_1 [ASC | DESC] [NULLS FIRST | NULLS LAST], column_1 [ASC |
DESC] [NULLS FIRST | NULLS LAST], …
For example,
SELECT name, address, credit_limit FROM customers ORDER BY name
ASC;
WHERE CLAUSE
The WHERE clause specifies a search condition for rows returned by the
SELECT statement. The following illustrates the syntax of the WHERE
clause:
SELECT select_list FROM table_name WHERE search_condition;
For example,
SELECT product_name, description, list_price, category_id FROM
products WHERE product_name = 'Kingston';
Alias or AS Keyword
When you query data from a table, Oracle uses the column names of
the table for displaying the column heading.
However, sometimes, the column names are quite vague for describing
the meaning of data.
To instruct Oracle to use a column alias, you simply list the column alias
next to the column name in the SELECT clause as shown below:
SELECT first_name AS forename, last_name AS surname FROM
employees;
AND Operator
The AND operator is a logical operator that combines Boolean
expressions and returns true if both expressions are true. If one of the
expressions is false, the AND operator returns false.
Typically, we use AND is used in the WHERE clause of the SELECT,
DELETE, and UPDATE statements to form a condition for matching
data
For example,
SELECT order_id, customer_id, status, order_date FROM orders WHERE
status = 'Pending' AND customer_id = 2 ORDER BY order_date;
OR Operator
The OR operator is a logical operator that combines Boolean
expressions and returns true if one of the expressions is true.
For example,
SELECT order_id, customer_id, status, salesman_id, order_date FROM
orders WHERE ( status = 'Canceled' OR status = 'Pending' ) AND
customer_id = 44 ORDER BY order_date;
BETWEEN Operator
The BETWEEN operator allows you to specify a range to test.
When you use the BETWEEN operator to form a search condition for
rows returned by a SELECT statement, only rows whose values are in
the specified range are returned.
For example -
SELECT product_name, standard_cost FROM products WHERE
standard_cost BETWEEN 500 AND 600 ORDER BY standard_cost;
IN Operator
The Oracle IN operator determines whether a value matches any values
in a list or a subquery.
For example,
SELECT order_id, customer_id, status, salesman_id FROM orders
WHERE salesman_id IN ( 54, 55, 56 ) ORDER BY order_id;
LIKE Operator
We use the Oracle LIKE operator to test whether values in a column
match a specified pattern.
For example, you may want to find contacts whose last names start
with 'St' or first names end with 'er'. In this case, you use the Oracle LIKE
operator.
For example,
SELECT first_name, last_name, phone FROM contacts WHERE
last_name LIKE 'St%' ORDER BY last_name;
GROUP BY Clause
The GROUP BY clause is used in a SELECT statement to group rows into a set
of summary rows by values of columns or expressions. The GROUP BY clause
returns one row per group.
The GROUP BY clause is often used with aggregate functions such as AVG(),
COUNT(), MAX(), MIN() and SUM(). In this case, the aggregate function
returns the summary information per group. For example, given groups of
products in several categories, the AVG() function returns the average price
of products in each category.
For example
SELECT category_id, AVG( price) FROM products GROUP BY category_id;;
HAVING Clause
The HAVING clause is an optional clause of the SELECT statement. It is
used to filter groups of rows returned by the GROUP BY clause.
This is why the HAVING clause is usually used with the GROUP BY
clause.
The following illustrates the syntax of the Oracle HAVING clause:
SELECT column_list FROM T GROUP BY c1 HAVING group_condition;
UNION Clause
The UNION operator is a set operator that combines result sets of two
or more SELECT statements into a single result set.
The following illustrates the syntax of the UNION operator that
combines the result sets of two queries:
SELECT column_list_1 FROM T1 UNION
SELECT column_list_1 FROM T2;
INTERSECT operator
The Oracle INTERSECT operator compares the result of two queries and
returns the distinct rows that are output by both queries.
The following statement shows the syntax of the INTERSECT operator:
SELECT column_list_1 FROM T1 INTERSECT
SELECT column_list_2 FROM T2;
MINUS Operator
The Oracle MINUS operator compares two queries and returns distinct
rows from the first query that are not output by the second query.
In other words, the MINUS operator subtracts one result set from
another.
The following illustrates the syntax of the Oracle MINUS operator:
SELECT column_list_1 FROM T1 MINUS
SELECT column_list_2 FROM T2;
ANY Operator
The Oracle ANY operator is used to compare a value to a list of values or
result set returned by a subquery.
The following illustrates the syntax of the ANY operator when it is used
with a list or subquery:
SELECT * FROM table_name WHERE c > ANY ( v1, v2, v3 );
ALL Operator
The Oracle ALL operator is used to compare a value to a list of values or
result set returned by a subquery.
The ALL operator must be preceded by an comparison operator such as
=, != >,>=, <, <= and followed by a list or subquery.
The list or subquery must be surrounded by the parentheses.
For example,
SELECT * FROM table_name WHERE c > ALL ( v1, v2, v3 );
INSERT Query
To insert a new row into a table, you use the Oracle INSERT statement
as follows:
INSERT INTO table_name (column_list) VALUES( value_list);
INSERT INTO SELECT statement
Sometimes, you want to select data from a table and insert it into
another table.
To do it, you use the Oracle INSERT INTO SELECT statement as follows:
INSERT INTO target_table (col1, col2, col3) SELECT col1, col2, col3 FROM
source_table WHERE condition;
UPDATE statement
To changes existing values in a table, you use the following Oracle
UPDATE statement:
UPDATE table_name SET column1 = value1, column2 = value2,
column3 = value3, ... WHERE condition;
For example,
UPDATE parts SET cost = 130 WHERE part_id = 1;
DELETE statement
To delete one or more rows from a table, you use the Oracle DELETE
statement as follows:
DELETE FROM table_name WHERE condition;
For example,
DELETE FROM sales WHERE order_id = 1 AND item_id = 1;
MERGE statement
The Oracle MERGE statement selects data from one or more source
tables and updates or inserts it into a target table. The syntax is as
follows -
JOINS
Oracle join is used to combine columns from two or more tables based
on values of the related columns.
The related columns are typically the primary key column(s) of the first
table and foreign key column(s) of the second table.
Oracle supports inner join, left join, right join, full outer join and cross
join.
INNER JOINS
The INNER JOIN keyword selects records that have matching values in
both tables.
Diagrammatically, you can understand them as the intersection of the
two result-sets.
INNER JOINS
Syntactically, it is written as follows -
SELECT * FROM T1 INNER JOIN T2 ON join_predicate;
For example,
SELECT * FROM orders INNER JOIN order_items ON
order_items.order_id = orders.order_id ORDER BY order_date DESC;
LEFT JOINS
The LEFT JOIN keyword returns all records from the left table (table1),
and the matching records from the right table (table2).
Diagrammatically, you can understand them as the intersection of the
two result-sets, plus all the remaining results of the left table.
LEFT JOINS
The following statement illustrates the syntax of the LEFT JOIN clause
when joining two tables T1 and T2:
SELECT column_list FROM T1 LEFT JOIN T2 ON join_predicate;
For example,
SELECT order_id, status, first_name, last_name FROM orders LEFT JOIN
employees ON employee_id = salesman_id ORDER BY order_date
DESC;
RIGHT JOINS
The RIGHT JOIN keyword returns the matching records from the left
table (table1), and all the records from the right table (table2).
Diagrammatically, you can understand them as the intersection of the
two result-sets, plus all the remaining results of the right table.
RIGHT JOINS
The following statement illustrates the syntax of the RIGHT JOIN clause
when joining two tables T1 and T2:
SELECT column_list FROM T1 RIGHT JOIN T2 ON join_predicate;
For example,
SELECT order_id, status, first_name, last_name FROM orders RIGHT
JOIN employees ON employee_id = salesman_id ORDER BY order_date
DESC;
FULL OUTER JOINS
The FULL OUTER JOIN keyword returns all records when there is a
match in left (table1) or right (table2) table records.
Diagrammatically, you can understand them as the intersection of the
two result-sets, plus all the remaining results of both the tables.
FULL OUTER JOINS
The following statement illustrates the syntax of the FULL OUTER JOIN
clause when joining two tables T1 and T2:
SELECT select_list FROM T1 FULL OUTER JOIN T2 ON join_condition;
For example,
SELECT order_id, status, first_name, last_name FROM orders FULL
OUTER JOIN employees ON employee_id = salesman_id ORDER BY
order_date DESC;
SELF JOINS
A self join is a regular join, but the table is joined with itself.
A self join is useful for comparing rows within a table or querying
hierarchical data.
The following illustrates how the table T is joined with itself:
SELECT column_list FROM T t1 INNER JOIN T t2 ON join_predicate;
For example, suppose there is a customers table and we would like to
identify customers from the same city -
SELECT A.CustomerName AS CustomerName1, B.CustomerName AS
CustomerName2, A.City FROM Customers A, Customers B WHERE
A.CustomerID <> B.CustomerID AND A.City = B.City ORDER BY A.City;
CROSS JOINS
A cross join is a type of join that returns the Cartesian product of rows
from the tables in the join.
In other words, it combines each row from the first table with each row
from the second table.
CROSS JOINS
The following illustrates the syntax of the CROSS JOIN clause:
SELECT column_list FROM T1 CROSS JOIN T2;
For example, for two tables - products and warehouses for which we
wanted a cartesian table -
SELECT product_id, warehouse_id FROM products CROSS JOIN
warehouses;
Subqueries
A subquery is a SELECT statement nested inside another statement
such as SELECT, INSERT, UPDATE, or DELETE.
Typically, you can use a subquery anywhere that you use an expression.
For example,
SELECT product_id, product_name, list_price FROM products WHERE
list_price = ( SELECT MAX( list_price ) FROM products );
Correlated Subqueries
A correlated subquery which is a subquery whose some clauses refer to
the column expressions in the outer query.
For example, here the subquery refers to the products table p as
defined in the outer query.
SELECT product_id, product_name, list_price FROM products p
WHERE list_price > ( SELECT AVG( list_price ) FROM products
WHERE category_id = p.category_id );

More Related Content

PPT
PPTX
SQL: Data Definition Language(DDL) command
PPTX
Database COMPLETE
PPT
Interactive SQL: SQL, Features of SQL, DDL & DML
PPTX
SQl data base management and design
DOC
Adbms
PPTX
SQL.pptx for the begineers and good know
SQL: Data Definition Language(DDL) command
Database COMPLETE
Interactive SQL: SQL, Features of SQL, DDL & DML
SQl data base management and design
Adbms
SQL.pptx for the begineers and good know

Similar to Introduction to Oracle Database.pptx (20)

PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
DOCX
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
PPTX
SQL Query
DOC
Module 3
PPT
My sql with querys
PPT
MYSQL
PPTX
Oracle: Commands
PPTX
Oracle: DDL
PDF
Database development coding standards
PPTX
PPTX
Introduction to database and sql fir beginers
PPTX
Introduction to sql new
DOCX
PPT
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
PDF
Mysql cheatsheet
ODP
PPTX
Oracle 10g
PDF
Sql tutorial
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SQL Query
Module 3
My sql with querys
MYSQL
Oracle: Commands
Oracle: DDL
Database development coding standards
Introduction to database and sql fir beginers
Introduction to sql new
1_SQL_11_13_Notes_on_how_to_gain_knowledge.ppt
Mysql cheatsheet
Oracle 10g
Sql tutorial
Ad

Recently uploaded (20)

PPTX
Cybersecurity: Protecting the Digital World
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
Website Design Services for Small Businesses.pdf
PPTX
chapter 5 systemdesign2008.pptx for cimputer science students
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
STL Containers in C++ : Sequence Container : Vector
PDF
iTop VPN Crack Latest Version Full Key 2025
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
Patient Appointment Booking in Odoo with online payment
Cybersecurity: Protecting the Digital World
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Trending Python Topics for Data Visualization in 2025
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
wealthsignaloriginal-com-DS-text-... (1).pdf
Designing Intelligence for the Shop Floor.pdf
Complete Guide to Website Development in Malaysia for SMEs
DNT Brochure 2025 – ISV Solutions @ D365
Monitoring Stack: Grafana, Loki & Promtail
Why Generative AI is the Future of Content, Code & Creativity?
Tech Workshop Escape Room Tech Workshop
Website Design Services for Small Businesses.pdf
chapter 5 systemdesign2008.pptx for cimputer science students
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
STL Containers in C++ : Sequence Container : Vector
iTop VPN Crack Latest Version Full Key 2025
How to Use SharePoint as an ISO-Compliant Document Management System
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Patient Appointment Booking in Odoo with online payment
Ad

Introduction to Oracle Database.pptx

  • 1. Introduction to Oracle DB By Siddhant Bhardwaj
  • 2. Important Terms to Remember In the simplest terms, a database is a collection of information, that is being stored in a systematic manner. This information is stored in a database is known as data Data is a collection of facts, such as numbers, words, measurements, observations or just descriptions of things. Data can be Qualitative or Quantitative.
  • 3. Important Terms to Remember Qualitative Data is Descriptive Data, i.e., it describes something in words. Quantitative Data is Numerical Data, i.e. it describes something in terms of Numbers.
  • 4. What Is A Table ? A table is a database object which is comprised of rows and columns in SQL. Simplifying it more we can say that it’s a collection of related data held in a table format.
  • 5. What Are Fields In A Table Fields are basically columns in a table with specific information about the data. They are attributes of a real-world object that we are interested in, which we will be storing as a column in a table.
  • 6. What Are Records In A Table A record is basically an individual entry that exists in a table. Records give the complete information of a single entry or entity. Thus, records equate to an individual row in a table.
  • 7. What Is A Schema In A Database A Schema is a collection of various logical data structures. The database user owns the schema and it has the same name as that of the user. The main aim of Schema in SQL is to aid in security management. It helps in defining which users have the authority to access which database objects.
  • 8. Installing Oracle in Windows Google Oracle Database Downloads Click on the link to Oracle Database Express
  • 9. Installing Oracle in Windows Download the latest version of Oracle Database Express Edition for Windows x64 machine.
  • 10. Installing Oracle in Windows Once it has been downloaded, extract the files from the downloaded folder. Next click the setup.exe file, which will initiate the installation folder. Accept the terms and conditions Keep clicking on the Next button. Set up your password and confirm it.
  • 11. Installing Oracle in Windows Next, navigate to the C Drive and oracleexe folder inside it. Go to app -> oracle -> product -> folder bearing version number -> server -> Get Started shortcut file. Here, edit the properties by right-clicking on the file and change the URL to 8080.
  • 13. Installing Oracle in Windows Now launch localhost:8080 on your browser and click on Application Express. Enter your user login credentials to log in (username - sys and your password)
  • 14. Installing Oracle in Windows Create a session in application express and then log into it. If you search for sql command line in start menu, you will be able to access your database from CLI also.
  • 15. Installing Oracle in Windows Download the latest Windows 64 bit version of Oracle Developer on your device from the Oracle Website. You will have to create an account with Oracle in order to download it Extract the files from downloaded zipped file and copy the extracted folder to the C Drive. Enter the folder and now create a shortcut for the SQL Developer in order to run and use the Oracle Developer. You can use your Application Express username and password to log into the developer.
  • 16. Installing Oracle On A Mac Install and run Docker Desktop for Mac from here - https://docs.docker.com/desktop/install/mac-install/ Install Docker Toolbox from Toolbox Releases and download the latest .pkg file - https://github.com/docker-archive/toolbox/releases Open terminal and run following command to install the oracle-11g-xe - docker pull xrdj6c/oracle-11g-xedocker pull xrdj6c/oracle-11g-xe docker run -d -p 49160:22 -p 1521:1521 -p 8080:8080 xrdj6c/oracle-11g-xe
  • 17. Installing Oracle On A Mac Install SQL Developer to connect the Oracle Database — https://www.oracle.com/database/sqldeveloper/technologies/d ownload/ Now we can create a new connection in SQL Developer with given details and Test, It will show status Success - workspace: oracle-11g-xe , username: system, connection type: Basic, hostname: localhost, port: 1521, SID: xe
  • 18. Data Types in SQL Data type in SQL basically defines the kind of data that will go into a particular column. All entries of one particular column will be of the same data type. They are - Character Data-types - CHAR. NCHAR. VARCHAR2, VARCHAR. CLOB. NCLOB. LONG NUMBER Datatype DATE Data-type Binary Data-types - BLOB, BFILE, RAW, LONG RAW
  • 19. Creating a Table In order to create a Table in Oracle, we need to execute the CREATE query in the following syntax - CREATE TABLE schema_name.table_name ( column_1 data_type column_constraint, column_2 data_type column_constraint, ... table_constraint );
  • 20. Creating a Table An example query to create a table in a schema named City would be as follows - CREATE TABLE city..persons( person_id NUMBER GENERATED BY DEFAULT AS IDENTITY, first_name VARCHAR2(50) NOT NULL, last_name VARCHAR2(50) NOT NULL, PRIMARY KEY(person_id) );
  • 21. Altering a Table To modify the structure of an existing table, you use the ALTER TABLE statement. The following illustrates the syntax: ALTER TABLE table_name action; The ALTER TABLE statement allows you to add one or more columns, modify column definitions, drop one or more columns, rename columns and rename tables.
  • 22. Altering a Table In case you want to add more than one column, you use the following syntax: ALTER TABLE table_name ADD ( column_name_1 data_type constraint, column_name_2 data_type constraint, ... ); To change the definition of a column in a table, you use the ALTER TABLE MODIFY column syntax as follows: ALTER TABLE table_name MODIFY column_name action;
  • 23. Dropping Columns The process of dropping a column from a big table can be time and resource consuming. Therefore, we typically make the column no longer visible for accessing. ALTER TABLE table_name SET UNUSED COLUMN column_name; We can drop the unused columns physically using the following statement: ALTER TABLE table_name DROP UNUSED COLUMNS;
  • 24. Dropping Tables To move a table to the recycle bin or remove it entirely from the database, you use the DROP TABLE statement: DROP TABLE schema_name.table_name [CASCADE CONSTRAINTS | PURGE]; We specify CASCADE CONSTRAINTS clause to remove all referential integrity constraints which refer to primary and unique keys in the table. If we don’t use this clause, Oracle returns an error and stops removing the table. We specify PURGE clause if you want to drop the table and release the space associated with it at once. The PURGE clause does not allow you to roll back or recover the table that you dropped.
  • 25. Truncating a Table For a table with a small number of rows, the DELETE statement does a good job. However, when you have a table with a large number of rows, using the DELETE statement to remove all data is not efficient. Oracle introduced the TRUNCATE TABLE statement that allows you to delete all rows from a big table. TRUNCATE TABLE schema_name.table_name [CASCADE] [[ PRESERVE | PURGE] MATERIALIZED VIEW LOG ]] [[ DROP | REUSE]] STORAGE ]
  • 26. Truncating a Table By default, to remove all rows from a table, you specify the name of the table that you want to truncate in the TRUNCATE TABLE clause: TRUNCATE TABLE table_name; Because we don’t specify the schema name explicitly, Oracle assumes that we truncate the table from our own schema. If a table has relationships with other tables via the foreign key constraints, you need to use the CASCADE clause: TRUNCATE TABLE table_name CASCADE;
  • 27. Truncating a Table The MATERIALIZED VIEW LOG clause allows you to specify whether a materialized view log defined on the table is to be preserved or purged when the table is truncated. The STORAGE clause allows you to choose either drop or reuse storage freed by the truncated rows and associated indexes if any. By default, the storage is dropped.
  • 28. Renaming a Table To rename a table, you use the following Oracle RENAME table statement as follows: RENAME table_name TO new_name;
  • 29. Oracle Constraints - Primary Key A primary key is a column of a combination of columns in a table that uniquely identifies a row in the table. To create a primary key in a table, you use the PRIMARY KEY constraint. Typically, you create a primary key for a table when you create that table. In addition, you can add a primary key to a table after the fact by using the ALTER TABLE statement.
  • 30. Oracle Constraints - Primary Key Creating a Primary Key with CREATE TABLE query - CREATE TABLE vendors ( vendor_id NUMBER PRIMARY KEY, vendor_name VARCHAR2(255) NOT NULL, address VARCHAR2(255) NOT NULL ); Creating a Primary Key with ALTER query - ALTER TABLE vendors ADD CONSTRAINT pk_vendors PRIMARY KEY (vendor_id);
  • 31. Oracle Constraints - Foreign Key A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table. ALTER TABLE child_table ADD CONSTRAINT fk_name FOREIGN KEY (col1,col2) REFERENCES parent_table(col1,col2); CREATE TABLE child_table ( ... CONSTRAINT fk_name FOREIGN KEY(col1, col2,...) REFERENCES parent_table(col1,col2) ON DELETE [ CASCADE | SET NULL ] );
  • 32. Oracle Constraints - Unique A unique constraint is an integrity constraint that ensures the data stored in a column, or a group of columns, is unique among the rows in a table. CREATE TABLE table_name ( ... column_name data_type UNIQUE ... ); ALTER TABLE table_name ADD CONSTRAINT unique_constraint_name UNIQUE(column_name1, column_nam2);
  • 33. Oracle Constraints - NOT NULL In Oracle, NOT NULL constraint specifies that a column cannot contain NULL values. CREATE TABLE table_name ( ... column_name data_type NOT NULL ... ); ALTER TABLE table_name MODIFY ( column_name NOT NULL);
  • 34. SELECT Query To retrieve data from one or more columns of a table, you use the SELECT statement with the following syntax: SELECT column_1,column_2,...FROM table_name; To make it handy, you can use the shorthand asterisk (*) to instruct Oracle to return data from all columns of a table as follows: SELECT * FROM table_name;
  • 35. DUAL Table The Oracle DUAL table which is a special table used for evaluating expressions or calling functions. The DUAL table has one column named DUMMY whose data type is VARCHAR2() and contains one row with a value X. By using the DUAL table, you can execute queries that contain functions that do not involve any table like the UPPER() function as follows or perform mathematical operations: SELECT UPPER('This is a string') FROM dual; SELECT 5 + 5 AS SUM1 FROM DUAL;
  • 36. DISTINCT Clause The DISTINCT clause is used in a SELECT statement to filter duplicate rows in the result set. It ensures that rows returned are unique for the column or columns specified in the SELECT clause. SELECT DISTINCT column_1 FROM table;
  • 37. ORDER BY Clause To query rows in either ascending or descending order by a column, you add the ORDER BY clause to the SELECT statement as follows: SELECT column_1, column_2, column_3, ... FROM table_name ORDER BY column_1 [ASC | DESC] [NULLS FIRST | NULLS LAST], column_1 [ASC | DESC] [NULLS FIRST | NULLS LAST], … For example, SELECT name, address, credit_limit FROM customers ORDER BY name ASC;
  • 38. WHERE CLAUSE The WHERE clause specifies a search condition for rows returned by the SELECT statement. The following illustrates the syntax of the WHERE clause: SELECT select_list FROM table_name WHERE search_condition; For example, SELECT product_name, description, list_price, category_id FROM products WHERE product_name = 'Kingston';
  • 39. Alias or AS Keyword When you query data from a table, Oracle uses the column names of the table for displaying the column heading. However, sometimes, the column names are quite vague for describing the meaning of data. To instruct Oracle to use a column alias, you simply list the column alias next to the column name in the SELECT clause as shown below: SELECT first_name AS forename, last_name AS surname FROM employees;
  • 40. AND Operator The AND operator is a logical operator that combines Boolean expressions and returns true if both expressions are true. If one of the expressions is false, the AND operator returns false. Typically, we use AND is used in the WHERE clause of the SELECT, DELETE, and UPDATE statements to form a condition for matching data For example, SELECT order_id, customer_id, status, order_date FROM orders WHERE status = 'Pending' AND customer_id = 2 ORDER BY order_date;
  • 41. OR Operator The OR operator is a logical operator that combines Boolean expressions and returns true if one of the expressions is true. For example, SELECT order_id, customer_id, status, salesman_id, order_date FROM orders WHERE ( status = 'Canceled' OR status = 'Pending' ) AND customer_id = 44 ORDER BY order_date;
  • 42. BETWEEN Operator The BETWEEN operator allows you to specify a range to test. When you use the BETWEEN operator to form a search condition for rows returned by a SELECT statement, only rows whose values are in the specified range are returned. For example - SELECT product_name, standard_cost FROM products WHERE standard_cost BETWEEN 500 AND 600 ORDER BY standard_cost;
  • 43. IN Operator The Oracle IN operator determines whether a value matches any values in a list or a subquery. For example, SELECT order_id, customer_id, status, salesman_id FROM orders WHERE salesman_id IN ( 54, 55, 56 ) ORDER BY order_id;
  • 44. LIKE Operator We use the Oracle LIKE operator to test whether values in a column match a specified pattern. For example, you may want to find contacts whose last names start with 'St' or first names end with 'er'. In this case, you use the Oracle LIKE operator. For example, SELECT first_name, last_name, phone FROM contacts WHERE last_name LIKE 'St%' ORDER BY last_name;
  • 45. GROUP BY Clause The GROUP BY clause is used in a SELECT statement to group rows into a set of summary rows by values of columns or expressions. The GROUP BY clause returns one row per group. The GROUP BY clause is often used with aggregate functions such as AVG(), COUNT(), MAX(), MIN() and SUM(). In this case, the aggregate function returns the summary information per group. For example, given groups of products in several categories, the AVG() function returns the average price of products in each category. For example SELECT category_id, AVG( price) FROM products GROUP BY category_id;;
  • 46. HAVING Clause The HAVING clause is an optional clause of the SELECT statement. It is used to filter groups of rows returned by the GROUP BY clause. This is why the HAVING clause is usually used with the GROUP BY clause. The following illustrates the syntax of the Oracle HAVING clause: SELECT column_list FROM T GROUP BY c1 HAVING group_condition;
  • 47. UNION Clause The UNION operator is a set operator that combines result sets of two or more SELECT statements into a single result set. The following illustrates the syntax of the UNION operator that combines the result sets of two queries: SELECT column_list_1 FROM T1 UNION SELECT column_list_1 FROM T2;
  • 48. INTERSECT operator The Oracle INTERSECT operator compares the result of two queries and returns the distinct rows that are output by both queries. The following statement shows the syntax of the INTERSECT operator: SELECT column_list_1 FROM T1 INTERSECT SELECT column_list_2 FROM T2;
  • 49. MINUS Operator The Oracle MINUS operator compares two queries and returns distinct rows from the first query that are not output by the second query. In other words, the MINUS operator subtracts one result set from another. The following illustrates the syntax of the Oracle MINUS operator: SELECT column_list_1 FROM T1 MINUS SELECT column_list_2 FROM T2;
  • 50. ANY Operator The Oracle ANY operator is used to compare a value to a list of values or result set returned by a subquery. The following illustrates the syntax of the ANY operator when it is used with a list or subquery: SELECT * FROM table_name WHERE c > ANY ( v1, v2, v3 );
  • 51. ALL Operator The Oracle ALL operator is used to compare a value to a list of values or result set returned by a subquery. The ALL operator must be preceded by an comparison operator such as =, != >,>=, <, <= and followed by a list or subquery. The list or subquery must be surrounded by the parentheses. For example, SELECT * FROM table_name WHERE c > ALL ( v1, v2, v3 );
  • 52. INSERT Query To insert a new row into a table, you use the Oracle INSERT statement as follows: INSERT INTO table_name (column_list) VALUES( value_list);
  • 53. INSERT INTO SELECT statement Sometimes, you want to select data from a table and insert it into another table. To do it, you use the Oracle INSERT INTO SELECT statement as follows: INSERT INTO target_table (col1, col2, col3) SELECT col1, col2, col3 FROM source_table WHERE condition;
  • 54. UPDATE statement To changes existing values in a table, you use the following Oracle UPDATE statement: UPDATE table_name SET column1 = value1, column2 = value2, column3 = value3, ... WHERE condition; For example, UPDATE parts SET cost = 130 WHERE part_id = 1;
  • 55. DELETE statement To delete one or more rows from a table, you use the Oracle DELETE statement as follows: DELETE FROM table_name WHERE condition; For example, DELETE FROM sales WHERE order_id = 1 AND item_id = 1;
  • 56. MERGE statement The Oracle MERGE statement selects data from one or more source tables and updates or inserts it into a target table. The syntax is as follows -
  • 57. JOINS Oracle join is used to combine columns from two or more tables based on values of the related columns. The related columns are typically the primary key column(s) of the first table and foreign key column(s) of the second table. Oracle supports inner join, left join, right join, full outer join and cross join.
  • 58. INNER JOINS The INNER JOIN keyword selects records that have matching values in both tables. Diagrammatically, you can understand them as the intersection of the two result-sets.
  • 59. INNER JOINS Syntactically, it is written as follows - SELECT * FROM T1 INNER JOIN T2 ON join_predicate; For example, SELECT * FROM orders INNER JOIN order_items ON order_items.order_id = orders.order_id ORDER BY order_date DESC;
  • 60. LEFT JOINS The LEFT JOIN keyword returns all records from the left table (table1), and the matching records from the right table (table2). Diagrammatically, you can understand them as the intersection of the two result-sets, plus all the remaining results of the left table.
  • 61. LEFT JOINS The following statement illustrates the syntax of the LEFT JOIN clause when joining two tables T1 and T2: SELECT column_list FROM T1 LEFT JOIN T2 ON join_predicate; For example, SELECT order_id, status, first_name, last_name FROM orders LEFT JOIN employees ON employee_id = salesman_id ORDER BY order_date DESC;
  • 62. RIGHT JOINS The RIGHT JOIN keyword returns the matching records from the left table (table1), and all the records from the right table (table2). Diagrammatically, you can understand them as the intersection of the two result-sets, plus all the remaining results of the right table.
  • 63. RIGHT JOINS The following statement illustrates the syntax of the RIGHT JOIN clause when joining two tables T1 and T2: SELECT column_list FROM T1 RIGHT JOIN T2 ON join_predicate; For example, SELECT order_id, status, first_name, last_name FROM orders RIGHT JOIN employees ON employee_id = salesman_id ORDER BY order_date DESC;
  • 64. FULL OUTER JOINS The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records. Diagrammatically, you can understand them as the intersection of the two result-sets, plus all the remaining results of both the tables.
  • 65. FULL OUTER JOINS The following statement illustrates the syntax of the FULL OUTER JOIN clause when joining two tables T1 and T2: SELECT select_list FROM T1 FULL OUTER JOIN T2 ON join_condition; For example, SELECT order_id, status, first_name, last_name FROM orders FULL OUTER JOIN employees ON employee_id = salesman_id ORDER BY order_date DESC;
  • 66. SELF JOINS A self join is a regular join, but the table is joined with itself. A self join is useful for comparing rows within a table or querying hierarchical data. The following illustrates how the table T is joined with itself: SELECT column_list FROM T t1 INNER JOIN T t2 ON join_predicate; For example, suppose there is a customers table and we would like to identify customers from the same city - SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City FROM Customers A, Customers B WHERE A.CustomerID <> B.CustomerID AND A.City = B.City ORDER BY A.City;
  • 67. CROSS JOINS A cross join is a type of join that returns the Cartesian product of rows from the tables in the join. In other words, it combines each row from the first table with each row from the second table.
  • 68. CROSS JOINS The following illustrates the syntax of the CROSS JOIN clause: SELECT column_list FROM T1 CROSS JOIN T2; For example, for two tables - products and warehouses for which we wanted a cartesian table - SELECT product_id, warehouse_id FROM products CROSS JOIN warehouses;
  • 69. Subqueries A subquery is a SELECT statement nested inside another statement such as SELECT, INSERT, UPDATE, or DELETE. Typically, you can use a subquery anywhere that you use an expression. For example, SELECT product_id, product_name, list_price FROM products WHERE list_price = ( SELECT MAX( list_price ) FROM products );
  • 70. Correlated Subqueries A correlated subquery which is a subquery whose some clauses refer to the column expressions in the outer query. For example, here the subquery refers to the products table p as defined in the outer query. SELECT product_id, product_name, list_price FROM products p WHERE list_price > ( SELECT AVG( list_price ) FROM products WHERE category_id = p.category_id );