SlideShare a Scribd company logo
1 of 49
SQL
Statements
Vikas K.Gupta
SQL as the standard language
īŽ

Oracle SQL complies with industry-accepted standards.

īŽ

Oracle Corporation ensures future compliance with evolving
standards by actively involving key personnel in SQL standards
committees.

īŽ

Industry-accepted committees are the American National Standards
Institute (ANSI) and the International Standards Organization (ISO).

īŽ

Both ANSI and ISO have accepted SQL as the standard language
for relational databases.
SQL Statements
īŽ

DRL - Retrieves data from the database

īŽ

DML - Enters new rows, changes existing
rows, and removes unwanted rows from
tables in the database, respectively.

īŽ

DDL - Sets up, changes, and removes data
structures from tables.

īŽ

TCL - Manages the changes made by DML
statements. Changes to the data can be
grouped together into logical transactions.

īŽ

DCL - Gives or removes access rights to
both the Oracle database and the structures
within it.
SELECT Statements
īŽ

To extract data from the database, you need to use SELECT statement.

Using a SELECT statement, you can do the following:
īŽ

Projection:
choose the columns in a table that you want returned by your query. You can choose
as few or as many columns of the table as you require.

īŽ

Selection:
choose the rows in a table that you want returned by a query. You can use various
criteria to restrict the rows that you see.

īŽ

Joining:
Bring together data that is stored in different tables by creating a link between them.
Basic SELECT Statement
īŽ
īŽ

SELECT identifies what columns
FROM identifies which table
Null Value
īŽ

A null is a value that is unavailable, unassigned, unknown, or
inapplicable.

īŽ

A null is not the same as zero or a blank space. Zero is a number, and a
space is a character.

īŽ

If a row lacks the data value for a particular column, that value is said to be
null, or to contain a null.

īŽ

If any column value in an arithmetic expression is null, the result is null.

īŽ

For example, if you attempt to perform division with zero, you get an error.
However, if you divide a number by null, the result is a null or unknown.
Column Alias
īŽ

Renames a column heading

īŽ

Specify the alias after the column using a space as a separator.
there can also be the optional AS keyword between the column
name and alias

īŽ

Requires double quotation marks if it contains spaces or
special characters or is case sensitive

īŽ

By default, alias headings appear in uppercase. If the alias contains
spaces or special characters (such as # or $), or is case sensitive,
enclose the alias in double quotation marks (" ").
Concatenation Operator
īŽ

Concatenates columns or character strings to other columns

īŽ

Is represented by two vertical bars (||)

īŽ

Creates a resultant column that is a character expression

īŽ

You can link columns to other columns, arithmetic expressions, or
constant values to create a character expression by using the
concatenation operator (||).

īŽ

Columns on either side of the operator are combined to make a
single output column.
Literal Character Strings
īŽ

A literal is a character, a number, or a date that is included in the SELECT
list and that is not a column name or a column alias.

īŽ

It is printed for each row returned.

īŽ

Literal strings of free-format text can be included in the query result and are
treated the same as a column in the SELECT list.

īŽ

Date and character literals must be enclosed within single quotation
marks (’ ’); number literals need not.
Eliminating Duplicate Rows
īŽ

Eliminate duplicate rows by using the DISTINCT
keyword in the SELECT clause.
SQL Statements
Versus

iSQL*Plus Commands
Displaying Table Structure
īŽ

Use the iSQL*Plus DESCRIBE command to display the
structure of a table.
Chapter - 2

Restricting and
Sorting Data
Where clause
Selection
īŽ

Restrict the rows returned by using the WHERE clause.

īŽ

A WHERE clause contains a condition that must be met, and it directly follows the
FROM clause.

īŽ

If the condition is true, the row meeting the condition is returned.

īŽ

The WHERE clause can compare values in columns, literal values, arithmetic
expressions, or functions.

īŽ

It consists of three elements:

īŽ

Column name
Comparison condition
Column name, constant, or list of values

īŽ
īŽ
Character Strings and Dates
īŽ

Character strings and date values are enclosed in single quotation
marks.

īŽ

Character values are case sensitive, and date values are format
sensitive.

īŽ

The default date format is DD-MON-RR.
Comparison Conditions
īŽ

Comparison conditions are
used in conditions that
compare one expression to
another value or expression.

īŽ

They are used in the WHERE
clause.

īŽ

An alias cannot be used in the
WHERE clause.

īŽ

Note: The symbol != and ^=
can also represent the not
equal to condition.
Other Comparison Conditions
īŽ

Use the BETWEEN condition to display
rows based on a range of values.

īŽ

Use the IN membership condition to test for
values in a list.

īŽ

Use the LIKE condition to perform wildcard
searches of valid search string values.

īŽ

Search conditions can contain either literal
characters or numbers:
% denotes zero or many characters.
_ denotes one character.

īŽ

Test for nulls with the IS NULL operator.
Examples
Logical Conditions
īŽ

A logical condition combines
the result of two component
conditions to produce a single
result based on them or inverts
the result of a single condition.

īŽ

A row is returned only if the
overall result of the condition is
true.

īŽ

You can use several
conditions in one WHERE
clause using the AND and OR
operators.
Examples :
Rules of Precedence
ORDER BY Clause
īŽ

Sort rows with the ORDER BY clause
ASC: ascending order, default
DESC: descending order

īŽ

The ORDER BY clause comes last in the SELECT statement.

īŽ

The order of rows returned in a query result is undefined. The ORDER BY clause can
be used to sort the rows.

īŽ

You can specify an expression, or an alias, or column position as the sort condition.

īŽ

Null values are displayed last for ascending sequences and first for descending
sequences.
Chapter - 3

Single-Row
Functions
character, number, and date functions
SQL Functions
īŽ

Perform calculations on data

īŽ

Modify individual data items

īŽ

Manipulate output for groups of rows

īŽ

Format dates and numbers for display

īŽ

Convert column data types

īŽ

SQL functions sometimes take
arguments and always return a value.
Types of SQL Functions
Single-Row Functions
īŽ

These functions operate on single rows only
and return one result per row.

There are different types of single-row functions.
īŽ
īŽ
īŽ
īŽ

Character
Number
Date
Conversion

Multiple-Row Functions
īŽ

Functions can manipulate groups of rows to
give one result per group of rows. These
functions are known as group functions.
Character Functions
Case Manipulation Functions
LOWER, UPPER, and INITCAP are
the three case- conversion
functions.
īŽ

LOWER Converts mixed case or
uppercase character strings to
lowercase

īŽ

UPPER Converts mixed case or
lowercase character strings to
uppercase

īŽ

INITCAP Converts the first letter
of each word to uppercase and
remaining letters to lowercase
Character-Manipulation Functions
īŽ

CONCAT Joins values together (You are
limited to using two parameters with
CONCAT.)

īŽ

SUBSTR Extracts a string of determined
length

īŽ

LENGTH Shows the length of a string as a
numeric value

īŽ

INSTR Finds numeric position of a named
character

īŽ

LPAD Pads the character value rightjustified

īŽ

RPAD: Pads the character value leftjustified

īŽ

TRIM: Trims heading or trailing characters
(or both) from a character string
Number Functions
īŽ

ROUND: Rounds value to specified decimal
ROUND(45.926, 2)

īŽ

TRUNC: Truncates value to specified decimal
TRUNC(45.926, 2)

īŽ

45.93

45.92

MOD: Returns remainder of division
MOD(1600, 300)

100
ROUND Function
īŽ

The ROUND function rounds the column, expression, or value to n decimal
places.

īŽ

If the second argument is 0 or is missing, the value is rounded to zero decimal
places.

īŽ

If the second argument is 2, the value is rounded to two decimal places.

īŽ

Conversely, if the second argument is -2, the value is rounded to two decimal places
to the left.

TRUNC Function
īŽ

The TRUNC function works with arguments similar to those of the ROUND function.
DUAL Table
īŽ

The DUAL table is owned by the user SYS and can be accessed by
all users.

īŽ

It contains one column, DUMMY, and one row with the value X.

īŽ

The DUAL table is useful when you want to return a value once
only, for instance, the value of a constant, pseudo column, or
expression that is not derived from a table with user data.

īŽ

The DUAL table is generally used for SELECT clause syntax
completeness, because both SELECT and FROM clauses are
mandatory, and several calculations do not need to select from
actual tables.
Working with Dates
īŽ

The default date display format is DD-MON-RR.

īŽ

Valid Oracle dates are between January 1, 4712 B.C. and December 31, 9999 A.D.

SYSDATE is a function that returns:
īŽ
īŽ
īŽ

Date
Time
SYSDATE is a date function that returns the current database server date and time.
You can use SYSDATE just as you would use any other column name.
Arithmetic with Dates
īŽ

Add or subtract a number to or from a date for a resultant date value.

īŽ

Subtract two dates to find the number of days between those dates.

īŽ

Add hours to a date by dividing the number of hours by 24.
Calculate the number of weeks

īŽ

The example on the slide displays the last name and the number of weeks
employed for all employees in department 90.

īŽ

It subtracts the date on which the employee was hired from the current date
(SYSDATE) and divides the result by 7 to calculate the number of weeks
that a worker has been employed.
Date Functions
īŽ

MONTHS_BETWEEN(date1, date2) -The
result can be positive or negative. If date1 is
later than date2, the result is positive; if
date1 is earlier than date2, the result is
negative.

īŽ

ADD_MONTHS (date, n) Adds n number of
calendar months to date.

īŽ

NEXT_DAY (date, 'char') Finds the date of
the next specified day of the week ('char')
following date. The value of char may be a
number representing a day or a character
string.

īŽ

LAST_DAY (date) Finds the date of the last
day of the month that contains date.

īŽ

ROUND (date[,'fmt']) If the format model
fmt is omitted, date is rounded to the
nearest day.

īŽ

TRUNC (date[, 'fmt']) If the format model
fmt is omitted, date is truncated to the
nearest day.
Using Date Functions
Using Date Functions
Conversion Functions
Implicit Data Type Conversion
Explicit Data Type Conversion
Using the TO_CHAR Function with Dates

The format model:
īŽ

Must be enclosed in single quotation marks and is case sensitive

īŽ

Can include any valid date format element

īŽ

Has an fm element to remove padded blanks or suppress leading zeros

īŽ

Is separated from the date value by a comma
Elements of the Date Format Model
Using the TO_CHAR Function with Numbers

These are some of the format elements you can use with the TO_CHAR function to
display a number value as a character:
SQL select statement and functions
SQL select statement and functions

More Related Content

What's hot

SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
kuldeep100
 

What's hot (20)

SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
 
Mysql
MysqlMysql
Mysql
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Oracle Database Sequence
Oracle Database SequenceOracle Database Sequence
Oracle Database Sequence
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
DML Commands
DML CommandsDML Commands
DML Commands
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 

Viewers also liked

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
 
Sql ppt
Sql pptSql ppt
Sql ppt
Anuja Lad
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
vijaybusu
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
Jamshid Hashimi
 
ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7
ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7
ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7
Dmitriy Krukov
 
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure PresentationMicrosoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft Private Cloud
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statements
Arun Nair
 

Viewers also liked (20)

SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic 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)
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
 
Mca ii-dbms-u-iv-structured query language
Mca ii-dbms-u-iv-structured query languageMca ii-dbms-u-iv-structured query language
Mca ii-dbms-u-iv-structured query language
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
 
Les04
Les04Les04
Les04
 
Les04
Les04Les04
Les04
 
ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7
ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7
ĐŖĐŋŅ€Đ°Đ˛ĐģĐĩĐŊиĐĩ ДаĐŊĐŊŅ‹Đŧи. ЛĐĩĐēŅ†Đ¸Ņ 7
 
SQL Differences SQL Interview Questions
SQL Differences  SQL Interview QuestionsSQL Differences  SQL Interview Questions
SQL Differences SQL Interview Questions
 
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure PresentationMicrosoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
 
Datastage Introduction To Data Warehousing
Datastage Introduction To Data WarehousingDatastage Introduction To Data Warehousing
Datastage Introduction To Data Warehousing
 
Sql server select queries ppt 18
Sql server select queries ppt 18Sql server select queries ppt 18
Sql server select queries ppt 18
 
Single-Row Functions in orcale Data base
Single-Row Functions in orcale Data baseSingle-Row Functions in orcale Data base
Single-Row Functions in orcale Data base
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statements
 

Similar to SQL select statement and functions

Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
Nalina Kumari
 
Module03
Module03Module03
Module03
Sridhar P
 

Similar to SQL select statement and functions (20)

Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
Sql
SqlSql
Sql
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
 
Module03
Module03Module03
Module03
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
SQL report
SQL reportSQL report
SQL report
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Sql functions
Sql functionsSql functions
Sql functions
 
SQL
SQLSQL
SQL
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 

More from Vikas Gupta (7)

SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Sql DML
Sql DMLSql DML
Sql DML
 
Sql DML
Sql DMLSql DML
Sql DML
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Sql join
Sql  joinSql  join
Sql join
 
Join sql
Join sqlJoin sql
Join sql
 
Sql intro
Sql introSql intro
Sql intro
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎ī¸+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

SQL select statement and functions

  • 2. SQL as the standard language īŽ Oracle SQL complies with industry-accepted standards. īŽ Oracle Corporation ensures future compliance with evolving standards by actively involving key personnel in SQL standards committees. īŽ Industry-accepted committees are the American National Standards Institute (ANSI) and the International Standards Organization (ISO). īŽ Both ANSI and ISO have accepted SQL as the standard language for relational databases.
  • 3. SQL Statements īŽ DRL - Retrieves data from the database īŽ DML - Enters new rows, changes existing rows, and removes unwanted rows from tables in the database, respectively. īŽ DDL - Sets up, changes, and removes data structures from tables. īŽ TCL - Manages the changes made by DML statements. Changes to the data can be grouped together into logical transactions. īŽ DCL - Gives or removes access rights to both the Oracle database and the structures within it.
  • 4. SELECT Statements īŽ To extract data from the database, you need to use SELECT statement. Using a SELECT statement, you can do the following: īŽ Projection: choose the columns in a table that you want returned by your query. You can choose as few or as many columns of the table as you require. īŽ Selection: choose the rows in a table that you want returned by a query. You can use various criteria to restrict the rows that you see. īŽ Joining: Bring together data that is stored in different tables by creating a link between them.
  • 5. Basic SELECT Statement īŽ īŽ SELECT identifies what columns FROM identifies which table
  • 6. Null Value īŽ A null is a value that is unavailable, unassigned, unknown, or inapplicable. īŽ A null is not the same as zero or a blank space. Zero is a number, and a space is a character. īŽ If a row lacks the data value for a particular column, that value is said to be null, or to contain a null. īŽ If any column value in an arithmetic expression is null, the result is null. īŽ For example, if you attempt to perform division with zero, you get an error. However, if you divide a number by null, the result is a null or unknown.
  • 7. Column Alias īŽ Renames a column heading īŽ Specify the alias after the column using a space as a separator. there can also be the optional AS keyword between the column name and alias īŽ Requires double quotation marks if it contains spaces or special characters or is case sensitive īŽ By default, alias headings appear in uppercase. If the alias contains spaces or special characters (such as # or $), or is case sensitive, enclose the alias in double quotation marks (" ").
  • 8. Concatenation Operator īŽ Concatenates columns or character strings to other columns īŽ Is represented by two vertical bars (||) īŽ Creates a resultant column that is a character expression īŽ You can link columns to other columns, arithmetic expressions, or constant values to create a character expression by using the concatenation operator (||). īŽ Columns on either side of the operator are combined to make a single output column.
  • 9. Literal Character Strings īŽ A literal is a character, a number, or a date that is included in the SELECT list and that is not a column name or a column alias. īŽ It is printed for each row returned. īŽ Literal strings of free-format text can be included in the query result and are treated the same as a column in the SELECT list. īŽ Date and character literals must be enclosed within single quotation marks (’ ’); number literals need not.
  • 10. Eliminating Duplicate Rows īŽ Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause.
  • 12. Displaying Table Structure īŽ Use the iSQL*Plus DESCRIBE command to display the structure of a table.
  • 13. Chapter - 2 Restricting and Sorting Data Where clause
  • 14. Selection īŽ Restrict the rows returned by using the WHERE clause. īŽ A WHERE clause contains a condition that must be met, and it directly follows the FROM clause. īŽ If the condition is true, the row meeting the condition is returned. īŽ The WHERE clause can compare values in columns, literal values, arithmetic expressions, or functions. īŽ It consists of three elements: īŽ Column name Comparison condition Column name, constant, or list of values īŽ īŽ
  • 15. Character Strings and Dates īŽ Character strings and date values are enclosed in single quotation marks. īŽ Character values are case sensitive, and date values are format sensitive. īŽ The default date format is DD-MON-RR.
  • 16. Comparison Conditions īŽ Comparison conditions are used in conditions that compare one expression to another value or expression. īŽ They are used in the WHERE clause. īŽ An alias cannot be used in the WHERE clause. īŽ Note: The symbol != and ^= can also represent the not equal to condition.
  • 17. Other Comparison Conditions īŽ Use the BETWEEN condition to display rows based on a range of values. īŽ Use the IN membership condition to test for values in a list. īŽ Use the LIKE condition to perform wildcard searches of valid search string values. īŽ Search conditions can contain either literal characters or numbers: % denotes zero or many characters. _ denotes one character. īŽ Test for nulls with the IS NULL operator.
  • 19. Logical Conditions īŽ A logical condition combines the result of two component conditions to produce a single result based on them or inverts the result of a single condition. īŽ A row is returned only if the overall result of the condition is true. īŽ You can use several conditions in one WHERE clause using the AND and OR operators.
  • 22. ORDER BY Clause īŽ Sort rows with the ORDER BY clause ASC: ascending order, default DESC: descending order īŽ The ORDER BY clause comes last in the SELECT statement. īŽ The order of rows returned in a query result is undefined. The ORDER BY clause can be used to sort the rows. īŽ You can specify an expression, or an alias, or column position as the sort condition. īŽ Null values are displayed last for ascending sequences and first for descending sequences.
  • 23. Chapter - 3 Single-Row Functions character, number, and date functions
  • 24. SQL Functions īŽ Perform calculations on data īŽ Modify individual data items īŽ Manipulate output for groups of rows īŽ Format dates and numbers for display īŽ Convert column data types īŽ SQL functions sometimes take arguments and always return a value.
  • 25. Types of SQL Functions Single-Row Functions īŽ These functions operate on single rows only and return one result per row. There are different types of single-row functions. īŽ īŽ īŽ īŽ Character Number Date Conversion Multiple-Row Functions īŽ Functions can manipulate groups of rows to give one result per group of rows. These functions are known as group functions.
  • 27. Case Manipulation Functions LOWER, UPPER, and INITCAP are the three case- conversion functions. īŽ LOWER Converts mixed case or uppercase character strings to lowercase īŽ UPPER Converts mixed case or lowercase character strings to uppercase īŽ INITCAP Converts the first letter of each word to uppercase and remaining letters to lowercase
  • 28. Character-Manipulation Functions īŽ CONCAT Joins values together (You are limited to using two parameters with CONCAT.) īŽ SUBSTR Extracts a string of determined length īŽ LENGTH Shows the length of a string as a numeric value īŽ INSTR Finds numeric position of a named character īŽ LPAD Pads the character value rightjustified īŽ RPAD: Pads the character value leftjustified īŽ TRIM: Trims heading or trailing characters (or both) from a character string
  • 29. Number Functions īŽ ROUND: Rounds value to specified decimal ROUND(45.926, 2) īŽ TRUNC: Truncates value to specified decimal TRUNC(45.926, 2) īŽ 45.93 45.92 MOD: Returns remainder of division MOD(1600, 300) 100
  • 30. ROUND Function īŽ The ROUND function rounds the column, expression, or value to n decimal places. īŽ If the second argument is 0 or is missing, the value is rounded to zero decimal places. īŽ If the second argument is 2, the value is rounded to two decimal places. īŽ Conversely, if the second argument is -2, the value is rounded to two decimal places to the left. TRUNC Function īŽ The TRUNC function works with arguments similar to those of the ROUND function.
  • 31. DUAL Table īŽ The DUAL table is owned by the user SYS and can be accessed by all users. īŽ It contains one column, DUMMY, and one row with the value X. īŽ The DUAL table is useful when you want to return a value once only, for instance, the value of a constant, pseudo column, or expression that is not derived from a table with user data. īŽ The DUAL table is generally used for SELECT clause syntax completeness, because both SELECT and FROM clauses are mandatory, and several calculations do not need to select from actual tables.
  • 32. Working with Dates īŽ The default date display format is DD-MON-RR. īŽ Valid Oracle dates are between January 1, 4712 B.C. and December 31, 9999 A.D. SYSDATE is a function that returns: īŽ īŽ īŽ Date Time SYSDATE is a date function that returns the current database server date and time. You can use SYSDATE just as you would use any other column name.
  • 33. Arithmetic with Dates īŽ Add or subtract a number to or from a date for a resultant date value. īŽ Subtract two dates to find the number of days between those dates. īŽ Add hours to a date by dividing the number of hours by 24.
  • 34. Calculate the number of weeks īŽ The example on the slide displays the last name and the number of weeks employed for all employees in department 90. īŽ It subtracts the date on which the employee was hired from the current date (SYSDATE) and divides the result by 7 to calculate the number of weeks that a worker has been employed.
  • 35. Date Functions īŽ MONTHS_BETWEEN(date1, date2) -The result can be positive or negative. If date1 is later than date2, the result is positive; if date1 is earlier than date2, the result is negative. īŽ ADD_MONTHS (date, n) Adds n number of calendar months to date. īŽ NEXT_DAY (date, 'char') Finds the date of the next specified day of the week ('char') following date. The value of char may be a number representing a day or a character string. īŽ LAST_DAY (date) Finds the date of the last day of the month that contains date. īŽ ROUND (date[,'fmt']) If the format model fmt is omitted, date is rounded to the nearest day. īŽ TRUNC (date[, 'fmt']) If the format model fmt is omitted, date is truncated to the nearest day.
  • 39. Implicit Data Type Conversion
  • 40. Explicit Data Type Conversion
  • 41. Using the TO_CHAR Function with Dates The format model: īŽ Must be enclosed in single quotation marks and is case sensitive īŽ Can include any valid date format element īŽ Has an fm element to remove padded blanks or suppress leading zeros īŽ Is separated from the date value by a comma
  • 42. Elements of the Date Format Model
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. Using the TO_CHAR Function with Numbers These are some of the format elements you can use with the TO_CHAR function to display a number value as a character: