1 Basic SQL Statements
1 Basic SQL Statements
1-2
Capabilities of SQL SELECT Statements
Projection Selection
Table 1 Table 1
Join
Table 1 Table 2
1-3
Basic SELECT Statement
1-4
Selecting All Columns
SELECT *
FROM departments;
1-5
Selecting Specific Columns
1-6
Writing SQL Statements
1-7
Column Heading Defaults
• iSQL*Plus:
– Default heading justification: Center
– Default heading display: Uppercase
• SQL*Plus:
– Character and Date column headings are left-
justified
– Number column headings are right-justified
– Default heading display: Uppercase
1-8
Arithmetic Expressions
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
1-9
Using Arithmetic Operators
1-10
Operator Precedence
_
* / +
• Multiplication and division take priority over
addition and subtraction.
• Operators of the same priority are evaluated from
left to right.
• Parentheses are used to force prioritized
evaluation and to clarify statements.
1-11
Operator Precedence
1-12
Using Parentheses
1-13
Defining a Null Value
1-14
Null Values
in Arithmetic Expressions
1-15
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 is case sensitive
1-16
Using Column Aliases
1-17
Concatenation Operator
A 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
1-18
Using the Concatenation Operator
SELECT
last_name||job_id AS "Employees"
FROM employees;
1-19
Literal Character Strings
1-20
Using Literal Character Strings
1-21
Duplicate Rows
1-22
Eliminating Duplicate Rows
1-23
SQL and iSQL*Plus Interaction
SQL statements
iSQL*Plus Oracle
Internet server
Browser
Formatted report
Client
1-24
SQL Statements Versus
iSQL*Plus Commands
SQL iSQL*Plus
• A language • An environment
• ANSI standard • Oracle proprietary
• Keyword cannot be • Keywords can be
abbreviated abbreviated
• Statements manipulate • Commands do not allow
data and table definitions manipulation of values in
in the database the database
• Runs on a browser
• Centrally loaded, does not
have to be implemented
on each machine
SQL iSQL*Plus
statements commands
1-25
Overview of iSQL*Plus
1-26
Logging In to iSQL*Plus
1-27
The iSQL*Plus Environment
10 8 9
2 3 4 5
1-28
Displaying Table Structure
DESC[RIBE] tablename
1-29
Displaying Table Structure
DESCRIBE employees
1-30
Interacting with Script Files
1-31
Interacting with Script Files
D:\temp\emp_sql.htm
1-32
Interacting with Script Files
DESCRIBE employees
SELECT first_name, last_name, job_id 1
FROM employees;
3 2
1-33
Summary
1-34
Practice 1 Overview
1-35
1-40