SlideShare a Scribd company logo
SQL Fundamentals Oracle 11g
M U H A M M A D WA H E E D
O R AC L E DATA BA S E D E V E LO P E R
E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m
Lecture#5
Basics of SELECT Statement
Transaction Properties
•All database transactions are ACID.
Atomicity
Consistency
Isolation
Durability
2
Transaction Properties(cont’d)
•All database transactions are ACID.
Atomicity: The entire sequence of actions must be either
completed or aborted. The transaction cannot be partially
successful.
Consistency: The transaction takes the resources from one
consistent state to another.
Isolation:A transaction's effect is not visible to other
transactions until the transaction is committed.
Durability:Changes made by the committed transaction are
permanent and must survive system failure.
3
SELECT Statement
•SELECT identifies what columns.
•FROM identifies which table.
4
Arithmetic Expressions
•Create expressions with number and date by using following
arithmetic operators:
Divide ( / )
Multiply ( * )
Add ( + )
Subtract ( - )
•You can use arithmetic operators in any SQL clause except FROM
clause.
•Operator precedence is applied by default. We need to use
parenthesis for custom precedence.
5
Arithmetic Expressions(cont’d)
•Example:
SELECT std_name,std_age + 30
FROM student;
•Example:
SELECT std_name,std_marks + 10/100
FROM student;
*enforcement of custom operator precedence is (std_marks + 10)/100.
6
Aliases
•Oracle ALIASES can be used to create a temporary name for
columns or tables.
•It has two types: column alias, table alias
•COLUMN ALIASES are used to make column headings in
your result set easier to read.
•TABLE ALIASES are used to shorten your SQL to make it
easier to read or when you are listing the same table more
than once in the FROM clause.
7
Aliases(cont’d)
•Syntax:
Column Alias : <column_name> AS <alias_name>
Table Alias : <table_name> <alias_name>
•Alias name can not contain special characters but if it
is desired then use double-quotes i.e.
“<alias_name>”.
•*Remember: ‘AS’ is only used with column not table.
8
Column Aliases(cont’d)
•Example:
SELECT std_id AS ID , std_name AS NAME
FROM student;
•To have special character in alias name follow following example:
SELECT std_id AS “Student ID” , std_name AS “Student Name”
FROM student;
or
SELECT std_id AS id, std_name AS "Student Name" FROM student;
9
Table Aliases(cont’d)
•Example:
SELECT s.std_id , s.std_name
FROM student s;
•To have special character in alias name follow following
example:
SELECT s.std_id AS “Student ID” , s.std_name AS “Student
Name”
FROM student s;
10
Aliases(cont’d)
11
Concatenation Operator
12
•Concatenates columns or character strings to other
column.
•It is represented by vertical bars ( || ).
Concatenation(cont’d)
13
•Example:
SELECT std_id||std_name FROM student;
•Example:
SELECT std_id||std_name AS “name”FROM student;
•Example:
SELECT std_id||std_name||std_age FROM student;
Concatenation(cont’d)
14
•Using Literal character string.
•It is neither column name nor a column alias rather it
is a string enclosed in single quotes.
•Example:
SELECT std_name|| ‘is’ || age || ‘years old’ AS
“Student Age”
FROM student;
Duplicate Records
15
•By default SELECT selects all rows from a table
including duplicate records.
•Duplicate records can be eliminated by using
keyword “DISTINCT”.
•Example:
SELECT DISTINCT std_name FROM student;
View Table Structure
16
•Syntax:
DESC[CRIBE] <table_name>;
bracket’s enclosed part is optional.
View Table SQL Structure
17
•Syntax:
SELECT
DBMS_METADATA.GET_DDL(‘TABLE’,‘<table_name>'[,‘<user
_name/schema>']) from DUAL;
bracket’s enclosed part is optional.
WHERE Clause
18
•Restricts the records to be displayed.
•Character string and date are enclosed in single
quotes.
•Character values are case sensitive while date values
are format sensitive.
•Default date format is ‘DD-MON-YY’.
Comparison Conditions/Operators
19
•There are following conditions:
=
>=
<
<=
<> (not equal to)
•Example:
SELECT * FROM student WHERE std_id<>1;
Comparison
Conditions/Operators(cont’d)
20
•Few other operators/conditions are:
> BETWEEN <lower_limit> AND <upper_limit>
> IN/MEMBERSHIP (set/list of values)
> LIKE
> IS NULL
BETWEEN … AND … Condition
21
•Use the BETWEEN condition to display rows based on
a range of values.
•Example:
SELECT * FROM student
WHERE std_age BETWEEN 17 AND 21;
IN/ MEMBERSHIP Condition
22
•Use to test/compare values from list of available
values.
•Example: let we have library defaulters with IDs
102,140,450 etc.
SELECT * FROM student
WHERE std_id IN ( 102,140,450);
Wildcard
23
•Databases often treat % and _ as wildcard characters.
•Pattern-match queries in the SQL repository (such as
CONTAINS, STARTS WITH, or ENDS WITH), assume
that a query that includes % or _ is intended as a
literal search including those characters and is not
intended to include wildcard characters.
LIKE Condition/Operator
24
•The Oracle LIKE condition allows wildcards to be
used in the WHERE clause of a SELECT, INSERT,
UPDATE, or DELETE statement. This allows you to
perform pattern matching.
LIKE Condition/Operator(cont’d)
25
•The SQL LIKE clause is used to compare a value to the
existing records in the database records
partially/fully.
•There are two wildcards used in conjunction with the
LIKE operator:
percent sign (%)
underscore (_)
LIKE Criteria Example(cont’d)
26
NULL Condition
27
•Compare records to find NULL values by using ‘IS
NULL’.
•Example: all students having no contact info
SELECT * FROM student
WHERE std_contact IS NULL;
LOGICAL Conditions
•A logical condition combines the result of two columns or inverts the value of a single column.
•There are following logical operators:
AND
OR
NOT
28
AND - Logical Conditions(cont’d)
•AND requires both conditions to be true.
•Example:
SELECT * FROM student WHERE std_id=1 AND age=21;
•Example:
SELECT * FROM student WHERE std_id <=5 AND std_name LIKE ‘%a%’;
29
OR - Logical Conditions(cont’d)
•OR requires both conditions to be true.
•Example:
SELECT * FROM student WHERE std_id=1 OR age=21;
•Example:
SELECT * FROM student WHERE std_id <=5 OR std_name LIKE ‘%a%’;
30
NOT - Logical Conditions(cont’d)
•NOT inverses the resulting value.
•NOT is used with other SQL operators e.g BETWEEN,IN,LIKE.
•Examples:
SELECT * FROM student
WHERE std_id NOT BETWEEN 1 AND 5;
WHERE std_id NOT IN (101,140,450);
WHERE std_name NOT LIKE ‘%A%’;
WHERE std_contact IS NOT NULL;
•Example:
SELECT * FROM student WHERE std_id <=5 OR std_name LIKE ‘%a%’;
31
Rules of Precedence
32
Rules of Precedence(cont’d)
•Example:
SELECT * FROM student
WHERE tch_name LIKE ‘%a%’
OR tch_id >5
AND tch_salary>=20000;
*it evaluates as “select all columns if tch_id is greater than 5 and tch_salary is greater or equal
to 20000, or if the tch_name containing ‘a’.
** to perform the OR operation first apply parenthesis.
33
ORDER BY Clause
•Sort the resulting rows in following orders:
ASC: ascending order(by default)
DESC: descending order
•It is used with select statement.
34
ORDER BY Clause(cont’d)
•Example:
SELECT * FROM student
ORDER BY dob;
or
SELECT * FROM student
ORDER BY dob DESC;
•ORDER BY on multiple columns:
SELECT * FROM student
ORDER BY dob,std_name DESC;
35
Motivational Speaking
36
Feedback/Suggestions?
Give your feedback at: m.waheed3668@gmail.com

More Related Content

What's hot

Session 6
Session 6Session 6
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
bixxman
 
Sql select
Sql select Sql select
Sql select
Mudasir Syed
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
Syed Zaid Irshad
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Select Clause
Select ClauseSelect Clause
Select Clause
Dhirendra Chauhan
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQL
Raajendra M
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
Ahmed Farag
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
PADYALAMAITHILINATHA
 
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
Terry Reese
 
Mandatory sql functions for beginners
Mandatory sql functions for beginnersMandatory sql functions for beginners
Mandatory sql functions for beginners
shravan kumar chelika
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
Balqees Al.Mubarak
 
Sql commands
Sql commandsSql commands
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
Ahmed Farag
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
Ahmed Farag
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
Vivek Singh
 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6
sumitbardhan
 
DML Commands
DML CommandsDML Commands

What's hot (20)

Session 6
Session 6Session 6
Session 6
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Sql select
Sql select Sql select
Sql select
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Select Clause
Select ClauseSelect Clause
Select Clause
 
Where conditions and Operators in SQL
Where conditions and Operators in SQLWhere conditions and Operators in SQL
Where conditions and Operators in SQL
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
 
Mandatory sql functions for beginners
Mandatory sql functions for beginnersMandatory sql functions for beginners
Mandatory sql functions for beginners
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
Sql commands
Sql commandsSql commands
Sql commands
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6
 
DML Commands
DML CommandsDML Commands
DML Commands
 

Similar to Basics of SELECT Statement - Oracle SQL

SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptx
RUBAB79
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
ssuser0562f1
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
ssuser0562f1
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
Anusha sivakumar
 
Practical 03 (1).pptx
Practical 03 (1).pptxPractical 03 (1).pptx
Practical 03 (1).pptx
solangiirfan92
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
newrforce
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
SaurabhLokare1
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Md. Mahedee Hasan
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
N.Jagadish Kumar
 
SQL
SQLSQL
SQL SELECT Statement
 SQL SELECT Statement SQL SELECT Statement
SQL SELECT Statement
IslamicUniversityofL
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
Achmad Solichin
 
Les01
Les01Les01
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
RickyLidar
 
relational algebra and it's implementation
relational algebra and it's implementationrelational algebra and it's implementation
relational algebra and it's implementation
dbmscse61
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
Javaid Iqbal
 

Similar to Basics of SELECT Statement - Oracle SQL (20)

SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptx
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 
Practical 03 (1).pptx
Practical 03 (1).pptxPractical 03 (1).pptx
Practical 03 (1).pptx
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
SQL
SQLSQL
SQL
 
SQL SELECT Statement
 SQL SELECT Statement SQL SELECT Statement
SQL SELECT Statement
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 
Les01
Les01Les01
Les01
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
relational algebra and it's implementation
relational algebra and it's implementationrelational algebra and it's implementation
relational algebra and it's implementation
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
 

Recently uploaded

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 

Recently uploaded (20)

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 

Basics of SELECT Statement - Oracle SQL

  • 1. SQL Fundamentals Oracle 11g M U H A M M A D WA H E E D O R AC L E DATA BA S E D E V E LO P E R E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m Lecture#5 Basics of SELECT Statement
  • 2. Transaction Properties •All database transactions are ACID. Atomicity Consistency Isolation Durability 2
  • 3. Transaction Properties(cont’d) •All database transactions are ACID. Atomicity: The entire sequence of actions must be either completed or aborted. The transaction cannot be partially successful. Consistency: The transaction takes the resources from one consistent state to another. Isolation:A transaction's effect is not visible to other transactions until the transaction is committed. Durability:Changes made by the committed transaction are permanent and must survive system failure. 3
  • 4. SELECT Statement •SELECT identifies what columns. •FROM identifies which table. 4
  • 5. Arithmetic Expressions •Create expressions with number and date by using following arithmetic operators: Divide ( / ) Multiply ( * ) Add ( + ) Subtract ( - ) •You can use arithmetic operators in any SQL clause except FROM clause. •Operator precedence is applied by default. We need to use parenthesis for custom precedence. 5
  • 6. Arithmetic Expressions(cont’d) •Example: SELECT std_name,std_age + 30 FROM student; •Example: SELECT std_name,std_marks + 10/100 FROM student; *enforcement of custom operator precedence is (std_marks + 10)/100. 6
  • 7. Aliases •Oracle ALIASES can be used to create a temporary name for columns or tables. •It has two types: column alias, table alias •COLUMN ALIASES are used to make column headings in your result set easier to read. •TABLE ALIASES are used to shorten your SQL to make it easier to read or when you are listing the same table more than once in the FROM clause. 7
  • 8. Aliases(cont’d) •Syntax: Column Alias : <column_name> AS <alias_name> Table Alias : <table_name> <alias_name> •Alias name can not contain special characters but if it is desired then use double-quotes i.e. “<alias_name>”. •*Remember: ‘AS’ is only used with column not table. 8
  • 9. Column Aliases(cont’d) •Example: SELECT std_id AS ID , std_name AS NAME FROM student; •To have special character in alias name follow following example: SELECT std_id AS “Student ID” , std_name AS “Student Name” FROM student; or SELECT std_id AS id, std_name AS "Student Name" FROM student; 9
  • 10. Table Aliases(cont’d) •Example: SELECT s.std_id , s.std_name FROM student s; •To have special character in alias name follow following example: SELECT s.std_id AS “Student ID” , s.std_name AS “Student Name” FROM student s; 10
  • 12. Concatenation Operator 12 •Concatenates columns or character strings to other column. •It is represented by vertical bars ( || ).
  • 13. Concatenation(cont’d) 13 •Example: SELECT std_id||std_name FROM student; •Example: SELECT std_id||std_name AS “name”FROM student; •Example: SELECT std_id||std_name||std_age FROM student;
  • 14. Concatenation(cont’d) 14 •Using Literal character string. •It is neither column name nor a column alias rather it is a string enclosed in single quotes. •Example: SELECT std_name|| ‘is’ || age || ‘years old’ AS “Student Age” FROM student;
  • 15. Duplicate Records 15 •By default SELECT selects all rows from a table including duplicate records. •Duplicate records can be eliminated by using keyword “DISTINCT”. •Example: SELECT DISTINCT std_name FROM student;
  • 16. View Table Structure 16 •Syntax: DESC[CRIBE] <table_name>; bracket’s enclosed part is optional.
  • 17. View Table SQL Structure 17 •Syntax: SELECT DBMS_METADATA.GET_DDL(‘TABLE’,‘<table_name>'[,‘<user _name/schema>']) from DUAL; bracket’s enclosed part is optional.
  • 18. WHERE Clause 18 •Restricts the records to be displayed. •Character string and date are enclosed in single quotes. •Character values are case sensitive while date values are format sensitive. •Default date format is ‘DD-MON-YY’.
  • 19. Comparison Conditions/Operators 19 •There are following conditions: = >= < <= <> (not equal to) •Example: SELECT * FROM student WHERE std_id<>1;
  • 20. Comparison Conditions/Operators(cont’d) 20 •Few other operators/conditions are: > BETWEEN <lower_limit> AND <upper_limit> > IN/MEMBERSHIP (set/list of values) > LIKE > IS NULL
  • 21. BETWEEN … AND … Condition 21 •Use the BETWEEN condition to display rows based on a range of values. •Example: SELECT * FROM student WHERE std_age BETWEEN 17 AND 21;
  • 22. IN/ MEMBERSHIP Condition 22 •Use to test/compare values from list of available values. •Example: let we have library defaulters with IDs 102,140,450 etc. SELECT * FROM student WHERE std_id IN ( 102,140,450);
  • 23. Wildcard 23 •Databases often treat % and _ as wildcard characters. •Pattern-match queries in the SQL repository (such as CONTAINS, STARTS WITH, or ENDS WITH), assume that a query that includes % or _ is intended as a literal search including those characters and is not intended to include wildcard characters.
  • 24. LIKE Condition/Operator 24 •The Oracle LIKE condition allows wildcards to be used in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement. This allows you to perform pattern matching.
  • 25. LIKE Condition/Operator(cont’d) 25 •The SQL LIKE clause is used to compare a value to the existing records in the database records partially/fully. •There are two wildcards used in conjunction with the LIKE operator: percent sign (%) underscore (_)
  • 27. NULL Condition 27 •Compare records to find NULL values by using ‘IS NULL’. •Example: all students having no contact info SELECT * FROM student WHERE std_contact IS NULL;
  • 28. LOGICAL Conditions •A logical condition combines the result of two columns or inverts the value of a single column. •There are following logical operators: AND OR NOT 28
  • 29. AND - Logical Conditions(cont’d) •AND requires both conditions to be true. •Example: SELECT * FROM student WHERE std_id=1 AND age=21; •Example: SELECT * FROM student WHERE std_id <=5 AND std_name LIKE ‘%a%’; 29
  • 30. OR - Logical Conditions(cont’d) •OR requires both conditions to be true. •Example: SELECT * FROM student WHERE std_id=1 OR age=21; •Example: SELECT * FROM student WHERE std_id <=5 OR std_name LIKE ‘%a%’; 30
  • 31. NOT - Logical Conditions(cont’d) •NOT inverses the resulting value. •NOT is used with other SQL operators e.g BETWEEN,IN,LIKE. •Examples: SELECT * FROM student WHERE std_id NOT BETWEEN 1 AND 5; WHERE std_id NOT IN (101,140,450); WHERE std_name NOT LIKE ‘%A%’; WHERE std_contact IS NOT NULL; •Example: SELECT * FROM student WHERE std_id <=5 OR std_name LIKE ‘%a%’; 31
  • 33. Rules of Precedence(cont’d) •Example: SELECT * FROM student WHERE tch_name LIKE ‘%a%’ OR tch_id >5 AND tch_salary>=20000; *it evaluates as “select all columns if tch_id is greater than 5 and tch_salary is greater or equal to 20000, or if the tch_name containing ‘a’. ** to perform the OR operation first apply parenthesis. 33
  • 34. ORDER BY Clause •Sort the resulting rows in following orders: ASC: ascending order(by default) DESC: descending order •It is used with select statement. 34
  • 35. ORDER BY Clause(cont’d) •Example: SELECT * FROM student ORDER BY dob; or SELECT * FROM student ORDER BY dob DESC; •ORDER BY on multiple columns: SELECT * FROM student ORDER BY dob,std_name DESC; 35
  • 37. Feedback/Suggestions? Give your feedback at: m.waheed3668@gmail.com