You are on page 1of 24

I

Introduction

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
After
After completing
completing this
this lesson,
lesson, you
you should
should bebe ab
ab
le
le to
to do
do the
the following:
following:
•• Discuss
Discuss thethe theoretical
theoretical and
and physical
physical aspects
aspects
of
of aa relational
relational database
database
•• Describe
Describe thethe Oracle
Oracle implementation
implementation ofof the
the RR
DBMS
DBMS and and ORDBMS
ORDBMS
•• Describe
Describe howhow SQL
SQL and
and PL/SQL
PL/SQL are
are used
used in
in tt
he
he Oracle
Oracle product
product set
set
•• Describe
Describe thethe use
use and
and benefits
benefits of
of PL/SQL
PL/SQL

I-2 Copyright  Oracle Corporation, 1998. All rights reserved.


System Development Life Cycle

Strategy
and
Analysis
Design
Build
and
Document
Transition

Production

I-3 Copyright  Oracle Corporation, 1998. All rights reserved.


Data Storage on Different Media
SALGRADE
SALGRADE
GRADE
GRADE LOSAL
LOSAL HISAL
HISAL
---------
--------- ---------
--------- ---------
---------
DEPT
DEPT 11 700
700 1200
1200
DEPTNO
DEPTNO DNAME
DNAME LOC
LOC
22 1201
1201 1400
1400
---------
--------- --------------
-------------- ----------
----------
33 1401
1401 2000
2000
10
10 ACCOUNTING
ACCOUNTING NEW
NEW
44 2001
2001 3000
3000
YORK
YORK
55 3001
3001 9999
9999
20
20 RESEARCH
RESEARCH DALLAS
DALLAS
30
30 SALES
SALES CHICAGO
CHICAGO
40
40 OPERATIONS
OPERATIONS BOSTON
BOSTON

Database

Electronic sp Filing cabinet


readsheet
I-5 Copyright  Oracle Corporation, 1998. All rights reserved.
Relational Database Concept

•• Dr.
Dr. E. E. F.
F. Codd
Codd proposed
proposed the
the relational
relational model
model fo
fo
rr database
database systems
systems inin 1970.
1970.
•• ItIt is
is the
the basis
basis for
for the
the relational
relational database
database manag
manag
ement
ement system
system (RDBMS).
(RDBMS).
•• The
The relational
relational model
model consists
consists ofof the
the following:
following:
–– Collection
Collection of
of objects
objects or
or relations
relations
–– Set
Set of
of operators
operators to
to act
act on
on the
the relations
relations
–– Data
Data integrity
integrity for
for accuracy
accuracy and
and consistency
consistency

I-6 Copyright  Oracle Corporation, 1998. All rights reserved.


Definition of a
Relational Database
A
A relational
relational database
database is
is aa collection
collection of
of rela
rela
tions
tions or
or two-dimensional
two-dimensional tables.
tables.
Database

Table Name: EMP Table Name: DEPT


EMPNO
EMPNO ENAME
ENAME JOB
JOB DEPTNO
DEPTNO DEPTNO
DEPTNO DNAME
DNAME LOC
LOC
7839
7839 KING
KING PRESIDENT
PRESIDENT 10
10 10
10 ACCOUNTING
ACCOUNTING NEW
NEW YORK
YORK
7698
7698 BLAKE
BLAKE MANAGER
MANAGER 30
30 20
20 RESEARCH
RESEARCH DALLAS
DALLAS
7782
7782 CLARK
CLARK MANAGER
MANAGER 10
10 30
30 SALES
SALES CHICAGO
CHICAGO
7566
7566 JONES
JONES MANAGER
MANAGER 20
20 40
40 OPERATIONS
OPERATIONS BOSTON
BOSTON

I-7 Copyright  Oracle Corporation, 1998. All rights reserved.


Data Models

Model of
system
in client’s Entity model of
mind client’s model

Table model
of entity model
Server

Tables on disk

I-8 Copyright  Oracle Corporation, 1998. All rights reserved.


Entity Relationship Model
•• Create
Create an
an entity
entity relationship
relationship diagram
diagram from
from busine
busine
ss
ss specifications
specifications oror narratives
narratives

EMPLOYEE
EMPLOYEE assigned DEPARTMENT
DEPARTMENT
assigned to
to
#*
#* number
number #*
#* number
number
** name
name ** name
name
composed of
composed of
oo job
job title
title oo location
location

•• Scenario
Scenario
–– “.
“. .. .. Assign
Assign one
one oror more
more employees
employees toto aa depart
depart
ment
ment .. .. .”
.”
–– “.
“. .. .. Some
Some departments
departments do do not
not yet
yet have
have assign
assign
ed
ed employees
employees .. .. .”
.”
I-9 Copyright  Oracle Corporation, 1998. All rights reserved.
Entity Relationship
Modeling Conventions
Entity Attribute
Soft box Singular name
Singular, unique name Lowercase
Uppercase Mandatory marked with “*”
Synonym in parentheses Optional marked with “o”

EMPLOYEE
EMPLOYEE assigned
assigned to
to DEPARTMENT
DEPARTMENT
#*
#* number
number #*
#* number
number
** name
name * name
composed of *
composed of name
oo job
job title
title oo location
location

Unique Identifier (UID)


Primary marked with “#”
Secondary marked with “(#)”
I-10 Copyright  Oracle Corporation, 1998. All rights reserved.
Relational Database Terminology
2 3 4
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
6
------------- ------------ --------------------- -------- ---------------- ----------- -------------- -----------
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 5 0 30
7900 JAMES CLERK 7698 03-DEC-81 950 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
1 7934 MILLER CLERK 7782 23-JAN-82 1300 10

I-12 Copyright  Oracle Corporation, 1998. All rights reserved.


Relating Multiple Tables
•• Each
Each row
row of
of data
data in
in aa table
table is
is uniquely
uniquely ide
ide
ntified
ntified by
by aa primary
primary key
key (PK).
(PK).
•• You
You can
can logically
logically relate
relate data
data from
from multipl
multipl
ee tables
tables using
using foreign
foreign keys
keys (FK).
(FK).
Table Name: EMP Table Name: DEPT
EMPNO ENAME JOB DEPTNO DEPTNO DNAME LOC
7839 KING PRESIDENT 10 10 ACCOUNTING NEW YORK
7698 BLAKE MANAGER 30 20 RESEARCH DALLAS
7782 CLARK MANAGER 10 30 SALES CHICAGO
7566 JONES MANAGER 20 40 OPERATIONS BOSTON

Primary key Foreign key Primary key


I-13 Copyright  Oracle Corporation, 1998. All rights reserved.
Relational Database Properties

A
A relational
relational database
database
•• Can
Can be
be accessed
accessed and
and modified
modified by
by execu
execu
ting
ting structured
structured query
query language
language (SQL)
(SQL) st
st
atements
atements
•• Contains
Contains aa collection
collection of
of tables
tables with
with no
no p
p
hysical
hysical pointers
pointers
•• Uses
Uses aa set
set of
of operators
operators

I-14 Copyright  Oracle Corporation, 1998. All rights reserved.


Communicating with a RDBMS
Using SQL
SQL statement
is entered Statement is sent to
SQL>
SQL> SELECT
SELECT loc
loc
database
22 FROM
FROM dept;
dept;

Database

Data is displayed
LOC
LOC
-------------
-------------
NEW
NEW YORK
YORK
DALLAS
DALLAS
CHICAGO
CHICAGO
BOSTON
BOSTON

I-15 Copyright  Oracle Corporation, 1998. All rights reserved.


Relational Database Managemen
t System

Server

User tables Data


dictionary
I-16 Copyright  Oracle Corporation, 1998. All rights reserved.
Oracle8: Object Relational Datab
ase Management System
•• User-defined
User-defined data
data types
types and
and objects
objects
•• Fully
Fully compatible
compatible with
with relational
relational databas
databas
ee
•• Support
Support of
of multimedia
multimedia and
and large
large objects
objects
•• High-quality
High-quality database
database server
server features
features

I-17 Copyright  Oracle Corporation, 1998. All rights reserved.


Defining an Object
An
An object
object
•• Is
Is aa person,
person, place,
place, or
or thing
thing
•• Knows
Knows things
things about
about itself
itself and
and performs
performs
actions
actions
•• Has
Has an
an identity
identity

I am a clock. I know
my time zone, and I
can display time.

I-18 Copyright  Oracle Corporation, 1998. All rights reserved.


Using an Object Model
•• Objects
Objects model
model aa problem
problem toto solve.
solve.
•• The
The model
model is
is stated
stated in
in terms
terms ofof the
the inter
inter
actions
actions between
between objects.
objects.
•• Object
Object models
models closely
closely resemble
resemble the
the real
real
world.
world.

Buy

Sell

Customers Business

I-19 Copyright  Oracle Corporation, 1998. All rights reserved.


Characteristics of Object Systems
•• Present
Present information
information inin object
object form
form
•• Classify
Classify objects
objects into
into object
object types
types
•• Inherit
Inherit attributes
attributes and
and code
code
•• Hide
Hide data,
data, code,
code, and
and attributes
attributes
•• Interact
Interact with
with other
other objects
objects
•• Recognize
Recognize different
different objects
objects without
without an
an
alysis
alysis
•• Interpret
Interpret the
the same
same command
command in in differe
differe
nt
nt ways
ways
I-20 Copyright  Oracle Corporation, 1998. All rights reserved.
Oracle Complete Solution
Applications
Applications Oracle
Oracle Developer
Developer
HR
HR
Financials
Financials Discoverer
Discoverer
Manufacturing
Manufacturing
... Oracle
Oracle Designer
Designer
...

SQL
SQL PL/SQL
PL/SQL SQL*
SQL* Plus
Plus

Oracle7/8 Data dictionar


Database
y
Data tables

I-21 Copyright  Oracle Corporation, 1998. All rights reserved.


SQL Statements
SELECT Data retrieval

INSERT
UPDATE Data manipulation language (DML)
DELETE

CREATE
ALTER
DROP Data definition language (DDL)
RENAME
TRUNCATE

COMMIT
ROLLBACK Transaction control
SAVEPOINT

GRANT Data control language (DCL)


REVOKE
I-22 Copyright  Oracle Corporation, 1998. All rights reserved.
About PL/SQL

•• PL/SQL
PL/SQL is is an
an extension
extension toto SQL
SQL with
with desi
desi
gn
gn features
features ofof programming
programming languages.
languages.
•• Data
Data manipulation
manipulation andand query
query statements
statements
of
of SQL
SQL are
are included
included within
within procedural
procedural u
u
nits
nits of
of code.
code.

I-23 Copyright  Oracle Corporation, 1998. All rights reserved.


PL/SQL Environment
PL/SQL engine
PL/SQL Procedural
PL/SQL PL/SQL
block block SQL Statement
Executor

SQL Statement Executor

Oracle Server

I-24 Copyright  Oracle Corporation, 1998. All rights reserved.


Tables Used in the Course
EMP
EMPNO
EMPNO ENAME
ENAME JOB
JOB MGR
MGR HIREDATE
HIREDATE SAL
SAL COMM
COMM DEPTNO
DEPTNO
---------
--------- ----------
---------- ---------
--------- ---------
--------- ---------
--------- ---------
--------- ---------
--------- ---------
---------
7839
7839 KING
KING PRESIDENT
PRESIDENT 17-NOV-81
17-NOV-81 5000
5000 10
10
7698
7698 BLAKE
BLAKE MANAGER
MANAGER 7839
7839 01-MAY-81
01-MAY-81 2850
2850 30
30
7782
7782 CLARK
CLARK MANAGER
MANAGER 7839
7839 09-JUN-81
09-JUN-81 2450
2450 10
10
7566
7566 JONES
JONES MANAGER
MANAGER 7839
7839 02-APR-81
02-APR-81 2975
2975 20
20
7654
7654 MARTIN
MARTIN SALESMAN
SALESMAN 7698
7698 28-SEP-81
28-SEP-81 1250
1250 1400
1400 30
30
7499
7499 ALLEN
ALLEN SALESMAN
SALESMAN 7698
7698 20-FEB-81
20-FEB-81 1600
1600 300
300 30
30
7844
7844 TURNER
TURNER SALESMAN
SALESMAN 7698
7698 08-SEP-81
08-SEP-81 1500
1500 00 30
30
DEPT 7900
7900 JAMES
JAMES CLERK
CLERK 7698
7698 03-DEC-81
03-DEC-81 950
950 30
30
7521
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
DEPTNO DNAMEWARD
DEPTNO DNAME SALESMAN
LOC
LOC 7698 22-FEB-81 1250 500 30
--------- 7902
7902 FORD
FORD
--------- --------------
--------------
ANALYST
ANALYST
----------
----------
7566
7566 03-DEC-81
03-DEC-81 SALGRADE
3000
3000 20
20
7369 SMITH
7369 10
SMITH CLERK
CLERK NEW
ACCOUNTING 7902
7902 17-DEC-80
17-DEC-80 800
800
GRADE LOSAL 20
20
HISAL
10 ACCOUNTING NEW GRADE LOSAL HISAL
YORK 7788 SCOTT
7788 SCOTT ANALYST
ANALYST 7566
7566 09-DEC-82 3000
09-DEC-82 ---------
3000 --------- 20
20
YORK --------- --------- ---------
---------
20 7876
7876 ADAMS
ADAMS CLERK
CLERK 7788
7788 12-JAN-83
12-JAN-83 1100
1100 11 20
20
20 RESEARCH
RESEARCH DALLAS
DALLAS 700
700 1200
1200
7934
7934 MILLER CLERK 7782 23-JAN-82 1300 10
30 SALESMILLER
30 SALES CLERK
CHICAGO
CHICAGO 7782 23-JAN-82 1300 22 1201
1201 10
1400
1400
40
40 OPERATIONS
OPERATIONS BOSTON
BOSTON 33 1401
1401 2000
2000
44 2001
2001 3000
3000
55 3001
3001 9999
9999

I-25 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary
•• Relational
Relational databases
databases areare composed
composed of of re
re
lations,
lations, managed
managed by by relational
relational operations
operations
,, and
and governed
governed by by data
data integrity
integrity constrai
constrai
nts.
nts.
•• The
The Oracle
Oracle Server
Server allows
allows you
you to
to store
store an
an
dd manage
manage information
information byby using
using the
the SQL
SQL ll
anguage
anguage and
and PL/SQL
PL/SQL engine.
engine.
•• PL/SQL
PL/SQL isis an
an extension
extension to to SQL
SQL with
with desi
desi
gn
gn features
features of
of programming
programming languages.
languages.

I-26 Copyright  Oracle Corporation, 1998. All rights reserved.

You might also like