SlideShare a Scribd company logo
1 of 40
Download to read offline
Oracle SQL Basics
Presented By:
Alphalogic Inc.
www.alphalogicinc.com
Agenda
01
02
03
Software Installation
Database Concepts
Database Fundamentals
SOFTWARE
INSTALLATION
Installation Guide
Install Oracle Database:
Dowanload oracle database from
Oracle.com and install it.
Link:
http://www.oracle.com/technetwo
rk/database/enterprise-edition/
downloads/index.html
Installation Guide
Install Java SDK:
Download latest Java SDK from
Oracle.com and install it.Set Environment
Path for SDK.
Link:
http://www.oracle.com/technetw
ork/java/javase/downloads/inde
x.html
Installation Guide
Install SQL Developer:
Download SQL Developer from
Oracle.com and install it. SQL Developer
is tool to execute and create SQL
Queries.
Link:
http://www.oracle.com/technetwo
rk/developer-tools/sql-develope
r/downloads/index.html
DATABASE CONCEPTS
“
“
What is Database?
A database is a collection of information that
is well oraganised so that it can be easily
accessed, managed and updated. It is a
repository which stores the tables.
What is Relational
Database (RDBMS)?
RDBMS stores the data into collection of
tables which might be realted by common
fields(columns).
What is a Table?
●
A table is a collection of related data held
in a structured format within a database
●
It consists of Fields(Columns) and
Records(Rows)
●
Every Column has a datatype- Table
follows rules like if a column of number
datatype can only hold number values so
the data is in structured format
What is
Transaction?
●
A transaction comprises of a Unit of work
performed within a system against a
database and is performed in a reliable
way independent of other transactions.
●
A transaction is reliable, means if any step
during a transaction gets failed then
whole transaction would get failed
Active
Partially
CommitedFailed
CommitedAborted
END
Begin
ACID Properties
ACID refers to the basic properties of a
database transaction. All oracle datbase
comply with ACID properties.
● Atomicity: The 'All' or 'Nothing'
property.The entire seq of actions must be
completed or aborted.
● Consistency: The transaction takes the
resource from one steady state to another
steady state.
● Isolation: A transaction's effect is not
visible to other transaction until the
transaction is commited. A transaction can
not interfere with another transaction
● Durability: Chnages made by the
commited transaction are permanent and
must survive the system failure.
DATABASE
FUNDAMENTALS
“ “
Enter The Database
How do we interact with a Database?
● SQL- Structured Query Langauge is a
computer language used for storing,
manipulating data stored in a relational
database
● It supports all relational operator
● Can be embedded in any procedural
language Used for insert and create data
● Very easy as the English language
● Using CAT data dictionary SELECT *
FROM CAT;
● CAT - Catalouge of all the tables owned by
the users
Let's See what tables do I own?
Let's Limit The Data
● SELECT * FROM sales WHERE total_amount > 1000;
● SELECT * FROM sales WHERE total_amount != 44;
● SELECT * FROM sales WHERE total_amount^44;
● SELECT * FROM sales WHERE quantity <= 10;
Use of Where clause for filtering numeric value
● SELECT * FROM sales WHERE sales_date = ’09-feb-2015’;
● SELECT * FROM product WHERE color = ‘RED’;
Use of Where clause for filtering text value
● SELECT * FROM sales WHERE total_amount > sales_amount;
Use of Where clause for comparing column values
01
02
03
Logical Operators
● SELECT * FROM sales WHERE total_amount NOT BETWEEN 1 and 100;
● SELECT * FROM sales WHERE total_amount BETWEEN 1 and 100;
Use of BETWEEN and NOT BETWEEN
● SELECT * FROM sales WHERE quantity IN (20,2,10);
Use of IN
● SELECT * FROM product WHERE product_name LIKE 'Mob%';
● SELECT * FROM product WHERE product_name LIKE '%Mob';
● SELECT * FROM product WHERE product_name LIKE 'Mob_Device';
Use of LIKE
01
02
03
Logical Operators
● SELECT * FROM sales WHERE total_amount > ALL (50,100,200);
Use of ALL
● SELECT * FROM sales WHERE total_amount > ANY (50,100,200);
Use of ANY
04
05
● SELECT * FROM product WHERE color IS NULL;
Use of NULL
● SELECT * FROM sales WHERE total_amount > 100 AND quantiy < 20;
Use of AND
06
07
Arithmetic Operator
1) Addition ( + ) : SELECT 100/ 20 FROM DUAL; --5
2) Substraction ( - ) : SELECT 100+20 FROM DUAL; --120
3) Multiplication ( * ) : SELECT 100-20 FROM DUAL; --80
4) Division ( / ) : SELECT 100*20 FROM DUAL; --2000
5) Modulus ( % ) : SELECT 10%100 FROM DUAL; --10
Let's Sort the Data
● SELECT sales_date, product_id, order_id, sales_amount, tax_amount FROM
sales ORDER BY tax_amount;
● SELECT sales_date, product_id, order_id, sales_amount, tax_amount FROM
sales ORDER BY sales_amount, tax_amount;
● SELECT order_id, sales_date, product_id, sales_amount, tax_amount FROM
sales ORDER BY order_id DESC;
Order By Clause
NULL values are treated as very large value by Oracle. So NULL data will sort to
the bottom of the sort is in ascending order and to the top of the sort is in
descending order.
How NULL values are treated while sorting the Data?
Set Operators
●
Set operators combines the result of two component
queries into a single unit. Queries containing the set
operators are called compound queries
●
The data type of columns should be same to use the set
operators
●
Types of Set Operators: UNION, UNION ALL,
INTERSECT, and MINUS
Set Operators
● SELECT order_id FROM sales UNION ALL SELECT order_id FROM
sales_history;
UNION ALL
● SELECT order_id FROM sales UNION SELECT order_id FROM
sales_history;
UNION
01
02
● SELECT order_id FROM sales INTERSECT SELECT order_id FROM
sales_history;
INTERSECT
● SELECT order_id FROM sales MINUS SELECT order_id FROM
sales_history;
MINUS
03
04
Let's group the data
● Aggregate Funcitons returns a single result row based on the group of rows.
● Some of the functions are: MIN(), MAX(), COUNT(), SUM(), AVG()
Aggregate/Summary Functions
● SELECT sales_date, SUM(total_amount) FROM sales GROUP BY
sales_date;
SUM Function
01
02
Let's group the data
● Where clause is used to filter the detailed result data whereas Having clause
is used to filter the aggregated result.
Difference Between Where and Having?
05
● SELECT sales_date, order_id, MAX(total_amount) FROM sales GROUP BY
sales_date, order_id;
MAX Funciton
● SELECT sales_date, MIN(total_amount) FROM sales GROUP BY
sales_date HAVING MIN(total_amount)< 100;
MIN Function with Having Clause
03
04
JOINS
Joins are used to join one or more table in database using a
common column in tables.
To get data from two or more tables in single SQL statement
To avoid the unwanted duplication of data, we split the single
table into multiple table and join them on the basis of
common columns
Why JOINS?
Interesting
Things
The CASE Statements evaluated a single expression and compares it against several
potential values, or evaluates multiple boolean expression and choose the first one that
is true.
CASE Statements:
We can provide different titles to the column name. Spaces are not allowed in an alias
name.
If required, then use double quotes : SELECT SUM(AMOUNT) "TOTAL AMOUNT"
FROM SALES;
Alias Name:
A pseudo column is an Oracle assigned value used in the same context as column
value but not stored on disk.
SYSDATE: Returns Current Date
USER: Returns the current timestamp
ROWNUM: It indicates a number indicating the order of the row selected from the table
ROWID: Returns the RowID(Binary Address) of a row in a database table
Pseudo Columns in Oracle:
Data Definition Language DDL
01 Create Table statement
CREATE TABLE movies ( Movie_number number, Movie_name varchar2(100),
Movie_type varchar2(40), Movie_release_date date );
02 Add column to table
ALTER TABLE movies ADD (movie_language varchar2(30));
03 Modify Column attributes
ALTER TABLE movies MODIFY (movie_type varchar2(50));
04 Drop Table
DROP TABLE movies;
Data Definition Language DDL
05 Insert Values into a table
INSERT INTO movies VALUES ( 01, 'TERMINATOR', 'ACTION', '12-JAN-2015' );
COMMIT;
06 Update a record
UPDATE movies set movie_release_date = '14-jan-2015' WHERE movie_number = 101;
COMMIT;
07 Delete a record
DELETE from movies WHERE movie_name = 'RUSH HOUR';
COMMIT;
08 Truncate Statement
TRUNCATE TABLE SALES;
Data Definition Language DDL
Difference between DELETE and TRUNCATE?
ROLLBACK after DELETE can work, but not after TRUNCATE.
TRUNCATE auto commits.
01
02
DELETE generates a small amount of REDO space and a large amount
of UNDO space but TRUNCATE generates neither of these two.
03
Let's Put Some Restrictions
Constraints apply the specific rule to data, ensuring the data confirms the
requirement defined.
Example: NOT NULL, UNIQUE, Primary Key, Check, Foreign Key
Why constraints?
Check constraint validates that value in a given column meets specific criteria.
CREATE TABLE movies (Movie_number number, Movie_name varchar2(100),
Movie_type varchar2(40) CHECK (movie_type IN ('ACTION', 'COMEDY')),
Movie_release_date date);
CHECK:
Let's Put Some Restrictions
A foreign Key constraint is used to enforce a relationship between two tables
CREATE TABLE movies (Movie_number number, Movie_name varchar2(100),
Movie_type varchar2(40), Movie_release_date date, Movie_director_number
number REFERENCES director(director_number) );
Foreign Key:
VIEWS
A view is simply the representation of a SQL statement that is stored
in memory so that it can be easily reused.
●
A view gives a look of a table as defined by the select statement
in the view definition
●
A view does not store data separately
●
Only the definition(SQL statement) of the view is stored
●
The data is retrieved from the underlying table based on the
view definition
●
Advantages:
●
Security - restrict the access of complete data to all
●
Abstraction - Hiding complex logic and just displaying the
required output
What is a VIEW?
VIEWS
CREATE VIEW SALES_MOBILE AS SELECT S.SALES_DATE, S.ORDER_ID,
S.QUANTITY, S.UNIT_PRICE, S.TOTAL_AMOUNT, P.PRODUCT_NAME,
P.PRODUCT_CATEGORY FROM SALES S, PRODUCT P WHERE
S.PRODUCT_ID = P.PRODUCT_ID AND PRODUCT_CATEGORY = 'Mobile';
Create a View
CREATE OR REPLACE VIEW SALES_MOBILE AS SELECT S.SALES_DATE,
S.ORDER_ID, S.QUANTITY, S.UNIT_PRICE, S.TOTAL_AMOUNT,
P.PRODUCT_NAME, P.PRODUCT_CATEGORY, S.PRODUCT_ID FROM
SALES S, PRODUCT P WHERE S.PRODUCT_ID = P.PRODUCT_ID AND
PRODUCT_CATEGORY = 'Mobile';
Modify View
DROP view SALES_MOBILE;
Drop a View
Other Database Objects
● Synonym is an alternative name for a table, view, sequence, procedure,
stored function
● Syntax: CREATE SYNONYM inventory_data FROM SALES;
Synonyms
● A Sequence is an object in Oracle that is used to generate a number
series(sequence).
● This can be useful when you need to create a Unique number to act as a
primary key.
● Syntax: CREATE SEQUENCE VA_RECORD_ID MIN VALUE 1, MAX VALUE
999999, START_WITH , INCEREMENT BY 1, CACHE 10;
● NEXTVAL is used to get next value of sequence and CURRVAL is used to get
the current value.
Sequences
Giving Permissions To Other Users
● GRANT command can be used to grant schema object privileges to the role
or to the user
● WITH GRANT OPTION enables the user to pass on the privilege to other user
or role.
● Syntax: GRANT SELECT ON SALES TO SCOTT WITH GRANT OPTION;
GRANT
● REVOKE command can be used to take back the granted privileges to the
user or role
● Syntax: REVOKE ALL ON SALES FROM SCOTT;
REVOKE
Sub Queries
● A sub query is a query within a query which can return one or more rows. A
subquery executes inner query before the main query
Sub Suery
● Pair wise Comparision: Values compared in pair
●
Syntax: SELECT sales_date, order_id, customer_id FROM SALES
WHERE (product_id, unit_price) IN (SELECT product_id, unit_price FROM
SALESPERSON where sales_date='01-Jan-2009');
● Non Pairwise Comparision: Values are compared individually
Multiple Column Subqueries
Sub Queries
To hold the result of a SQL statement using a WITH clause and use it in multiple
SQL Statement.
●
Syntax: WITH st as (SELECT * FROM SALES_TOTAL) SELECT * FROM
SALES s, st WHERE s.sales_date=st.sales_date;
WITH Clause
Scaler sub queries will allow treating the output of a sub query as a column or
even an expression within a select statement.
●
It must return only one row and one column.
●
Syntax: SELECT s.sales_date, s.id, (SELECT SUM(total_sakes) FROM
SALES) as sales_total from SALES s;
Scaler Subquery
Sub Queries
Correlated sub query is a subquery that uses the values from the outer query and
is evaluated once for each row processed by the outer query.
●
Syntax: SELECT * FROM SALES x where total_amt>(SELECT
AVG(sales_amt) FROM SALES y WHERE y.c_id=x.c_id);
Corelated Subquery
Index
An index is a performance tuning method of allowing faster retrieval of records
Properties:
●
Indexes enable faster data acess
●
Index stores column values and their location
●
The index can be created on multiple columns
Index
DROP INDEX <index_name>;
DROP Index:
Index
A unique Index is an Index no duplicate values are allowed
●
Unique Index will not accept duplicate values
●
It can have null values until and unless restricted
●
Syntax: CREATE UNIQUE INDEX cust_idx ON CUSTOMER(cust_id);
Unique Index
ALTER INDEX <index_old_name> RENAME TO new_name_of_index>;
Rename Index
Thank you

More Related Content

What's hot (20)

Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 

Similar to Oracle SQL Basics: Database Concepts, Fundamentals & More

Performance tuning
Performance tuningPerformance tuning
Performance tuningami111
 
How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?loginworks software
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219Peter Schouboe
 
Subqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsSubqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsmaxpane
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republicKaing Menglieng
 
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...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...Alex Zaballa
 
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...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...Alex Zaballa
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Alex Zaballa
 
TSQL in SQL Server 2012
TSQL in SQL Server 2012TSQL in SQL Server 2012
TSQL in SQL Server 2012Eduardo Castro
 
TSQL Coding Guidelines
TSQL Coding GuidelinesTSQL Coding Guidelines
TSQL Coding GuidelinesChris Adkin
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...Jürgen Ambrosi
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesAshwin Dinoriya
 
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020Geir Høydalsvik
 
The ultimate-guide-to-sql
The ultimate-guide-to-sqlThe ultimate-guide-to-sql
The ultimate-guide-to-sqlMcNamaraChiwaye
 

Similar to Oracle SQL Basics: Database Concepts, Fundamentals & More (20)

Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
 
Db2 day 2015 ns ps
Db2 day 2015 ns psDb2 day 2015 ns ps
Db2 day 2015 ns ps
 
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
 
How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?How to work with Subquery in Data Mining?
How to work with Subquery in Data Mining?
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219
 
Subqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsSubqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactions
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
 
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...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...
 
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...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...
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
Beg sql
Beg sqlBeg sql
Beg sql
 
Beg sql
Beg sqlBeg sql
Beg sql
 
TSQL in SQL Server 2012
TSQL in SQL Server 2012TSQL in SQL Server 2012
TSQL in SQL Server 2012
 
TSQL Coding Guidelines
TSQL Coding GuidelinesTSQL Coding Guidelines
TSQL Coding Guidelines
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and Privileges
 
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
 
The ultimate-guide-to-sql
The ultimate-guide-to-sqlThe ultimate-guide-to-sql
The ultimate-guide-to-sql
 

Recently uploaded

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Oracle SQL Basics: Database Concepts, Fundamentals & More

  • 1. Oracle SQL Basics Presented By: Alphalogic Inc. www.alphalogicinc.com
  • 4. Installation Guide Install Oracle Database: Dowanload oracle database from Oracle.com and install it. Link: http://www.oracle.com/technetwo rk/database/enterprise-edition/ downloads/index.html
  • 5. Installation Guide Install Java SDK: Download latest Java SDK from Oracle.com and install it.Set Environment Path for SDK. Link: http://www.oracle.com/technetw ork/java/javase/downloads/inde x.html
  • 6. Installation Guide Install SQL Developer: Download SQL Developer from Oracle.com and install it. SQL Developer is tool to execute and create SQL Queries. Link: http://www.oracle.com/technetwo rk/developer-tools/sql-develope r/downloads/index.html
  • 8. What is Database? A database is a collection of information that is well oraganised so that it can be easily accessed, managed and updated. It is a repository which stores the tables.
  • 9. What is Relational Database (RDBMS)? RDBMS stores the data into collection of tables which might be realted by common fields(columns).
  • 10. What is a Table? ● A table is a collection of related data held in a structured format within a database ● It consists of Fields(Columns) and Records(Rows) ● Every Column has a datatype- Table follows rules like if a column of number datatype can only hold number values so the data is in structured format
  • 11. What is Transaction? ● A transaction comprises of a Unit of work performed within a system against a database and is performed in a reliable way independent of other transactions. ● A transaction is reliable, means if any step during a transaction gets failed then whole transaction would get failed Active Partially CommitedFailed CommitedAborted END Begin
  • 12. ACID Properties ACID refers to the basic properties of a database transaction. All oracle datbase comply with ACID properties. ● Atomicity: The 'All' or 'Nothing' property.The entire seq of actions must be completed or aborted. ● Consistency: The transaction takes the resource from one steady state to another steady state. ● Isolation: A transaction's effect is not visible to other transaction until the transaction is commited. A transaction can not interfere with another transaction ● Durability: Chnages made by the commited transaction are permanent and must survive the system failure.
  • 14. Enter The Database How do we interact with a Database? ● SQL- Structured Query Langauge is a computer language used for storing, manipulating data stored in a relational database ● It supports all relational operator ● Can be embedded in any procedural language Used for insert and create data ● Very easy as the English language ● Using CAT data dictionary SELECT * FROM CAT; ● CAT - Catalouge of all the tables owned by the users Let's See what tables do I own?
  • 15. Let's Limit The Data ● SELECT * FROM sales WHERE total_amount > 1000; ● SELECT * FROM sales WHERE total_amount != 44; ● SELECT * FROM sales WHERE total_amount^44; ● SELECT * FROM sales WHERE quantity <= 10; Use of Where clause for filtering numeric value ● SELECT * FROM sales WHERE sales_date = ’09-feb-2015’; ● SELECT * FROM product WHERE color = ‘RED’; Use of Where clause for filtering text value ● SELECT * FROM sales WHERE total_amount > sales_amount; Use of Where clause for comparing column values 01 02 03
  • 16. Logical Operators ● SELECT * FROM sales WHERE total_amount NOT BETWEEN 1 and 100; ● SELECT * FROM sales WHERE total_amount BETWEEN 1 and 100; Use of BETWEEN and NOT BETWEEN ● SELECT * FROM sales WHERE quantity IN (20,2,10); Use of IN ● SELECT * FROM product WHERE product_name LIKE 'Mob%'; ● SELECT * FROM product WHERE product_name LIKE '%Mob'; ● SELECT * FROM product WHERE product_name LIKE 'Mob_Device'; Use of LIKE 01 02 03
  • 17. Logical Operators ● SELECT * FROM sales WHERE total_amount > ALL (50,100,200); Use of ALL ● SELECT * FROM sales WHERE total_amount > ANY (50,100,200); Use of ANY 04 05 ● SELECT * FROM product WHERE color IS NULL; Use of NULL ● SELECT * FROM sales WHERE total_amount > 100 AND quantiy < 20; Use of AND 06 07
  • 18. Arithmetic Operator 1) Addition ( + ) : SELECT 100/ 20 FROM DUAL; --5 2) Substraction ( - ) : SELECT 100+20 FROM DUAL; --120 3) Multiplication ( * ) : SELECT 100-20 FROM DUAL; --80 4) Division ( / ) : SELECT 100*20 FROM DUAL; --2000 5) Modulus ( % ) : SELECT 10%100 FROM DUAL; --10
  • 19. Let's Sort the Data ● SELECT sales_date, product_id, order_id, sales_amount, tax_amount FROM sales ORDER BY tax_amount; ● SELECT sales_date, product_id, order_id, sales_amount, tax_amount FROM sales ORDER BY sales_amount, tax_amount; ● SELECT order_id, sales_date, product_id, sales_amount, tax_amount FROM sales ORDER BY order_id DESC; Order By Clause NULL values are treated as very large value by Oracle. So NULL data will sort to the bottom of the sort is in ascending order and to the top of the sort is in descending order. How NULL values are treated while sorting the Data?
  • 20. Set Operators ● Set operators combines the result of two component queries into a single unit. Queries containing the set operators are called compound queries ● The data type of columns should be same to use the set operators ● Types of Set Operators: UNION, UNION ALL, INTERSECT, and MINUS
  • 21. Set Operators ● SELECT order_id FROM sales UNION ALL SELECT order_id FROM sales_history; UNION ALL ● SELECT order_id FROM sales UNION SELECT order_id FROM sales_history; UNION 01 02 ● SELECT order_id FROM sales INTERSECT SELECT order_id FROM sales_history; INTERSECT ● SELECT order_id FROM sales MINUS SELECT order_id FROM sales_history; MINUS 03 04
  • 22. Let's group the data ● Aggregate Funcitons returns a single result row based on the group of rows. ● Some of the functions are: MIN(), MAX(), COUNT(), SUM(), AVG() Aggregate/Summary Functions ● SELECT sales_date, SUM(total_amount) FROM sales GROUP BY sales_date; SUM Function 01 02
  • 23. Let's group the data ● Where clause is used to filter the detailed result data whereas Having clause is used to filter the aggregated result. Difference Between Where and Having? 05 ● SELECT sales_date, order_id, MAX(total_amount) FROM sales GROUP BY sales_date, order_id; MAX Funciton ● SELECT sales_date, MIN(total_amount) FROM sales GROUP BY sales_date HAVING MIN(total_amount)< 100; MIN Function with Having Clause 03 04
  • 24. JOINS Joins are used to join one or more table in database using a common column in tables. To get data from two or more tables in single SQL statement To avoid the unwanted duplication of data, we split the single table into multiple table and join them on the basis of common columns Why JOINS?
  • 25. Interesting Things The CASE Statements evaluated a single expression and compares it against several potential values, or evaluates multiple boolean expression and choose the first one that is true. CASE Statements: We can provide different titles to the column name. Spaces are not allowed in an alias name. If required, then use double quotes : SELECT SUM(AMOUNT) "TOTAL AMOUNT" FROM SALES; Alias Name: A pseudo column is an Oracle assigned value used in the same context as column value but not stored on disk. SYSDATE: Returns Current Date USER: Returns the current timestamp ROWNUM: It indicates a number indicating the order of the row selected from the table ROWID: Returns the RowID(Binary Address) of a row in a database table Pseudo Columns in Oracle:
  • 26. Data Definition Language DDL 01 Create Table statement CREATE TABLE movies ( Movie_number number, Movie_name varchar2(100), Movie_type varchar2(40), Movie_release_date date ); 02 Add column to table ALTER TABLE movies ADD (movie_language varchar2(30)); 03 Modify Column attributes ALTER TABLE movies MODIFY (movie_type varchar2(50)); 04 Drop Table DROP TABLE movies;
  • 27. Data Definition Language DDL 05 Insert Values into a table INSERT INTO movies VALUES ( 01, 'TERMINATOR', 'ACTION', '12-JAN-2015' ); COMMIT; 06 Update a record UPDATE movies set movie_release_date = '14-jan-2015' WHERE movie_number = 101; COMMIT; 07 Delete a record DELETE from movies WHERE movie_name = 'RUSH HOUR'; COMMIT; 08 Truncate Statement TRUNCATE TABLE SALES;
  • 28. Data Definition Language DDL Difference between DELETE and TRUNCATE? ROLLBACK after DELETE can work, but not after TRUNCATE. TRUNCATE auto commits. 01 02 DELETE generates a small amount of REDO space and a large amount of UNDO space but TRUNCATE generates neither of these two. 03
  • 29. Let's Put Some Restrictions Constraints apply the specific rule to data, ensuring the data confirms the requirement defined. Example: NOT NULL, UNIQUE, Primary Key, Check, Foreign Key Why constraints? Check constraint validates that value in a given column meets specific criteria. CREATE TABLE movies (Movie_number number, Movie_name varchar2(100), Movie_type varchar2(40) CHECK (movie_type IN ('ACTION', 'COMEDY')), Movie_release_date date); CHECK:
  • 30. Let's Put Some Restrictions A foreign Key constraint is used to enforce a relationship between two tables CREATE TABLE movies (Movie_number number, Movie_name varchar2(100), Movie_type varchar2(40), Movie_release_date date, Movie_director_number number REFERENCES director(director_number) ); Foreign Key:
  • 31. VIEWS A view is simply the representation of a SQL statement that is stored in memory so that it can be easily reused. ● A view gives a look of a table as defined by the select statement in the view definition ● A view does not store data separately ● Only the definition(SQL statement) of the view is stored ● The data is retrieved from the underlying table based on the view definition ● Advantages: ● Security - restrict the access of complete data to all ● Abstraction - Hiding complex logic and just displaying the required output What is a VIEW?
  • 32. VIEWS CREATE VIEW SALES_MOBILE AS SELECT S.SALES_DATE, S.ORDER_ID, S.QUANTITY, S.UNIT_PRICE, S.TOTAL_AMOUNT, P.PRODUCT_NAME, P.PRODUCT_CATEGORY FROM SALES S, PRODUCT P WHERE S.PRODUCT_ID = P.PRODUCT_ID AND PRODUCT_CATEGORY = 'Mobile'; Create a View CREATE OR REPLACE VIEW SALES_MOBILE AS SELECT S.SALES_DATE, S.ORDER_ID, S.QUANTITY, S.UNIT_PRICE, S.TOTAL_AMOUNT, P.PRODUCT_NAME, P.PRODUCT_CATEGORY, S.PRODUCT_ID FROM SALES S, PRODUCT P WHERE S.PRODUCT_ID = P.PRODUCT_ID AND PRODUCT_CATEGORY = 'Mobile'; Modify View DROP view SALES_MOBILE; Drop a View
  • 33. Other Database Objects ● Synonym is an alternative name for a table, view, sequence, procedure, stored function ● Syntax: CREATE SYNONYM inventory_data FROM SALES; Synonyms ● A Sequence is an object in Oracle that is used to generate a number series(sequence). ● This can be useful when you need to create a Unique number to act as a primary key. ● Syntax: CREATE SEQUENCE VA_RECORD_ID MIN VALUE 1, MAX VALUE 999999, START_WITH , INCEREMENT BY 1, CACHE 10; ● NEXTVAL is used to get next value of sequence and CURRVAL is used to get the current value. Sequences
  • 34. Giving Permissions To Other Users ● GRANT command can be used to grant schema object privileges to the role or to the user ● WITH GRANT OPTION enables the user to pass on the privilege to other user or role. ● Syntax: GRANT SELECT ON SALES TO SCOTT WITH GRANT OPTION; GRANT ● REVOKE command can be used to take back the granted privileges to the user or role ● Syntax: REVOKE ALL ON SALES FROM SCOTT; REVOKE
  • 35. Sub Queries ● A sub query is a query within a query which can return one or more rows. A subquery executes inner query before the main query Sub Suery ● Pair wise Comparision: Values compared in pair ● Syntax: SELECT sales_date, order_id, customer_id FROM SALES WHERE (product_id, unit_price) IN (SELECT product_id, unit_price FROM SALESPERSON where sales_date='01-Jan-2009'); ● Non Pairwise Comparision: Values are compared individually Multiple Column Subqueries
  • 36. Sub Queries To hold the result of a SQL statement using a WITH clause and use it in multiple SQL Statement. ● Syntax: WITH st as (SELECT * FROM SALES_TOTAL) SELECT * FROM SALES s, st WHERE s.sales_date=st.sales_date; WITH Clause Scaler sub queries will allow treating the output of a sub query as a column or even an expression within a select statement. ● It must return only one row and one column. ● Syntax: SELECT s.sales_date, s.id, (SELECT SUM(total_sakes) FROM SALES) as sales_total from SALES s; Scaler Subquery
  • 37. Sub Queries Correlated sub query is a subquery that uses the values from the outer query and is evaluated once for each row processed by the outer query. ● Syntax: SELECT * FROM SALES x where total_amt>(SELECT AVG(sales_amt) FROM SALES y WHERE y.c_id=x.c_id); Corelated Subquery
  • 38. Index An index is a performance tuning method of allowing faster retrieval of records Properties: ● Indexes enable faster data acess ● Index stores column values and their location ● The index can be created on multiple columns Index DROP INDEX <index_name>; DROP Index:
  • 39. Index A unique Index is an Index no duplicate values are allowed ● Unique Index will not accept duplicate values ● It can have null values until and unless restricted ● Syntax: CREATE UNIQUE INDEX cust_idx ON CUSTOMER(cust_id); Unique Index ALTER INDEX <index_old_name> RENAME TO new_name_of_index>; Rename Index