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

What's hot (20)

PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Sql server windowing functions
Sql server windowing functionsSql server windowing functions
Sql server windowing functions
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Oracle Database Sequence
Oracle Database SequenceOracle Database Sequence
Oracle Database Sequence
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Database
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Create table
Create tableCreate table
Create table
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
SQL
SQLSQL
SQL
 

Similar to Oracle SQL Basics

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

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 

Recently uploaded (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 

Oracle SQL Basics

  • 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