Tải bản đầy đủ (.ppt) (442 trang)

An Introduction to Oracle DBMS Architecture and Server-Side Programming

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.38 MB, 442 trang )

An Introduction to
Oracle DBMS Architecture
and
Server-Side Programming
Victor Matos
Department of Computer and Information Science
Cleveland State University

1


CONTENTS

Introduction
Oracle Architecture
PL/SQL Programming
Supplied Packages
Collections and Records
Objects
Cursors
Batch Processing
Exceptions
Packages
Triggers
Mutating Tables
Example Package (OLD)

3
18
127
213


222
272
309
333
344
357
367
397
423
CREDITS.
This document is a collage of notes taken from

2

1.

Oracle Documentation Files (www.oracle.com)

2.

Fundamentals of Database Systems by Elmasri & Navathe. Ed.
Addison Wesley

3.

Oracle – The Complete Reference by Koch & Loney. Ed. Oracle Press

4.

Microsoft On-Line Help files (www.microsoft.com)


5.

V. Matos lecture notes


What is ORACLE ?


Very robust implementation of a
Relational Database Management
System (RDBMS)



The relational model of data is simple to understand and has been
extensively scrutinized since 1970’s

3


What else is good about ORACLE ?
• The company is solid and successful,
since 1994 revenues in the order
of $2+ billion/year (~ $3BD in 2005)
• Very popular software,
worldwide distribution
(≈ 41% world market in 2007)
• Runs in different
type of computers.


4


Reasons for the Oracle Success









users are given specific
rights to operate on the data.
Backup and Recovery minimizes data loss and idle
time in the presence of failures
Space Management flexible allocation
Open Connectivity uninterrupted services
reachable from heterogeneous clients
Security Mechanisms

Development Tools

many to choose from
5


Software Support on the Oracle Server







built-in programming
capabilities based on the PL/SQL
language
Stored Procedures: programs stored in the
server-side could be invoked using
an ADA-like interface
Triggers: dormant server-side routines
which are ‘fired’ when specific
maintenance conditions are met
Procedural Option:

6


Parts of the Oracle Server

cont

• Packages:
libraries of server-side routines including proc,
functions, triggers, user defined data types,
constants, variables, etc.
ORACLE
PACKAGES


Various
Clients

ORACLE
SERVER

Same set of Proc,
functions, datatype, const, etc

7


Parts of the Oracle Server

cont

Distributed Option:
• Data could be stored in different machines and
placed in different cities.
• Oracle Distributed option provides location
transparency, the user does not need to be aware
of where the data is kept.

8


Oracle Distributed Option
Cleveland, Ohio
Ohio

Inventory

Workstation

SELECT PartNumber, Price
FROM
Ohio_inventory
WHERE inv_sup = Sup_Numb;

Indians95 Oraccle Server

, suppliers
NETWORK

New York, NY.
Suppliers
Yankees96 ORACLE Server

9


Oracle Distributed Option
Homogenous Distributed Database Systems
A homogenous distributed database system is a network of two or more
Oracle Databases that reside on one or more machines

Heterogeneous
Distributed Database
Systems
- In a heterogeneous distributed

database system, at least one of
the databases is a non-Oracle
Database system.
- To the application, the
heterogeneous distributed
database system appears as a
single, local, Oracle Database.
- The local Oracle Database
server hides the distribution and
heterogeneity of the data.

10


Oracle Distributed Option
Location Transparency


For a client application, the location and
platform of the databases are transparent.



You can also create synonyms for remote
objects in the distributed system so that
users can access them with the same
syntax as local objects.




For example, if you are connected to local
database MFG but want to access data on
remote database HQ, creating a synonym
on mfg for the remote emp table enables
you to issue this query:

SELECT * FROM emp;
same as
SELECT * FROM ;


In this way, a distributed system gives the
appearance of native data access.



Users on mfg do not have to know that the
data they access resides on remote
databases.
11


Parts of the Oracle Server

cont

Parallel Server Option:
• Independent machines (nodes) which their own
memory and disk space could tap into a common
disk database.

• This loosely coupled architecture provides data
sharing and message exchange between processes

12


Parallel Server Option
NODE 1
Cleveland, Ohio

NODE 2
New York, NY.
NY data

Ohio data

Shared
Database
Indians95 Oraccle Server

Yankees96 ORACLE Server

13


Parts of the Oracle Server

cont

Parallel Query Option:

• Computers holding more than one CPU (such as
multiPentium Windows NT, XT, …) could use those
processors in solving independent portions of a
query.
• An Oracle control unit breaks the query into
pieces, and re-assembles the partial results.

14


Parallel Query Option

Cleveland, Ohio

Original SQL
statement

SELECT LastName, Dno
FROM Employee
WHERE (salary > 70000) or (sex = 'F')

Ohio data
Pentium 1
SELECT LastName, Dno
FROM Employee
WHERE (salary > 70000)
Indians95 Oraccle Server
Dual Pentium
Windows NT4.0


Pentium 2

OR

SELECT LastName, Dno
FROM Employee
WHERE (sex = 'F')
Result s

15


Links to ORACLE Products & Services
www.oracle.com
TECHNOLOGY PRODUCTS
Database and Grids
Middleware | Data Hubs
Developer Tools
Security | Search
Enterprise Management
Business Intelligence
Collaboration | Content
Data Warehousing
Standards | Java | Linux
Downloads

APPLICATION PRODUCTS
Customer Relationship Management
Financial Accounting
Human Resources

Supply Chain
Public Sector Applications
Banking Applications
Retail Applications
Telecom Applications
Higher Education Applications
Other Industries
ORACLE SERVICES
Support | Education
On Demand
Financing
INSIGHT | Consulting
16


Links to ORACLE Products & Services
www.oracle.com
INDUSTRIES
Oracle has solutions for many industry segments such as.
Automotive

Banking

Engineering &
Construction

Government

Government


         
            

                 

            

                 

            

            

                 

Download (PDF)

Download (PDF)

Download (PDF)

Government

Healthcare

Human Capital
Management

                 


Download (PDF)
Manufacturing

                 
Download (PDF)
Retail

         
                      
       

                       
      

               

              

                       
      

            

Telecommunications

                       
      
Download (PDF)

Download (PDF)


Download (PDF)

Download (PDF)

Download (PDF)

Download (PDF)

17


Components of Typical Oracle Server

Data Dictionary
Permanent Storage
Memory & Processes

18


Oracle Server – Database Dictionary
The Database dictionary is a read-only set of tables and
views that provides information about the database.
A data dictionary contains:
■ The definitions of all schema objects in the database (tables, views, indexes,
clusters, synonyms, sequences, procedures, functions, packages, triggers, and so on)
■ How much space has been allocated for, and is currently used by, the schema objects
■ Default values for columns
■ Integrity constraint information

■ The names of Oracle users
■ Privileges and roles each user has been granted
■ Auditing information, such as who has accessed or updated various schema objects
■ Other general database information
The data dictionary tables and views for a given database are stored in that database’s
SYSTEM tablespace.
19


Oracle Server – Database Dictionary
How the Data Dictionary Is Used
The data dictionary has three primary uses:
■ Oracle accesses the data dictionary to find information about
users, schema objects, and storage structures.
■ Oracle modifies the data dictionary every time that a data
definition language (DDL) statement is issued.
■ Any Oracle user can use the data dictionary as a read-only
reference for information about the database.
Data Dictionary View Prefixes
Prefix Scope
USER
User’s view (what is in the user’s schema)
ALL
Expanded user’s view (what the user can access)
DBA
Database administrator’s view (what is in all users’ schemas)

20



ORACLE Architecture
A. What is inside of the database dictionary?
SYSTEM SQL> column COMMENTS format a35 wrap
SYSTEM SQL>

select * from DICTIONARY;

TABLE_NAME
-----------------------------DBA_ROLES
DBA_PROFILES
USER_RESOURCE_LIMITS
USER_PASSWORD_LIMITS
USER_CATALOG
ALL_CATALOG
DBA_CATALOG
USER_CLUSTERS
ALL_CLUSTERS
DBA_CLUSTERS

DBA_SQLSET_DEFINITIONS
USER_SQLSET_DEFINITIONS
1821 rows selected.

COMMENTS
--------------------------------------All Roles which exist in the database
Display all profiles and their limits
Display resource limit of the user
Display password limits of the user
Tables, Views, Synonyms and Sequences
owned by the user

All tables, views, synonyms, sequences
accessible to the user
All database Tables, Views, Synonyms,
Sequences
Descriptions of user's own clusters
Description of clusters accessible
to the user
Description of all clusters in the
database
Synonym for DBA_SQLSET
Synonym for USER_SQLSET

21


ORACLE Architecture
B. What is inside of a table?
SCOTT_SQL> describe
Name
------------------FNAME
MINIT
LNAME
SSN
BDATE
ADDRESS
SEX
SALARY
SUPERSSN
DNO


Employee

Null?
Type
-------- ------------------------VARCHAR2(10)
CHAR(1)
NOT NULL VARCHAR2(15)
NOT NULL CHAR(9)
DATE
VARCHAR2(28)
CHAR(1)
NUMBER(10,2)
CHAR(9)
NUMBER(38)

NOTE: You could use desc instead of describe
22


ORACLE Architecture
B. What tables do I have?
SCOTT_SQL> select table_name, blocks, num_rows

from user_tables;
TABLE_NAME
BLOCKS
NUM_ROWS
------------------------------ ---------- ---------DEPENDENT
5
7

DEPARTMENT
5
3
DEPT_LOCATIONS
5
5
PROJECT
5
6
JUNK
5
1
PAY_CHECK_TABLE
5
3
WORKS_ON
5
17
EMPLOYEE
5
8
7 rows selected.

23


Physical Database Structures
Datafiles

• Every Oracle database has one or more physical datafiles.

• The datafiles contain all the database data.
• The data of logical database structures, such as tables and indexes, is physically stored in the datafiles
allocated for a database.
The characteristics of datafiles are:
■ A datafile can be associated with only one database.
■ Datafiles can have certain characteristics set to let them automatically extend when the database
runs out of space.
■ One or more datafiles form a logical unit of database storage called a tablespace.
■ Data in a datafile is read, as needed, during normal database operation and stored in the memory
cache of Oracle.
Example.
Assume that a user wants to access some data in a table of a database. If the requested information is not
already in the memory cache for the database, then it is read from the appropriate datafiles and stored in
memory. Modified or new data is not necessarily written to a datafile immediately. To reduce the amount
of disk access and to increase performance, data is pooled in memory and written to the appropriate
datafiles all at once, as determined by the database writer process (DBWn) background process.
24


ORACLE Architecture
•A database consists of one
or more logical storage units
called tablespaces, which
collectively store all of the
database’s data.
•Each tablespace consists of
one or more files called
datafiles.
•Datafiles are physical
structures that conform to the

operating system in which
Oracle is running.

25


×