October 1999
Instructor Guide for
Introduction to Oracle:
SQL and PL/SQL
Author
Priya Nathan
Copyright ” Oracle Corporation, 1999. All rights reserved.
This documentation contains proprietary information of Oracle Corporation. It is
provided under a license agreement containing restrictions on use and disclosure
and is also protected by copyright law. Reverse engineering of the software is
prohibited. If this documentation is delivered to a U.S. Government Agency of the
Department of Defense, then it is delivered with Restricted Rights and the
following legend is applicable:
Restricted Rights Legend
Use, duplication or disclosure by the Government is subject to restrictions for
commercial computer software and shall be deemed to be Restricted Rights
software under Federal law, as set forth in subparagraph (c) (1) (ii) of DFARS
252.227-7013, Rights in Technical Data and Computer Software (October 1988).
This material or any portion of it may not be copied in any form or by any means
without the express prior written permission of Oracle Corporation. Any other
copying is a violation of copyright law and may result in civil and/or criminal
penalties.
If this documentation is delivered to a U.S. Government Agency not within the
Department of Defense, then it is delivered with “Restricted Rights,” as defined in
FAR 52.227-14, Rights in Data-General, including Alternate III (June 1987).
The information in this document is subject to change without notice. If you find
any problems in the documentation, please report them in writing to Education
Products, Oracle Corporation, 500 Oracle Parkway, Box SB-6, Redwood Shores,
CA 94065. Oracle Corporation does not warrant that this document is error-free.
Oracle is a registered trademark of Oracle Corporation.
All other products or company names are used for identification purposes only
and may be trademarks of their respective owners.
Oracle Education Products 3
Introduction
Introduction
Introduction to Oracle: SQL and PL/SQL is often the first course that many Oracle students
attend. You might be their first contact with any Oracle personnel.
At the same time, this may be one of the first courses that you teach as an Oracle instructor, so
you might appreciate some help in achieving the best performance possible at an early stage of
your career.
The tools and tips in this section come from the highly recommended AIT (Advanced
Instructional Techniques) class, which many Oracle Educaton instructors have attended. If
you attend that class, you will learn all that is here—and much more.
Aim of This Document
• To help you make this the best technical course that students have ever attended, to excite
them to learn, and to make them want to come back for more
• To give you some tips and techniques to help you vary your lecture style, avoid monotony
in classes, and make the learning experience more entertaining and interesting for both the
students and yourself
This document is not a substitute for your own personal training and delivery instructions that
you receive from your Education department.
Using This Document
None of these suggestions and techniques are mandatory. They are simply examples of how to
introduce variety and change of pace into your classes.
Not all techniques suit all instructors. Choose those with which you feel most comfortable. If
possible, test the techniques with a fellow instructor who is also eager to encourage interactive
learning in the classroom.
4 Oracle Education Products
The Learning Environment
Introduction
Establish a pleasant and effective learning environment at the start of a class.
Tips to Improve the Class Climate
When students first arrive at a course, they have doubts, concerns, and fears. To change these
negative feelings to positive ones, try to make students feel welcome, safe, comfortable,
important, competent, understood, and responsible. Think carefully about what you can say
and do to foster these feelings of comfort and familiarity in your students, especially in the
first 30 minutes of the course.
Students learn more effectively in a physically and emotionally comfortable environment.
Early Arrivals
Some students arrive early for class. Do not ignore these students—welcome them with a
smile. Make them feel comfortable by introducing yourself and providing details about the
class and the environment.
Housekeeping
Explaining the “housekeeping” ground rules at the start of a class is very important to make
students feel comfortable and confident in their surroundings. Remember to explain some of
the following points:
• Layout of building: Point out the location of restrooms, refreshments, and so on.
• Timing of class: State the start and end times and lunchtime.
• Questions: Encourage students to ask questions during the class.
Personal Introductions
Allowing time for students to introduce themselves is important for you and for them. When
you know that course timings are tight, it is very tempting to reduce time allowed for
introductions or skip them altogether, but you do so at your peril. Introductions help foster a
good relationship between all the students.
Use introductions to find out more about your audience: those who might not have sufficient
prerequisite knowledge, those who might cause problems because they are eager to prove
themselves in front of others, and so on.
Thought for the Day
Never do for the learners what they can do for themselves.
Efficient Use of Icebreakers
You can use icebreakers successfully throughout the course.
• At the beginning of a class: Choose something that helps students get to know others in the
class.
Oracle Education Products 5
The Learning Environment
• After break times: Occupy and entertain those who return early from breaks.
• Afternoon: Avoid the graveyard-shift syndrome. Give students a short, light activity to
refresh them after lunch or in the late afternoon.
Icebreakers to Use in Class Introductions
You can vary your class introductions with either of these icebreakers:
Partner Introductions
• Ask each person to select a partner who is a stranger to them.
• Give ten minutes for partners to interview each other and find out as much as possible
about each other.
• Suggest that they take notes during their interviews.
• After the interviews, ask each person to stand in turn and introduce their partner to the
entire group (encourage them to refer to their notes).
Note: This icebreaker works best with smaller groups (fewer than 20). For larger groups,
it is too time-consuming.
Icebreakers for After-Lunch Activity
Try using one of these to wake up the group after lunch:
Common Ground
Use this icebreaker for small groups or for each small group sitting together as a team
(example: four to six people).
• Give the groups a specific time (example: five minutes) to list everything they can find
that they all have in common. Tell them to avoid the obvious (example: “we are all taking
this workshop”). Ask them to make a list.
• After the time is up, ask each group how many items they have in their list.
• For fun, ask them to announce some of the most interesting items in their lists.
Dreams and Nightmares
• Each person states a dream about something positive that they hope will happen in this
course.
• Each person states a nightmare about something negative that they hope will not happen in
this course.
• Put the dreams and nightmares on a flip chart so all groups can read them.
Notice that most of these icebreakers are brief exercises that focus on getting to know the
people they will work with. If groups are changed regularly, start each session with a different
icebreaker.
6 Oracle Education Products
Lecture Styles
Keywords
• As you speak, write keywords on a flip chart to create an emerging content outline.
• When you fill a page, tape it to the wall and start a new one on the flipchart.
• Put no more than seven keywords on a page.
• When finished, ask the students to review by recalling the content that is triggered by each
keyword. The review can be an individual exercise or it can be done through discussion in
small groups.
Cartoon Lecture
• Find cartoons that relate to the content of your lecture. Transfer the cartoons onto
overhead transparencies.
• For each key point in the lecture, show the cartoon after you have described the content
verbally.
• When the lecture is finished, show each cartoon again and have the students review the
content using the cartoon as a mental trigger. The review can be an individual exercise or
it can be done through discussion in groups.
The mind is like the stomach. It’s not how much you put into it that counts, but how much it
digests.
Examples and Exceptions
• Good lectures often contain examples, analogies, and metaphors.
• As you deliver a lecture, ask students in small groups to create an example or analogy of
the point you are describing.
• For a change of pace, ask them to create exceptions to the point.
• Encourage learners to use situations from their own experience as the source for examples,
where possible.
Fill in the Blank
• Design a printed outline of the key ideas to be covered in the lecture.
• Leave out a word or short phrase in each item in the outline.
• As you lecture, ask students to fill in the missing words.
Before I speak, I have something important to say. Groucho Marx
Search and Learn
• Rather than deliver a lecture, put the content in printed form. Use headings and bullets
rather than paragraphs.
• Give learners a series of questions to answer by searching through the printed material. If
you want a competitive element, have small groups search quickly for the answer. The
group that finds it first raises their hands and announces the location of the answer. If they
Oracle Education Products 7
Lecture Styles
are correct, they receive a point. At the end, you could have a prize for the winning group.
Forming Effective Questions
The following points will help you to make your questioning more effective:
• Employ the characteristics of a good question:
– Concise and contains only one idea
– Thought provoking and interesting
– Focused on important material
– Open-ended (requires more than a “yes” or “no” answer)
– Requires reasoning rather than memory
– Challenging but answerable
• Four directions for questions:
– Direct: Ask a specific student.
– Overhead: Ask the students in general; anyone can answer.
– Relay: Ask someone else to answer a student’s question.
– Reverse: Mirror a student’s question back to the same student.
• Do not repeat students’ answers. Otherwise, students may stop listening to each other.
• Use “crossfire” questioning. Refer questions to others, such as:
– “How would you have answered that?”
– “Why do you think that?”
– “What do you think of that answer?”
– “What evidence do you have for that?”
• When answering a question, use these techniques:
– When someone asks you a question, smile, take a step toward them, and say “yes” as
if you are pleased to have a question.
– Check to be sure everyone heard and understood the question.
– Answer briefly and state reasons for your answer.
– Tie your answer to key points in your lesson, if possible.
– If you do not know an answer, admit it—never bluff. Ask if anyone else knows the
answer. If no one does, offer to find out.
– If someone asks a contentious question, give a direct and friendly answer. Do not be
provoked into a defensive position.
– If someone asks a question that you will be covering later, say “That’s a good
question. We will be covering that in a few minutes.”
8 Oracle Education Products
Bibliography
Eitlington, Julius. The Winning Trainer. Gulf Publishing, 1984.
Forbess-Green, Sue. Encyclopedia of Icebreakers. University Associates, 1990.
Jones, Philip (ed.). Adult Learning in Your Classroom. Lakewood Publications,
1982.
Newstrom, John, and Edward Scannell. Games Trainers Play. McGraw-Hill, 1980.
O’Connor, Joseph, and John Seymour. Introducing Neuro-Linguistic
Programming. Thorsons, 1995.
O’Connor, Joseph, and John Seymour. Training with NLP. Thorsons, 1994.
Pike, Robert. Creative Training Techniques Handbook. Lakewood Publications,
1989.
Scannell, Edward, and John Newstrom. More Games Trainers Play. McGraw-Hill,
1991.
Oracle Education Products 9
About the Course
About the Course
Lesson Objectives and Aims
Each lesson starts with an objectives page that describes the reasons for the lesson; there is
also an objectives slide that should be used. The intention of each lesson should be clear to
everyone—lecturer and students—at the start of every lesson.
The topics covered in each lesson should give students enough information to complete the
required part of each practice.
Lesson Timings
If a lesson drags on, for whatever reason (yes there will be those exceptions) then break the
lesson for five minutes. Give everyone a rest.
Practices
Practices are as important as the lesson. Practice timings are usually the same as or more than
the lecture time allowance, to ensure that the students get as much exposure to the product as
possible.
The "If you have time" questions are there for those who need a challenge; for example, for
students who already have SQL knowledge or are finding the subject easy. What questions
students are expected to complete is made clear in the table at the start of each practice.
Enforcing Learning Points
Consider the following ideas when teaching:
• Always use the lesson objectives slide to stress the intention of the lesson, and use the
summary slide to reiterate learning points.
• Invite student questions at all times.
• At the start of a new day, spend 5 minutes of your time to remind students of the topics
covered the previous day. No detail is required, this is just a memory-jogging session.
• Do not discuss syntax slides word-for-word. Identify and discuss the main learning points.
In most cases, students have an opportunity to use the syntax during the practices.
Practice Sessions
Some practices, contain "if you want extra challenge" questions. Let the student do these only
if you they have completed all of the other questions within the allocated time and would like
a further challenge to their skills.
Demonstrations
Do not show slides and demonstrate for each slide; use demonstrations to stress learning
points:
• There is not enough time.
• Students get bored watching the lecturer doing all the work and having all the fun, it
10 Oracle Education Products
seems, when they are itching to get their hands on the product.
• You can use the Class Management Notes to assist you when teaching the courses. This
document has been constructed to try to help instructors identify what the main learning
points are for any lesson.
• You can present the course without any demonstration at all.
Interaction
Ensure the students are aware that the course is interactive. As much as you are there to teach,
the students are there to understand, assimilate, and experiment. If they do not understand
anything that is presented, they should ask questions. Students should not be afraid to ask
questions, or be worried as to whether the questions are relevant. Of course some questions
may be beyond the scope of the course (if that is the case, say so) or beyond the scope of your
knowledge.
Appendixes and Answers
Clearly identify which appendixes are available and where to find them in the manual and
specifically where to find the practice demostrate tables and practice solutions.
Snippets
This course includes animation and activity snippets. A description of these snippets can be
found in Snipdesc.doc along with the other lessons for this course.
Structure of the Instructor Guide
Element Description
Additional information Additional information that the instructor can
share in class
Hint A hint to the instructor with specific reference to
the slide
Additional example An additional example to explain in class
Additional reference Where the instructor can look up additional
information related to the subject of the slide
Oracle Education Products 11
Introduction
Introduction
Additional Information
If time permits, share the following
information with the class. Structured
systems analysis and design helps in
understanding and designing a system,
which will be programmed later in any
programming language. It is the stepping
stone in creating simple or large, critical-
mission, complex systems. During this
stage, you will learn how to put down on
paper a large, complex system in a short
and understandable manner that can be
understood by any lay person.
Beginning with strategy and analysis, the
project team’s objective is to identify the
high-level requirements and develop a
conceptual scope of work. This
information is used to develop the
preliminary cost and time requirements. It
also serves as the foundation for the
remaining phases.
The design phase facilitates the design of
all system components. This includes the
user interface, database model, report
layout, business rules, systems interfacing,
and documentation. In essence, the project
team creates the blueprints for the
development of the system.
Prototyping may be performed to help
facilitate the design and transition phases
and ensure the validity of business rules,
determine the feasibility of technical
options, and help to expose the value of
the comprehensive information
management system.
System Development Life Cycle
Strategy
and
Analysis
Design
Build
and
Document
Transition
Production
12 Oracle Education Products
(continued) Transition is the process of applying
technology, skill, and development
standards to the design specifications.
Testing involves the validation of all
system components to ensure that the
product operates and performans in
accordance with the design specifications.
QA audits, client reviews, quality
certification, implementation planning,
installation, setup, and training are
included in the production and rollout
phase.
A flexible support and maintenance plan
may include phone support,
troubleshooting, planned upgrades, and
enhancements.
Additional Information
If time permits, share the following
information with the class. A relational set
is often modeled as a table. The items of a
set are the rows of the table. The fields in
the items are the columns. The columns in
a table can have names. The rows are
unordered and unnamed. A database
consists of one or more tables plus a
catalog (also represented by tables)
describing the database.
Relational Database Concept
• Dr. E. F. Codd proposed the relational model
for database systems in 1970.
• It is the basis for the relational database
management system (RDBMS).
• The relational model consists of the following:
– Collection of objects or relations
– Set of operators to act on the relations
– Data integrity for accuracy and consistency
Oracle Education Products 13
Introduction
Additional Information
If time permits, share the following
information with the class. The relational
model presents an orderly, predictable,
and intuitive approach to organizing,
manipulating, and viewing data.
Relational tables have six properties,
which must be satisfied for any table to be
classified as relational. These are:
• Entries of attributes are single-valued.
Entries in every row and column
position in a table must be single-
valued. This means columns do not
contain repeating groups.
• Entries of attributes are of the same
kind.
Entries in a column must be of the
same kind. For example, a column
that stores salary information should
not be used to store commission
information.
• No two rows are identical.
Each row should be unique. This
uniqueness is ensured by the values in
a specific set of columns called the
primary key.
• The order of attributes is unimportant.
There is no significance attached to
the order in which columns are stored
in the table. A user can retrieve
columns in any order.
• The order of rows is unimportant.
There is no significance attached to
the order in which rows are stored in
the table. A user can retrieve rows in
any order.
• Every column can be uniquely
identified.
Each column is identified by its name
and not its position. A column name
should be unique in the table.
Definition of a
Relational Database
A relational database is a collection of
relations or two-dimensional tables.
Database
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Table Name: DEPT
EMPNO ENAME JOB DEPTNO
7839 KING PRESIDENT 10
7698 BLAKE MANAGER 30
7782 CLARK MANAGER 10
7566 JONES MANAGER 20
EMPNO ENAME JOB DEPTNO
7839 KING PRESIDENT 10
7698 BLAKE MANAGER 30
7782 CLARK MANAGER 10
7566 JONES MANAGER 20
Table Name: EMP
14 Oracle Education Products
Additional Reference
/>lodewyck/4720/ERModel/index.htm
/>Chap3/index.htm
/>Phoenix3/index.htm
• Create an entity relationship diagram from
business specifications or narratives
• Scenario
– “. . . Assign one or more employees to a
department . . .”
– “. . . Some departments do not yet have
assigned employees . . .”
Entity Relationship Model
EMPLOYEE
#* number
*name
o job title
EMPLOYEE
#* number
*name
o job title
DEPARTMENT
#* number
*name
olocation
DEPARTMENT
#* number
*name
olocation
assigned to
composed of
Oracle Education Products 15
Introduction
Additional Information
If time permits, share the following
information with the class. Object
orientation is the use of objects and classes
in analysis, design, and programming. The
use of objects distinguishes object
orientation from other techniques such as
traditional structured methods (process-
based: data and function are separate) or
other techniques such as knowledge-based
systems (logic programming, rules:
Prolog) or mathematical methods.
Object orientation is:
View Of The World - A Better
Approach
Process
Iterative/Incremental - Easy to add to
systems
Methods
Analysis
Design
Implementation
Languages
Programming Technique
Object-oriented programming languages
provide full support for object design.
Additional Reference
erdyne-object-
sys.com/oofaq2/
Oracle8: Object Relational
Database Management System
• User-defined data types and objects
• Fully compatible with relational
database
• Support of multimedia and large objects
• High-quality database server features
16 Oracle Education Products
Additional Reference
erdyne-object-
sys.com/oofaq2/
Data Models
Model of
system
in client’s
mind
Entity model of
client’s model
Table model
of entity model
Tables on disk
Server
Oracle Education Products 17
Introduction
Additional Information
If time permits, share this information
with the class. PL/SQL is the procedural
extension to SQL, provided by Oracle.
Through PL/SQL, the data manipulation
capabilities of SQL are combined with the
processing capabilities of a procedural
language. PL/SQL provides features like
conditional execution, looping, and
branching. PL/SQL supports subroutines
too. The basic unit in any PL/SQL
program is a block, which can occur
sequentially (one after the other) or nested
(one inside the other). Using PL/SQL you
can write subprograms, procedures,
packages, and functions that are stored in
the database.
Hint
One of the ways of introducing PL/SQL to the class is by explaining the capabilities that
SQL lacks and how PL/SQL serves as an extension to SQL. The objective of this slide is to
highlight that PL/SQL combines the data manipulating power of SQL with the data
processing power of procedural languages.
The Problem: SQL is the most powerful and comprehensive database language, that enables
you to create, organize, retrieve and maintain data stored in a database. But it does not
provide the features which a typical programming language offers, such as control-of-flow
constructs (sequence, selection and iteration constructs), or the facility to define and use
variables. SQL has a more set based approach. It returns a set of rows after a query is
executed.
The Solution: The solution is PL/SQL, which is a language that has the programming
features that SQL lacks. It provides control-of-flow constructs and lets you declare and use
variables. PL/SQL gives the flexibility of row-wise access to the records in the underlying
table.
Additional Reference
/>01_oview.htm#651
About PL/SQL
• PL/SQL is an extension to SQL with
design features of programming
languages.
• Data manipulation and query statements
of SQL are included within procedural
units of code.
18 Oracle Education Products
Hint
Draw attention to the fact that PL/SQL can
reside in two environments:
• The Oracle Server
• Oracle Tools
Explain the diagram on the slide as
follows: The diagram shows the PL/SQL
engine processing an anonymous block.
The engine executes procedural
statements but sends SQL statements to
the SQL statement executor in the Oracle
server.
Additional Reference
/>8.0/815/server.815/a67842/
01_oview.htm#962
PL/SQL Environment
PL/SQL
block
PL/SQL engine
Oracle Server
Procedural
Statement
Executor
PL/SQL
SQL
SQL Statement Executor
PL/SQL
block
Oracle Education Products 19
Lesson 1: Writing Basic Select Statements
Lesson 1: Writing Basic Select Statements
Additional Information
Explain that selection retrieves only
selected rows, projection retrieves only
selected columns and joins can retrieve
rows, columns, or both depending on the
SELECT clause.
Hint
If time permits, you can include the
explanation of other relational operators
like PRODUCT, INTERSECTION, and
DIFFERENCE.
PRODUCT: the result of a query that
concatenates rows from two sets of data.
All rows in the first set are concatenated
with all rows in the second set, often
producing a very large new set.
INTERSECTION: displays all rows that
appear in both of two relations.
DIFFERENCE: displays rows that appear
in one relation only. (SQL uses operator
minus.)
Hint
Explain that all clauses mentioned within
[ ] are optional. Also mention that other
clauses like GROUP BY and ORDER BY
are also part of a SELECT statement and
will be explained in the later lessons.
Capabilities of SQL SELECT
Statements
Selection
Projection
Table 1
Table 2
Table 1
Table 1
Join
Basic SELECT Statement
SELECT [DISTINCT] {*,
column
[
alias
], }
FROM
table;
SELECT [DISTINCT] {*,
column
[
alias
], }
FROM
table;
• SELECT identifies
what
columns.
• FROM identifies
which
table.
20 Oracle Education Products
Hint
Point out that using tabs and indents, and
placing different clauses on separate lines
I increases readability of the SQL
statement.
Hint
Revisit slide 4 here. Explain SELECT and
FROM as keywords here.
Highlight that this is not a projection as all
columns are being selected.
Hint
Highlight that this is a projection as only
the selected columns are being displayed.
Also all rows are selected.
Basic SELECT Statement
SELECT [DISTINCT] {*,
column
[
alias
], }
FROM
table;
SELECT [DISTINCT] {*,
column
[
alias
], }
FROM
table;
• SELECT identifies
what
columns.
• FROM identifies
which
table.
Selecting All Columns
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> SELECT *
2 FROM dept;
Selecting Specific Columns
DEPTNO LOC
10 NEW YORK
20 DALLAS
30 CHICAGO
40 BOSTON
SQL> SELECT deptno, loc
2 FROM dept;
Oracle Education Products 21
Lesson 1: Writing Basic Select Statements
Hint
Highlight that the case of the columns
specified in the SELECT list does not
influence the case of the headings in the
results set. Mention that these headings
can be customized and will be covered in
the subsequent slides.
Hint
The explanation can include that
sometimes there is a requirement to
perform certain calculations with the data
from the tables. Highlight that these
calculated values can be displayed on the
screen or used to update the data in the
underlying tables. Mention that arithmetic
operators cannot be used in the FROM
clause.
Additional Reference
/>8.0/815/server.815/a67779/
operator.htm#997746
Hint
Explain that an expression is a
combination of one or more values,
operators, and functions that evaluate to a
value. Highlight that SQL*PLUS ignores
blank spaces before and after the
arithmetic operators.
Column Heading Defaults
• Default justification
– Left: Date and character data
– Right: Numeric data
• Default display: Uppercase
Arithmetic Expressions
Create expressions on NUMBER and DATE
data by using arithmetic operators.
Operator
+
-
*
/
Description
Add
Subtract
Multiply
Divide
Using Arithmetic Operators
SQL> SELECT ename, sal, sal+300
2 FROM emp;
ENAME SAL SAL+300
KING 5000 5300
BLAKE 2850 3150
CLARK 2450 2750
JONES 2975 3275
MARTIN 1250 1550
ALLEN 1600 1900
14 rows selected.
22 Oracle Education Products
Hint
Explain that if your arithmetic expression
contains more than one operator, the
priority is *, / first then +, (left to right if
there are several operators with the same
priority).
Hint
Mention that only one kind of parenthesis
( ) is accepted as part of SQL*Plus syntax.
Additional Example
Explain the difference between in the
output of these two SELECT statements:
SELECT ename, sal + 250 * 12
FROM emp;
SELECT ename, (sal + 250) *
12
FROM emp;
Hint
Mention that no two NULLS compare as
equal. Demonstrate the structure of the
EMP table and highlight that the EMPNO
has been defined as NOT NULL, so no
NULLs will be accepted. Explain that this
will be addressed in detail in the later
lessons.
Additional Reference
/>8.0/815/server.815/a67779/
ch2.htm#4008
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.
*
/+
_
Using Parentheses
SQL> SELECT ename, sal, 12*(sal+100)
2 FROM emp;
ENAME SAL 12*(SAL+100)
KING 5000 61200
BLAKE 2850 35400
CLARK 2450 30600
JONES 2975 36900
MARTIN 1250 16200
14 rows selected.
Defining a 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.
SQL> SELECT ename, job, comm
2 FROM emp;
ENAME JOB COMM
KING PRESIDENT
BLAKE MANAGER
TURNER SALESMAN 0
14 rows selected.
Oracle Education Products 23
Lesson 1: Writing Basic Select Statements
Hint
Highlight that including a NULL column
value in an arithmetic expression will give
wrong results, though SQL*PLUS will not
report any error. We might be fooled by
the erroneous results.
Additional Reference
Oracle SQL Reference Manual, Release 8,
“Elements of SQL”
Hint
Explain that column aliases produce more
readable and meaningful output. You can
have descriptive column aliases. You can
set the case of the column alias to lower
case, mixed case, or upper case. Highlight
that you cannot use column aliases in a
WHERE clause and that a column alias
does not change the actual name of the
column. Mention that column aliases can
be generated using both AS and by using
double quotes.
Hint
Explain the use of the double quotes and
that you must use them if the column alias
contains a space.
Null Values
in Arithmetic Expressions
Arithmetic expressions containing a null
value evaluate to null.
SQL> select ename, 12*sal+comm
2 from emp
3 WHERE ename=’KING’;
ENAME 12*SAL+COMM
KING
Defining a Column Alias
• Renames a column heading
• Is useful with calculations
• Immediately follows column name;
optional AS keyword between column
name and alias
• Requires double quotation marks if it
contains spaces or special characters
or is case sensitive
Using Column Aliases
SQL> SELECT ename AS name, sal salary
2 FROM emp;
NAME SALARY
SQL> SELECT ename "Name",
2 sal*12 "Annual Salary"
3 FROM emp;
Name Annual Salary
24 Oracle Education Products
Hint
Highlight that the resulting value is a
character value. Ask the participants to
note that the symbol for the concatenation
operator is ||.
Additional Reference
/>8.0/815/server.815/a67779/
operator.htm#997790
Additional Example
SELECT
substr(ename,1,1)||empno
“Email ID”
FROM emp;
The result set will now contain the first
character of the employee’s name
concatenated with his employee number.
For example, the e-mail ID for King will
be K7839. Explain the SUBSTR function
in brief.
Hint
Highlight that the literal is a part of every
row of the results set. Literal character
strings can be used to generate reports.
Additional Reference
/>8.0/815/server.815/a67779/
ch2.htm#3305
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
Using the Concatenation
Operator
SQL> SELECT ename||job AS "Employees"
2 FROM emp;
Employees
KINGPRESIDENT
BLAKEMANAGER
CLARKMANAGER
JONESMANAGER
MARTINSALESMAN
ALLENSALESMAN
14 rows selected.
Literal Character Strings
• A literal is a character, expression, or
number included in the SELECT list.
• Date and character literal values must
be enclosed within single quotation
marks.
• Each character string is output once for
each row returned.
Oracle Education Products 25
Lesson 1: Writing Basic Select Statements
Hint
Revisit the concatenation operator here.
Explain how a space can be a part of the
results set by enclosing a space between
two single quotes. Revisit column alias
here.
Hint
Alternatively to get a list of the unique
departments, they can select DEPTNO
from the DEPT table.
Additional Example
SELECT job
FROM emp;
Additional Example
SELECT DISTINCT(job)
FROM emp;
Using Literal Character Strings
Employee Details
KING is a PRESIDENT
BLAKE is a MANAGER
CLARK is a MANAGER
JONES is a MANAGER
MARTIN is a SALESMAN
14 rows selected.
SQL> SELECT ename ||’ ’||’is a’||’ ’||job
2 AS "Employee Details"
3 FROM emp;
Duplicate Rows
The default display of queries is all rows,
including duplicate rows.
SQL> SELECT deptno
2 FROM emp;
SQL> SELECT deptno
2 FROM emp;
DEPTNO
10
30
10
20
14 rows selected.
Eliminating Duplicate Rows
Eliminate duplicate rows by using the
DISTINCT keyword in the SELECT clause.
SQL> SELECT DISTINCT deptno
2 FROM emp;
DEPTNO
10
20
30