SlideShare a Scribd company logo
Copyright © 2004, Oracle. All rights reserved.
Retrieving Data Using
the SQL SELECT Statement
Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to do
the following:
• List the capabilities of SQL SELECT statements
• Execute a basic SELECT statement
• Differentiate between SQL statements and
iSQL*Plus commands
Copyright © 2004, Oracle. All rights reserved.
Capabilities of SQL SELECT Statements
SelectionProjection
Table 1 Table 2
Table 1Table 1
Join
Copyright © 2004, Oracle. All rights reserved.
Basic SELECT Statement
• SELECT identifies the columns to be displayed
• FROM identifies the table containing those columns
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table;
Copyright © 2004, Oracle. All rights reserved.
Selecting All Columns
SELECT *
FROM departments;
Copyright © 2004, Oracle. All rights reserved.
Selecting Specific Columns
SELECT department_id, location_id
FROM departments;
Copyright © 2004, Oracle. All rights reserved.
Writing SQL Statements
• SQL statements are not case-sensitive.
• SQL statements can be on one or more lines.
• Keywords cannot be abbreviated or split
across lines.
• Clauses are usually placed on separate lines.
• Indents are used to enhance readability.
• In iSQL*Plus, SQL statements can optionally be
terminated by a semicolon (;). Semicolons are
required if you execute multiple SQL statements.
• In SQL*plus, you are required to end each SQL
statement with a semicolon (;).
Copyright © 2004, Oracle. All rights reserved.
Column Heading Defaults
• iSQL*Plus:
– Default heading alignment: Center
– Default heading display: Uppercase
• SQL*Plus:
– Character and Date column headings are left-
aligned
– Number column headings are right-aligned
– Default heading display: Uppercase
Copyright © 2004, Oracle. All rights reserved.
Arithmetic Expressions
Create expressions with number and date data by
using arithmetic operators.
Multiply*
Divide/
Subtract-
Add+
DescriptionOperator
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, salary, salary + 300
FROM employees;
Using Arithmetic Operators
…
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, salary, 12*salary+100
FROM employees;
Operator Precedence
SELECT last_name, salary, 12*(salary+100)
FROM employees;
…
…
1
2
Copyright © 2004, Oracle. All rights reserved.
Defining a Null Value
• A null is a value that is unavailable, unassigned,
unknown, or inapplicable.
• A null is not the same as a zero or a blank space.
SELECT last_name, job_id, salary, commission_pct
FROM employees;
…
…
Copyright © 2004, Oracle. All rights reserved.
SELECT last_name, 12*salary*commission_pct
FROM employees;
Null Values
in Arithmetic Expressions
Arithmetic expressions containing a null value
evaluate to null.
…
…
Copyright © 2004, Oracle. All rights reserved.
Defining a Column Alias
A column alias:
• Renames a column heading
• Is useful with calculations
• Immediately follows the column name (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 if it is case-
sensitive
Copyright © 2004, Oracle. All rights reserved.
Using Column Aliases
SELECT last_name "Name" , salary*12 "Annual Salary"
FROM employees;
SELECT last_name AS name, commission_pct comm
FROM employees;
…
…
Copyright © 2004, Oracle. All rights reserved.
Concatenation Operator
A concatenation operator:
• Links columns or character strings to other
columns
• Is represented by two vertical bars (||)
• Creates a resultant column that is a character
expression
SELECT last_name||job_id AS "Employees"
FROM employees;
…
Copyright © 2004, Oracle. All rights reserved.
Literal Character Strings
• A literal is a character, a number, or a date that is
included in the SELECT statement.
• Date and character literal values must be enclosed
by single quotation marks.
• Each character string is output once for each
row returned.
Copyright © 2004, Oracle. All rights reserved.
Using Literal Character Strings
…
SELECT last_name ||' is a '||job_id
AS "Employee Details"
FROM employees;
Copyright © 2004, Oracle. All rights reserved.
Alternative Quote (q) Operator
• Specify your own quotation mark delimiter
• Choose any delimiter
• Increase readability and usability
SELECT department_name ||
q'[, it's assigned Manager Id: ]'
|| manager_id
AS "Department and Manager"
FROM departments;
…
Copyright © 2004, Oracle. All rights reserved.
Duplicate Rows
The default display of queries is all rows, including
duplicate rows.
SELECT department_id
FROM employees;
…
SELECT DISTINCT department_id
FROM employees;
…
1
2
Copyright © 2004, Oracle. All rights reserved.
SQL and iSQL*Plus Interaction
SQL statements
Query resultsiSQL*Plus
commands
Client
Formatted report
Internet
browser
Oracle
server
Copyright © 2004, Oracle. All rights reserved.
SQL Statements Versus
iSQL*Plus Commands
SQL
statements
SQL
• A language
• ANSI standard
• Keyword cannot be
abbreviated
• Statements manipulate
data and table definitions
in the database
iSQL*Plus
• An environment
• Oracle-proprietary
• Keywords can be
abbreviated
• Commands do not allow
manipulation of values in
the database
• Runs on a browser
• Centrally loaded; does not
have to be implemented
on each machine
iSQL*Plus
commands
Copyright © 2004, Oracle. All rights reserved.
Overview of iSQL*Plus
After you log in to iSQL*Plus, you can:
• Describe table structures
• Enter, execute, and edit SQL statements
• Save or append SQL statements to files
• Execute or edit statements that are stored in
saved script files
Copyright © 2004, Oracle. All rights reserved.
Logging In to iSQL*Plus
From your browser environment:
Copyright © 2004, Oracle. All rights reserved.
iSQL*Plus Environment
6
3 4 5
1
2
8 9
7
Copyright © 2004, Oracle. All rights reserved.
Displaying Table Structure
Use the iSQL*Plus DESCRIBE command to display the
structure of a table:
DESC[RIBE] tablename
Copyright © 2004, Oracle. All rights reserved.
Displaying Table Structure
DESCRIBE employees
Copyright © 2004, Oracle. All rights reserved.
Interacting with Script Files
SELECT last_name, hire_date, salary
FROM employees; 1
2
Copyright © 2004, Oracle. All rights reserved.
Interacting with Script Files
Copyright © 2004, Oracle. All rights reserved.
Interacting with Script Files
1
Copyright © 2004, Oracle. All rights reserved.
Interacting with Script Files
2
3
D:TEMPemp_data.sql
Copyright © 2004, Oracle. All rights reserved.
iSQL*Plus History Page
1
2
3
Copyright © 2004, Oracle. All rights reserved.
iSQL*Plus History Page
3
4
Copyright © 2004, Oracle. All rights reserved.
Setting iSQL*Plus Preferences
2
3
1
Copyright © 2004, Oracle. All rights reserved.
Setting the Output Location Preference
1
2
Copyright © 2004, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Write a SELECT statement that:
– Returns all rows and columns from a table
– Returns specified columns from a table
– Uses column aliases to display more descriptive
column headings
• Use the iSQL*Plus environment to write, save, and
execute SQL statements and iSQL*Plus
commands
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table;
Copyright © 2004, Oracle. All rights reserved.
Practice 1: Overview
This practice covers the following topics:
• Selecting all data from different tables
• Describing the structure of tables
• Performing arithmetic calculations and specifying
column names
• Using iSQL*Plus

More Related Content

What's hot

02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
rehaniltifat
 
Oracle sql joins
Oracle sql joinsOracle sql joins
Oracle sql joins
redro
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Achmad Solichin
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)
Achmad Solichin
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
Achmad Solichin
 
Oracle APEX Interactive Grid Essentials
Oracle APEX Interactive Grid EssentialsOracle APEX Interactive Grid Essentials
Oracle APEX Interactive Grid Essentials
Karen Cannell
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Salman Memon
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Oracle sql & plsql
Oracle sql & plsqlOracle sql & plsql
Oracle sql & plsql
Sid Xing
 
Introduction of Oracle
Introduction of Oracle Introduction of Oracle
Introduction of Oracle
Salman Memon
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 
8. sql
8. sql8. sql
8. sql
khoahuy82
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
rehaniltifat
 
11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar
rehaniltifat
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handoutsjhe04
 
Sql oracle
Sql oracleSql oracle
Sql oracle
Md.Abu Noman Shuvo
 
Cursores explicitos
Cursores explicitosCursores explicitos
Cursores explicitos
marvinarevalo83
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Sabana Maharjan
 

What's hot (20)

02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
 
Oracle sql joins
Oracle sql joinsOracle sql joins
Oracle sql joins
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
 
Oracle APEX Interactive Grid Essentials
Oracle APEX Interactive Grid EssentialsOracle APEX Interactive Grid Essentials
Oracle APEX Interactive Grid Essentials
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
 
Sql commands
Sql commandsSql commands
Sql commands
 
Oracle sql & plsql
Oracle sql & plsqlOracle sql & plsql
Oracle sql & plsql
 
Introduction of Oracle
Introduction of Oracle Introduction of Oracle
Introduction of Oracle
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
8. sql
8. sql8. sql
8. sql
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
 
11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Sql oracle
Sql oracleSql oracle
Sql oracle
 
Cursores explicitos
Cursores explicitosCursores explicitos
Cursores explicitos
 
plsql Les08
plsql Les08 plsql Les08
plsql Les08
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 

Viewers also liked

Pure and Hybrid Seed Production
Pure and Hybrid Seed ProductionPure and Hybrid Seed Production
Pure and Hybrid Seed Production
Junaid Abbas
 
Oracle forms les01
Oracle forms  les01Oracle forms  les01
Oracle forms les01Abed Othman
 
Oracle 11g PL/SQL notes
Oracle 11g PL/SQL notesOracle 11g PL/SQL notes
Oracle 11g PL/SQL notes
anilakduygu
 
Quality seed production in maize hybrids
Quality seed production in maize hybridsQuality seed production in maize hybrids
Quality seed production in maize hybridsjesuslovesu
 
Hybrid seed production and male sterility in maize
Hybrid seed production and male sterility  in maizeHybrid seed production and male sterility  in maize
Hybrid seed production and male sterility in maizemegha25887
 
Maize
MaizeMaize
Hybrid Seed Production Technology of Maize
Hybrid Seed Production Technology of MaizeHybrid Seed Production Technology of Maize
Hybrid Seed Production Technology of Maize
Mohammad Safar Noori
 

Viewers also liked (7)

Pure and Hybrid Seed Production
Pure and Hybrid Seed ProductionPure and Hybrid Seed Production
Pure and Hybrid Seed Production
 
Oracle forms les01
Oracle forms  les01Oracle forms  les01
Oracle forms les01
 
Oracle 11g PL/SQL notes
Oracle 11g PL/SQL notesOracle 11g PL/SQL notes
Oracle 11g PL/SQL notes
 
Quality seed production in maize hybrids
Quality seed production in maize hybridsQuality seed production in maize hybrids
Quality seed production in maize hybrids
 
Hybrid seed production and male sterility in maize
Hybrid seed production and male sterility  in maizeHybrid seed production and male sterility  in maize
Hybrid seed production and male sterility in maize
 
Maize
MaizeMaize
Maize
 
Hybrid Seed Production Technology of Maize
Hybrid Seed Production Technology of MaizeHybrid Seed Production Technology of Maize
Hybrid Seed Production Technology of Maize
 

Similar to Les01

Database Management Systems SQL And DDL language
Database Management Systems SQL And DDL languageDatabase Management Systems SQL And DDL language
Database Management Systems SQL And DDL language
HSibghatUllah
 
Les01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.pptLes01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.ppt
DrZeeshanBhatti
 
SQL, consultas rapidas y sencillas, oracle
SQL, consultas rapidas y sencillas, oracleSQL, consultas rapidas y sencillas, oracle
SQL, consultas rapidas y sencillas, oracle
marycielocartagena73
 
Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句
renguzi
 
SQL SELECT Statement
 SQL SELECT Statement SQL SELECT Statement
SQL SELECT Statement
IslamicUniversityofL
 
Less07 schema
Less07 schemaLess07 schema
Less07 schemaImran Ali
 
plsql les01
 plsql les01 plsql les01
plsql les01
sasa_eldoby
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
bunny0143
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Les08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*PlusLes08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*Plus
siavosh kaviani
 
plsql les02
 plsql les02 plsql les02
plsql les02
sasa_eldoby
 
Les01
Les01Les01

Similar to Les01 (20)

Les01
Les01Les01
Les01
 
Database Management Systems SQL And DDL language
Database Management Systems SQL And DDL languageDatabase Management Systems SQL And DDL language
Database Management Systems SQL And DDL language
 
Les01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.pptLes01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.ppt
 
SQL, consultas rapidas y sencillas, oracle
SQL, consultas rapidas y sencillas, oracleSQL, consultas rapidas y sencillas, oracle
SQL, consultas rapidas y sencillas, oracle
 
Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句
 
Les10
Les10Les10
Les10
 
Les05
Les05Les05
Les05
 
SQL SELECT Statement
 SQL SELECT Statement SQL SELECT Statement
SQL SELECT Statement
 
Less07 schema
Less07 schemaLess07 schema
Less07 schema
 
plsql les01
 plsql les01 plsql les01
plsql les01
 
Les03
Les03Les03
Les03
 
Les09
Les09Les09
Les09
 
Les06
Les06Les06
Les06
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
 
Les07
Les07Les07
Les07
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Les08
Les08Les08
Les08
 
Les08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*PlusLes08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*Plus
 
plsql les02
 plsql les02 plsql les02
plsql les02
 
Les01
Les01Les01
Les01
 

More from Abrianto Nugraha

Ds sn is-02
Ds sn is-02Ds sn is-02
Ds sn is-02
Abrianto Nugraha
 
Ds sn is-01
Ds sn is-01Ds sn is-01
Ds sn is-01
Abrianto Nugraha
 
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkapPertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Abrianto Nugraha
 
04 pemodelan spk
04 pemodelan spk04 pemodelan spk
04 pemodelan spk
Abrianto Nugraha
 
02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised
Abrianto Nugraha
 
01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan
Abrianto Nugraha
 
Pertemuan 7
Pertemuan 7Pertemuan 7
Pertemuan 7
Abrianto Nugraha
 
Pertemuan 7 dan_8
Pertemuan 7 dan_8Pertemuan 7 dan_8
Pertemuan 7 dan_8
Abrianto Nugraha
 
Pertemuan 5
Pertemuan 5Pertemuan 5
Pertemuan 5
Abrianto Nugraha
 
Pertemuan 6
Pertemuan 6Pertemuan 6
Pertemuan 6
Abrianto Nugraha
 
Pertemuan 4
Pertemuan 4Pertemuan 4
Pertemuan 4
Abrianto Nugraha
 
Pertemuan 3
Pertemuan 3Pertemuan 3
Pertemuan 3
Abrianto Nugraha
 
Pertemuan 2
Pertemuan 2Pertemuan 2
Pertemuan 2
Abrianto Nugraha
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
Abrianto Nugraha
 
Modul 1 mengambil nilai parameter
Modul 1   mengambil nilai parameterModul 1   mengambil nilai parameter
Modul 1 mengambil nilai parameter
Abrianto Nugraha
 
Modul 3 object oriented programming dalam php
Modul 3   object oriented programming dalam phpModul 3   object oriented programming dalam php
Modul 3 object oriented programming dalam php
Abrianto Nugraha
 
Modul 2 menyimpan ke database
Modul 2  menyimpan ke databaseModul 2  menyimpan ke database
Modul 2 menyimpan ke database
Abrianto Nugraha
 

More from Abrianto Nugraha (20)

Ds sn is-02
Ds sn is-02Ds sn is-02
Ds sn is-02
 
Ds sn is-01
Ds sn is-01Ds sn is-01
Ds sn is-01
 
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkapPertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
Pertemuan 5 optimasi_dengan_alternatif_terbatas_-_lengkap
 
04 pemodelan spk
04 pemodelan spk04 pemodelan spk
04 pemodelan spk
 
02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised02 sistem pengambilan-keputusan_revised
02 sistem pengambilan-keputusan_revised
 
01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan01 pengantar sistem-pendukung_keputusan
01 pengantar sistem-pendukung_keputusan
 
Pertemuan 7
Pertemuan 7Pertemuan 7
Pertemuan 7
 
Pertemuan 7 dan_8
Pertemuan 7 dan_8Pertemuan 7 dan_8
Pertemuan 7 dan_8
 
Pertemuan 5
Pertemuan 5Pertemuan 5
Pertemuan 5
 
Pertemuan 6
Pertemuan 6Pertemuan 6
Pertemuan 6
 
Pertemuan 4
Pertemuan 4Pertemuan 4
Pertemuan 4
 
Pertemuan 3
Pertemuan 3Pertemuan 3
Pertemuan 3
 
Pertemuan 2
Pertemuan 2Pertemuan 2
Pertemuan 2
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
 
Modul 1 mengambil nilai parameter
Modul 1   mengambil nilai parameterModul 1   mengambil nilai parameter
Modul 1 mengambil nilai parameter
 
Modul 3 object oriented programming dalam php
Modul 3   object oriented programming dalam phpModul 3   object oriented programming dalam php
Modul 3 object oriented programming dalam php
 
Modul 2 menyimpan ke database
Modul 2  menyimpan ke databaseModul 2  menyimpan ke database
Modul 2 menyimpan ke database
 
Pbo 7
Pbo 7Pbo 7
Pbo 7
 
Pbo 6
Pbo 6Pbo 6
Pbo 6
 
Pbo 4
Pbo 4Pbo 4
Pbo 4
 

Recently uploaded

Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

Les01

  • 1. Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement
  • 2. Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: • List the capabilities of SQL SELECT statements • Execute a basic SELECT statement • Differentiate between SQL statements and iSQL*Plus commands
  • 3. Copyright © 2004, Oracle. All rights reserved. Capabilities of SQL SELECT Statements SelectionProjection Table 1 Table 2 Table 1Table 1 Join
  • 4. Copyright © 2004, Oracle. All rights reserved. Basic SELECT Statement • SELECT identifies the columns to be displayed • FROM identifies the table containing those columns SELECT *|{[DISTINCT] column|expression [alias],...} FROM table;
  • 5. Copyright © 2004, Oracle. All rights reserved. Selecting All Columns SELECT * FROM departments;
  • 6. Copyright © 2004, Oracle. All rights reserved. Selecting Specific Columns SELECT department_id, location_id FROM departments;
  • 7. Copyright © 2004, Oracle. All rights reserved. Writing SQL Statements • SQL statements are not case-sensitive. • SQL statements can be on one or more lines. • Keywords cannot be abbreviated or split across lines. • Clauses are usually placed on separate lines. • Indents are used to enhance readability. • In iSQL*Plus, SQL statements can optionally be terminated by a semicolon (;). Semicolons are required if you execute multiple SQL statements. • In SQL*plus, you are required to end each SQL statement with a semicolon (;).
  • 8. Copyright © 2004, Oracle. All rights reserved. Column Heading Defaults • iSQL*Plus: – Default heading alignment: Center – Default heading display: Uppercase • SQL*Plus: – Character and Date column headings are left- aligned – Number column headings are right-aligned – Default heading display: Uppercase
  • 9. Copyright © 2004, Oracle. All rights reserved. Arithmetic Expressions Create expressions with number and date data by using arithmetic operators. Multiply* Divide/ Subtract- Add+ DescriptionOperator
  • 10. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, salary, salary + 300 FROM employees; Using Arithmetic Operators …
  • 11. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, salary, 12*salary+100 FROM employees; Operator Precedence SELECT last_name, salary, 12*(salary+100) FROM employees; … … 1 2
  • 12. Copyright © 2004, Oracle. All rights reserved. Defining a Null Value • A null is a value that is unavailable, unassigned, unknown, or inapplicable. • A null is not the same as a zero or a blank space. SELECT last_name, job_id, salary, commission_pct FROM employees; … …
  • 13. Copyright © 2004, Oracle. All rights reserved. SELECT last_name, 12*salary*commission_pct FROM employees; Null Values in Arithmetic Expressions Arithmetic expressions containing a null value evaluate to null. … …
  • 14. Copyright © 2004, Oracle. All rights reserved. Defining a Column Alias A column alias: • Renames a column heading • Is useful with calculations • Immediately follows the column name (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 if it is case- sensitive
  • 15. Copyright © 2004, Oracle. All rights reserved. Using Column Aliases SELECT last_name "Name" , salary*12 "Annual Salary" FROM employees; SELECT last_name AS name, commission_pct comm FROM employees; … …
  • 16. Copyright © 2004, Oracle. All rights reserved. Concatenation Operator A concatenation operator: • Links columns or character strings to other columns • Is represented by two vertical bars (||) • Creates a resultant column that is a character expression SELECT last_name||job_id AS "Employees" FROM employees; …
  • 17. Copyright © 2004, Oracle. All rights reserved. Literal Character Strings • A literal is a character, a number, or a date that is included in the SELECT statement. • Date and character literal values must be enclosed by single quotation marks. • Each character string is output once for each row returned.
  • 18. Copyright © 2004, Oracle. All rights reserved. Using Literal Character Strings … SELECT last_name ||' is a '||job_id AS "Employee Details" FROM employees;
  • 19. Copyright © 2004, Oracle. All rights reserved. Alternative Quote (q) Operator • Specify your own quotation mark delimiter • Choose any delimiter • Increase readability and usability SELECT department_name || q'[, it's assigned Manager Id: ]' || manager_id AS "Department and Manager" FROM departments; …
  • 20. Copyright © 2004, Oracle. All rights reserved. Duplicate Rows The default display of queries is all rows, including duplicate rows. SELECT department_id FROM employees; … SELECT DISTINCT department_id FROM employees; … 1 2
  • 21. Copyright © 2004, Oracle. All rights reserved. SQL and iSQL*Plus Interaction SQL statements Query resultsiSQL*Plus commands Client Formatted report Internet browser Oracle server
  • 22. Copyright © 2004, Oracle. All rights reserved. SQL Statements Versus iSQL*Plus Commands SQL statements SQL • A language • ANSI standard • Keyword cannot be abbreviated • Statements manipulate data and table definitions in the database iSQL*Plus • An environment • Oracle-proprietary • Keywords can be abbreviated • Commands do not allow manipulation of values in the database • Runs on a browser • Centrally loaded; does not have to be implemented on each machine iSQL*Plus commands
  • 23. Copyright © 2004, Oracle. All rights reserved. Overview of iSQL*Plus After you log in to iSQL*Plus, you can: • Describe table structures • Enter, execute, and edit SQL statements • Save or append SQL statements to files • Execute or edit statements that are stored in saved script files
  • 24. Copyright © 2004, Oracle. All rights reserved. Logging In to iSQL*Plus From your browser environment:
  • 25. Copyright © 2004, Oracle. All rights reserved. iSQL*Plus Environment 6 3 4 5 1 2 8 9 7
  • 26. Copyright © 2004, Oracle. All rights reserved. Displaying Table Structure Use the iSQL*Plus DESCRIBE command to display the structure of a table: DESC[RIBE] tablename
  • 27. Copyright © 2004, Oracle. All rights reserved. Displaying Table Structure DESCRIBE employees
  • 28. Copyright © 2004, Oracle. All rights reserved. Interacting with Script Files SELECT last_name, hire_date, salary FROM employees; 1 2
  • 29. Copyright © 2004, Oracle. All rights reserved. Interacting with Script Files
  • 30. Copyright © 2004, Oracle. All rights reserved. Interacting with Script Files 1
  • 31. Copyright © 2004, Oracle. All rights reserved. Interacting with Script Files 2 3 D:TEMPemp_data.sql
  • 32. Copyright © 2004, Oracle. All rights reserved. iSQL*Plus History Page 1 2 3
  • 33. Copyright © 2004, Oracle. All rights reserved. iSQL*Plus History Page 3 4
  • 34. Copyright © 2004, Oracle. All rights reserved. Setting iSQL*Plus Preferences 2 3 1
  • 35. Copyright © 2004, Oracle. All rights reserved. Setting the Output Location Preference 1 2
  • 36. Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: • Write a SELECT statement that: – Returns all rows and columns from a table – Returns specified columns from a table – Uses column aliases to display more descriptive column headings • Use the iSQL*Plus environment to write, save, and execute SQL statements and iSQL*Plus commands SELECT *|{[DISTINCT] column|expression [alias],...} FROM table;
  • 37. Copyright © 2004, Oracle. All rights reserved. Practice 1: Overview This practice covers the following topics: • Selecting all data from different tables • Describing the structure of tables • Performing arithmetic calculations and specifying column names • Using iSQL*Plus