Project Report On Oracle DB

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 38

UJJAIN ENGINEERING COLLEGE

UJJAIN (M.P.)

Year 2013 2014

INDUSTRIAL TRAINING PROJECT REPORT


ON
Oracle Certified Associate (OCA) training course on
oracle 9i
A Dissertation Submitted in Partial Fulfillment of
the Requirement for the Degree of
Bachelor of Engineering
in
Computer Science Engineering.

Under The Guidance Of :

Submitted by :

Prof. Ashok Mewafarosh

Anshul Jain
0701CS101010

Certificate
___________________________________________________

This is to Certify that Mr. Anshul Jain working


under the guidance of
Prof. Ashok Mewafarosh
have satisfactorily completed the Industrial
Training Project Report On Oracle Certified
Associate (OCA) training course on Oracle9i
towards the partial fulfillment of the degree in
Bachelor of Engineering (Computer Science and
Engineering) from Ujjain Engineering College, Ujjain
(declared Autonomous by govt. of MP)

Internal Examiner:
External Examiner:

ORACLE 9i

Introduction:
Optimizing high-quality service in a service-driven marketplace, Oracle9i maximizes the
usefulness of traditional business and intranet applications while also providing users with the
functionality needed to foster the growth of the emerging hosted applications market on the
Internet.
Oracle9i builds on historic Oracle strengths to offer the first complete and simple software
infrastructure for the Internet's next generation of intelligent, collaborative applications.
Oracle9i new features expedite delivery of the performance, scalability, and availability that is
crucial to providing hosted service software for anyone, anywhere, and anytime.

Oracle9i Architecture:
Oracle9i architecture is depicted in below figure.
Oracle9i is made up of the following components:

Oracle9i Database

Oracle9i Application Server

Oracle9i Developer Suite

Oracle9i Database:
The Oracle9i Database introduces the following advanced and automated design features to stand
alone or to work in conjunction with the Oracle9i Application Server or the Oracle9i Developer
Suite to optimize performance for traditional applications and for the emerging hosted
applications market.
Oracle9i Real Application Clusters:
Oracle9i Real Application Clusters provides the following functionality:

Out-of-the-box linear scaling transparency

Compatibility with all applications without redesign

Capacity for rapidly adding nodes and disks

Systems Management:
Integrated system management products in Oracle9i create a comprehensive view of all critical
components that drive e-business processes. From the client and application server to the
database and host, Oracle9i quickly and completely assesses the overall health of an e-business
infrastructure.
High Availability:
Setting a new standard for high availability, Oracle9i introduces powerful new functionalities in
the areas of disaster recovery, system fault recovery, and planned downtime.
High Security:
Oracle9i offers the most secure internet platform available to protect company information with
multiple layers of security for data, users, and companies. Included are features for building
internet-scale applications, for providing security for users, and for keeping separate the data
from different hosted user communities.

Oracle9i Application Server:

Recognized as the leading application server for database-driven Web sites, Oracle9i Application
Server offers the industry's most innovative and comprehensive set of middle-tier services.
Comprehensive Middle-tier Services:
Continued innovation within comprehensive middle-tier services--ranging from self-service
enterprise portals to e-stores and supplier exchange--continues to establish that the
Oracle9i Application Server is the industry's preferred application server for database-driven
Web sites.
New Caching Technology:
The new caching technology in Oracle9i can dramatically increase Web site performance,
scalability, and availability. Oracle9i provides greater numbers of users with more personalized,
dynamic Web content without adding application or Databases.
Scalability and Performance:
Superb scalability and performance now is made available for all Web applications. Oracle Portal
services make it easy for Web site developers to deploy enterprise portals with centralized

management and unified security. Standard Java, with rich XML and content management
support--as well as back-office transactional applications built using Oracle Forms Developer-can easily be deployed.
Wireless Device Access:
Information in any database or internet application is easily available through Oracle9i so that
support for each wireless device's specific markup language is no longer necessary.
Business Intelligence:
Oracle9i Application Server has built-in reporting and ad hoc query functionality to derive
business intelligence after Web site deployment.
Oracle9i Developer Suite:
Oracle Internet Developer Suite combines leading Oracle applications development tools,
business intelligence tools, and enterprise portal building tools into a single, integrated product.
Built on internet standards such as Java, XML, CORBA, and HTML, the Oracle Internet
Developer Suite provides a high-performance development environment with tools needed to
respond to rapidly changing markets and user demands.
Extensive Development Alternatives:
Oracle Internet Developer Suite tools are suitable for any kind of development approach
including component-based development, Java coding, or visual modeling. They also offer rapid
application development based on fourth generation language (4GL). Applications can be
developed for all clients, including High Productive Java Client, Universal HTML Client, and
Anywhere Mobile Client.
Tools
Oracle Internet Developer Suite includes the following tools:

Oracle Forms Developer, which enables developers to leverage declarative capabilities


and visual editors to automatically generate highly interactive Java clients without having
to code in Java.

Oracle Designer, which models business processes, data entities, and relationships.
Models are automatically transformed into designs, which automatically generate
complete applications and databases.

Oracle JDeveloper and Business Components for Java, which includes a J2EE(tm)
development environment with end-to-end support for developing, debugging, and
deploying e-business applications.

Oracle Reports Developer, which can build enterprise-level reports rapidly and
productively and which is wizard-driven, includes a graphical layout editor, and delivers
advanced capabilities to tackle the most challenging reports involving complex queries
and programmatic logic.

Oracle Discoverer, which provides users with powerful, on-demand query and reporting
capabilities to gain strategic insight into their business and to formulate new ebusiness
strategic

Overview :
The Oracle Server is an object relational database management system that provides an open,
comprehensive, integrated approach to information management. Primary Components There are
several processes, memory structures, and files in an Oracle Server; however, not all of them are
used when processing a SQL statement. Some are used to improve the performance of the
database, ensure that the database can be recovered in the event of a software or hardware error,
or perform other tasks necessary to maintain the database. The Oracle Server consists of an
Oracle instance and an Oracle database.
Oracle Instance :
An Oracle instance is the combination of the background processes and memory structures. The
instance must be started to access the data in the database. Every time an instan ce is started, a
system global area (SGA) is allocated and Oracle background processes are started.The SGA is a
memory area used to store database information that is shared by database processes.
System Global Area The SGA is a memory area used to store database information that is shared
by database processes. It contains data and control information for the Oracle Server. It is
allocated in the virtual memory of the computer where the Oracle server resides. The SGA

consists of several memory structures: The shared pool is used to store the most recently
executed SQL statements and the most recently used data from the data dictionary. These SQL
statements may be submitted by a user process or, in the case of stored procedures, read from the
data dictionary.
The database buffer cache is used to store the most recently use d data. The data is read from,
and written to, the data files.
The redo log buffer is used to track changes made to the database by the server and
background processes.
There are also two optional memory structures in the SGA:
Java pool: Used to store Java code
Large pool: Used to store large memory structures not directly related to SQL statement
processing; for example, data blocks copied during backup and restore operations

Background Processes:
The background processes in an instance perform common functions that are needed to service
requests from concurrent users without compromising the integrity and performance of the
system. They consolidate functions that would otherwise be handled by multiple Oracle
programs running for each user. The background processes perform I/O and monitor other Oracle
processes to provide increased parallelism for better performance and reliability.
Depending on its configuration, an Oracle instance may include several background processes,
but every instance includes these five required background processes:
Database Writer (DBWO) is responsible for writing changed data from the database buffer
cache to the data files.
Log Writer (LGWR) writes changes registered in the redo log buffer to the redo log files.
System Monitor (SMON) checks for consistency of the database and, if necessary, initiates
recovery of the database when the database is opened.
Process Monitor (PMON) cleans up resources if one of the Oracle processes fails.
The Checkpoint Process (CKPT) is responsible for updating database status information in the
control files and data files whenever changes in the buffer cache are permanently recorded in the
database.
Other Processes :
The user process is the application program that originates SQL statements. The server process
executes the SQL statements sent from the user process.

Database Files :
Database files are operating system files that provide the actual physical storage for database
information. The database files are used to ensure that the data is kept consistent and can be
recovered in the event of a failure of the instance.
Other Files :
Non database files are used to configure the instance, authenticate privileged users, and recover
the database in the event of a disk failure.
SQL Statement Processing :
The user and server processes are the primary processes involved when a SQL statement is
executed; however, other processes may help the server complete the processing of the SQL
statement.
Oracle Database Administrators:
Database administrators are responsible for maintaining the Oracle Server so that the server can
process user requests. An understanding of the Oracle architecture is necessary to maintain it
effectively.
Oracle Database Files :
An Oracle database is a collection of data that is treated as a unit. The general purpose of a
database is to store and retrieve related information. The database has a logical structure and a
physical structure. The physical structure of the database is the set of operating system files in
the database. An Oracle database consists of three file types:
Data files contain the actual data in the database. The data is stored in user-defined tables, but
data files also contain the data dictionary, before-images of modified data, indexes, and other
types of structures. A database has at least one data file. The characteristics of data files are:
A data file can be associated with only one database. Data files can have certain characteristics
set so they can automatically extend when the database runs out of space. One or more data files
form a logical unit of database storage called a table space. Redo logs contain a record of
changes made to the database to enable recovery of the data in case of failures. A database
requires at least two redo log files.
Control files contain information necessary to maintain and yen fy database integrity. For
example, a control file is used to identify the data files and redo log files. A database needs at
least one control file.
Other Key Files :
The Oracle Server also uses other files that are not part of the database:
The parameter file defines the characteristics of an Oracle instance. For example, it parameters

that size some of the memory structures in the SGA.


The password file authenticates which users are permitted to start up and shut down an Oracle
instance.
Archived redo log files are offline copies of the redo log files that may be necessary to recover
from media failures.
Components Used to Process SQL:
Not all of the components of an Oracle instance are used to process SQL statements.The user and
server processes are used to connect a user to an Oracle instance. These processes are not part of
the Oracle instance, but are required to process a SQL statement. Some of the background
processes, SGA structures, and database files are used to process SQL statements. Depending on
the type of SQL statement, different components are used:
Queries require additional processing to return rows to the user.
Data manipulation language (DML) statements require additional processing to log the
changes made to the data.
Commit processing ensures that the modified data in a transaction n can be recovered.
Some required background processes do not directly participate in processing a SQL statement
but are used to improve performance and to recover the database. The optional background
process, ARC0, is used to ensure that a production database can be recovered.
Connection :
A connection is a communication pathway between a user processes a and an Oracle Server. A
database user can connect to an Oracle Server in one of three ways:
The user logs on to the operating system running the Oracle instance and starts an application
or tool that accesses the database on that system. The communication pathway is established
using the interprocess communication mechanisms available on the host operating system.
The user starts the application or tool on a local computer and connects over a network to the
computer running the Oracle instance. In this configuration, called client-server, network
software is used to communicate between the user and the Oracle Server.
In a three-tiered connection, the user s computer communicates over the network to an
application or a network server, which is connected through a network to the mach ine running
the Oracle instance. For example, the user runs a browser on a network computer to use an
application residing on an NT server that retrieves data from an Oracle database running on a
UNIX host.
Session :

Session is a specific connection of a user to an Oracle Server. The session starts when the user is
validated by the Oracle Server, and it ends when the user logs out or when the ere is an abnormal
termination. For a given database user, many concurrent sessions are possible if the user logs on
from many tools, applications, or terminals at the same time. Except for some specialized
database administration tools, starting a database session requires that the Oracle Server be
available for use.
Shared Pool Components:
During the parse stage, the server process uses the area in the SGA known as the shared pool to
compile the statement. The shared pool has two primary components:
Library cache
Data dictionary cache
Library Cache : The library cache stores information about the most recently use d SQL
statements in a memory structure called shared SQL area.
The shared SQL area contains:
The text of the SQL statement
The parse tree: A compiled version of the statement
The execution plan: The steps to be taken when executing the statement
Function of the Database Buffer Cache:
When a query is processed, the server process looks in the database buffer cache for any blocks
it needs. If the block is not found in the database buffer cache, the server process reads the block
from the data file and places a copy in the buffer cache. Because subsequent requests for the sa
me block may find the block in memory, the requests may not require physical reads. The Oracle
Server uses a least recently used algorithm to age out buffers that have not been accessed
recently to make room for new blocks in the buffer cache.
DML Processing:
Steps A data manipulation language (DML) statement requires only two phases of processing:
Parse is the same as the parse phase used for processing a query
Execute requires additional processing to make data changes DML Execute Phase to execute a
DML statement:

If the data and rollback blocks are not already in the buffer cache, the server process reads them
from the data files into the buffer cache.
The server process places locks on the rows that are to be modified.
In the redo log buffer, the server process records the changes to be made to the rollback and
data.
The rollback block changes record the values of the data before it is modified. The rollback
block is used to store the before image of the data, so that the DML statements can be rolled back
if necessary.
The data blocks changes record the new values of the data.
Program Global Area Components:
A program global area (PGA) is a memory region that contains data and control information f or
a server process. It is a non shared memory created by Oracle when a server process is started.
Access to it is exclusive to that server process and is read and written only by the Oracle Server
code acting on behalf of it. The PGA memory allocated by each server process attached to an
Oracle instance is referred to as the aggregated PGA memory allocated by the instance.
In a dedicated server configuration, the PGA of the server includes these components:
Sort area: Used for any sorts that may be required to process the SQL statement
Session information: Includes user privileges and performance statistics for the session
Cursor state: Indicates the stage in the processing of the SQL statements that are currently used
by the session.

Redo Log Buffer Characteristics:


The redo log buffer has the following characteristics:
Its size in bytes is defined by the LOG_BUFFER parameter.
It records the block that is changed, the location of the change, and the new value in a redo
entry. A redo entry makes no distinction between the type of block that is cha nged; it simply
records which bytes are changed in the block.
The redo log buffer is used sequentially, and changes made by one transaction may be
interleaved with changes made by other transactions.

It is a circular buffer that is reused after it is filled, but o nly after all the old redo entries are
recorded in the redo log files.
Rollback Segment:
Before making a change, the server process saves the old data va lue into a rollback segment.
This before image is used to:
Undo the changes if the transaction is rolled back
Provide read consistency by ensuring that other transactions do not see uncommitted changes
made by the DML statement
Recover the database to a consistent state in case of failures.
Fast COMMIT:
The Oracle Server uses a fast commit mechanism that guarantees t hat the committed changes
can be recovered in case of instance failure.
LOG Writer:
LGWR performs sequential writes from the redo log buffer to the redo log file under the
following situations:
When a transaction commits
When the redo log buffer is one-third full
When there is more than a megabyte of changes recorded in the redo log buffer
Before DBW0 writes modified blocks in the database buffer cache to the data files.

Workshop:
Entity Relationship diagram:

1. Create the tables based on the following table instance charts. Choose the
appropriate data types and be sure to add integrity constraints.

a. Table name: MEMBER

Query:
CREATE TABLE member
(member_id NUMBER (10)
CONSTRAINT member_id_pk PRIMARY KEY,
last_name VARCHAR2 (25)
CONSTRAINT member last_ name_nn NOT NULL, first name VARCHAR2 (25),
address VARCHAR2 (100),
city VARCHAR2 (30),
phone VARCHAR2 (15),
join_date DATE DEFAULT SYSDATE
CONSTRAINT member_join _date _nn NOT NULL);

b. Table name: TITLE

Query:
CREATE TABLE title
(title_id NUMBER (10)
CONSTRAINT title_id_pk PRIMARY KEY,
title VARCHAR2 (60) CONSTRAINT title_nn NOT NULL,
description VARCHAR2 (400)
CONSTRAINT title_description_nn NOT NULL,
Rating VARCHAR2 (4)
CONSTRAINT title_rating_ck CHECK
(rating IN (G, PG, R, NC17, NR)),
category VARCHAR2 (20),
CONSTRAINT title _category_ck CHECK
(category IN (DRAMA, COMEDY, ACTION,
CHILD, SCIFI, DOCUMENTARY)), release_date DATE);

c. Table name: TITLE_COPY

Query:
CREATE TABLE title_copy
(copy_id NUMBER (1O),
title_id NUMBER (1O) ,
CONSTRAINT title copy_title if fk REFERENCES title(titleid),
status VARCHAR2 (15)
CONSTRAINT title copystatus nn NOT NULL,
CONSTRAINT title copy_status_ck CHECK
(status IN (AVAILABLE, DESTROYED,RENTED, RESERVED)),
CONSTRAINT title_copy_copy_id_title_id_pk
PRIMARY KEY (copy_id, title_id));

d. Table name: RENTAL

Query:
CREATE TABLE rental
(book_date DATE DEFAULT SYSDATE,
member_id NUMBER(1O)
CONSTRAINT rentalmember_id_fk
REFERENCES member (member_id),
copy_id NUMBER(1O),
act_ret_date DATE,
exp_ret_date DATE DEFAULT SYSDATE + 2,
title_id NUMBER(1O),
CONSTRAINT rental_book_date_copy_title _pk
PRIMARY KEY (book date, member id,
copy_id, title_id),
CONSTRAINT rental_copy_id_title_id_fk
FOREIGN KEY (copy_id, title_id)
REFERENCES title_copy (copy_id, title_id));

e. Tablename:RESERVATION

Query:
CREATE TABLE reservation
(
res_date DATE,
member_id NUMBER(1O)
CONSTRAINT reservation_member_id
REFERENCES member (member_id),
title_id NUMBER(1O)
CONSTRAINT reservation_title_id
REFERENCES title (title_id),
CONSTRAINT reservation_res_date_mem_tit_pk PRIMARY KEY (res_date, member_id,
title_id)
);

2. Verify that the tables and constraints were created properly by checking the data
dictionary.
Query:

a. SELECT table_name FROM user_tables WHERE table_name IN ('MEMBER', 'TITLE',


TITLE_COPY', 'RENTAL', 'RESERVATION');

Output:

TABLE_NAME
MEMBER
RENTAL
RESERVATION
TITLE
TITLE_COPY

b. SELECT constraint_name, constraint_type, table_name FROM user_constraints WHERE


table_name IN ('MEMBER', 'TITLE', 'TITLE_COPY', 'RENTAL', 'RESERVATION');

Output:

CONSTRAINT_NAME

CON

TABLE_NAME

MEMBER_LAST_NAME_NN

MEMBER

MEMBER_JOIN_DATE_NN

MEMBER

MEMBER_MID_PK

MEMBER

RENTAL_BMCT_PK

RENTAL

RENTAL_MEMBER_ID_FK

RENTAL

RENTAL_COPY_ID_TITLE_ID_FK

RENTAL

RES_RES_MEMBER_TITLE_PK

RESERVATION

RESERVATION_MEMBER_ID_FK

RESERVATION

RESERVATION_TITLE_ID_FK

RESERVATION

TITLE_TITLE_NN

TITLE

TITLE_DESCRIPTION_NN

TITLE

TITLE_RATING_CK

TITLE

TITLE_CATEGORY_CK

TITLE

TITLE_TID_PK

TITLE

TITLE_COPY_STATUS_NN

TITLE_COPY

TITLE_COPY_STATUS_CK

TITLE_COPY

TITLE_COPY_COPY_ID_TITLE_ID_PK

TITLE_COPY

TITLE_COPY_TID_FK

TITLE_COPY

3. Create sequences to uniquely identify each row in the MEMBER table and the
TITLE table.

a. Member number for the MEMBER table: start with 101; do not allow caching of
the values. Name the sequence MEMBER_ID_SEQ .
Query:
CREATE SEQUENCE member _ id _ seq START WITH 101 NOCACHE;

a. Title number for the TITLE table: start with 92; no caching. Name the sequence
TITLE_ID_SEQ .
Query:
CREATE SEQUENCE title _ id _ seq START WITH 92 NOCACHE;

a. Verify the existence of the sequences in the data dictionary .


Query:
SELECT sequence_name FROM user_sequences WHERE sequence_name IN
('MEMBER_ID_SEQ', 'TITLE_ID_SEQ ');
Output:

SEQUENCE_NAME
MEMBER_ID_SEQ
TITLE_ID_SEQ

4. Add data to the tables. Create a script for each set of data to add.
a. Add movie titles to the TITLE table. Write a script to enter the movie information.
Save the statements in a script named. Use the sequences to uniquely identify each

title. Enter the release dates in the DD-MON-YYYY format. Remember that single
quotation marks in a character field must be specially handled.

Query:

Output:

TITLE_ID

TITLE

DESCRIPTION

Willie and

All of Willies's friends make a Christmas list for

Christmas Too

Santa, but Willie has yet to add his own wish list.

92

RATING CATEGORY RELEASE_

CHILD

95/10/05

SCIFI

95/05/19

NR

SCIFI

95/08/12

PG

COMEDY

95/07/12

PG

DRAMA

95/09/12

NR

ACTION

95/06/01

Yet another installation of science fiction history.


93

Alien Again

Can the heroine save the planet from the alien


life form?
A meteor crashes near a small American town

94

The Glob
and unleashes carnivorous goo in this classic.
With a little luck and a lot of ingenuity, a

95

My Day Off
teenager skips school for a day in New York
A six-year-old has doubts about Santa Claus, but

96

Miracles on Ice
she discovers that miracles really do exist
After discovering a cache of drugs, a young

97

Soda Gang

couple find themselves pitted against a vicious


gang.

b. Add data to the MEMBER table. Place the insert statements in a script named
lab14_4b.sql. Execute commands in the script. Be sure to use the sequence to add
the member numbers.

Query:

SET ECHO OFF


SET VERIFY OFF
INSERT INTO member (member_id, first_name, last_name, address, city, phone,
join_date)
VALUES (member_id_seq.NEXTVAL, &first _name, &last_name, &address,
&city, &phone, TO DATE (&join_date,
DD-MM-YYYY);
COMMIT;
SET VERIFY ON
SET ECHO ON

c. Add data to the MEMBER table. Place the insert statements lab2 . Execute commands
in the script. Be sure to use the sequence to add the member numbers.

Query:
SET ECHO OFF
SET VERIFY OFF
INSERT INTO member (member_id, first_name, last_name, address, city, phone,
join_date) VALUES (member_id_seq.NEXTVAL, '&first_name', '&last_name',
'&address', '&city', '&phone', TO_DATE('&join_date', 'DD-MM-YYYY');
COMMIT;
SET VERIFY ON
SET ECHO ON
Output:
MEMBER_ID

LAST_NAME

FIRST_NAME

ADDRESS

CITY

PHONE

JOIN_DAT

101

Velasquez

Carmen

283 King Street

Seattle

206-899-6666

90/03/08

102

Ngao

LaDoris

5 Modrany

Bratislava

586-355-8882

90/03/08

103

Nagayama

Midori

68 Via Centrale

Sao Paolo

254-852-5764

91/06/17

104

Quick-to-See

Mark

6921 King Way

Lagos

63-559-7777

90/04/07

105

Ropebum

Audry

86 Chu Street

Hong Kong

41-559-87

91/01/18

106

Urguhart

Molly

3035 Laurier

Quebec

418542-9988

91/01/18

d.

Add the following movie copies in the TITLE_COPY table:

Query:
INSERT INTO title copy(copy_id, title_id, status) VALUES (1, 92, AVAILABLE);
INSERT INTO title copy(copy_id, title_id, status) VALUES (1, 93, AVAILABLE);
INSERT INTO title copy(copy_id, title_id, status) VALUES (2, 93, RENTED);
INSERT INTO title copy(copy_id, title_id, status) VALUES (1, 94, AVAILABLE);
INSERT INTO title copy(copy_id, title_id, status) VALUES (1, 95, AVAILABLE);
INSERT INTO title_copy (copy_id, title_id, status)
VALUES (2, 95, AVAILABLE);
INSERT INTO title_copy (copy_id, title_id, status)
VALUES (3, 95, RENTED);

INSERT INTO title_copy (copy_id, title_id, status)


VALUES (1, 96, AVAILABLE);
INSERT INTO title_copy (copy_id, title_id, status)
VALUES (1, 97, AVAILABLE);

Output:

COPY_ID

TITLE_ID

STATUS

92

AVAILABLE

93

AVAILABLE

93

RENTED

94

AVAILABLE

95

AVAILABLE

95

AVAILABLE

95

RENTED

96

AVAILABLE

97

AVAILABLE

d. Add the following rentals to the RENTAL table:

Query:
INSERT INTO rental (title_id, copy_id, member_id,
book_date, exp_ret_date, act_ret_date)
VALUES (92, 1, 101, sysdate-3, sysdate-1, sysdate-2);
INSERT INTO rental (title_id, copy_id, member_id,
book_date, exp_ret_date, act_ret_date)
VALUES (93, 2, 101, sysdate-1, sysdate-1, NULL);
INSERT INTO rental (title_id, copy_id, member_id,
book_date, exp_ret_date, act_ret_date)
VALUES (95, 3, 102, sysdate-2, sysdate, NULL);

INSERT INTO rental (title_id, copy_id, member_id,


book_date, exp_ret_date ,act_ret_date)
VALUES (97, 1, 106, sysdate-4, sysdate-2, sysdate-2); COMMIT;
Output:
BOOK_DAT

MEMBER_ID

COPY_ID

09/05/11

101

09/05/13

101

09/05/12
09/05/10

ACT_RET_
09/05/12

EXP_RET_

TITLE_ID

09/05/13

92

09/05/13

93

102

09/05/14

95

106

09/05/12

96

09/05/12

5. Create a view named TITLE_AVAIL to show the movie titles and the availability of
each copy and its expected return date if rented. Query all rows from the view.
Order the results by title.
Query:

CREATE VIEW title_avail AS


SELECT t.title, c.copyid, c.status, r.exp_ret_date
FROM title t, title_copy c, rental r
WHERE t.titleid = c.titleid
AND c.copy_id = r.copyid(+)
AND c.title id = r.title id(+);
SELECT *
FROM title_avail
ORDER BY title, copy id;

Output:

TITLE

COPY_ID

STATUS

Alien Again

AVAILABLE

Alien Again

RENTED

EXP_RET_

09/05/13

Miracles on Ice

AVAILABLE

My Day Off

AVAILABLE

My Day Off

AVAILABLE

My Day Off

RENTED

Soda Gang

AVAILABLE

The Glob

AVAILABLE

Willie and Christmas Too

AVAILABLE

09/05/12

09/05/14

09/05/13

6.Make changes to data in the tables.

a. Add a new title. The movie is Interstellar Wars, which is rated PG and classified as
a scifi movie. The release date is 07-JUL-77. The description is Futuristic interstellar
action movie. Can the rebels save the humans from the evil empire? Be sure to add a
title copy record for two copies.
Query:
INSERT INTO title (title_id, title, description, rating, category, release_date)
VALUES (title_id_seg. NEXTVAL, Interstellar Wars,
Futuristic interstellar action movie. Can the rebels save the humans from the evil Empire?
PG, SCIFI, 07JUL77);
INSERT INTO title_copy (copy_id, title_id, status)
VALUES (1, 98, AVAILABLE);
INSERT INTO title_copy (copy_id, title_id, status)
VALUES (2, 98, AVAILABLE);

b. Enter two reservations. One reservation is for Carmen Velasquez, who wants to
rent Interstellar Wars. The other is for Mark Quick-to-See, who wants to rent
Soda Gang.
Query:

INSERT INTO reservation (res_date, member_id, title_id)


VALUES (SYSDATE, 101, 98);
INSERT INTO reservation (res_date, member_id, title_id)
VALUES (SYSDATE, 104, 97)

c. Customer Carmen Velasquez rents the movie Interstellar Wars, copy 1. Remove
her reservation for the movie. Record the information about the rental. Allow the
default value for the expected return date to be used. VerifSr that the rental was
recorded by using the view you created.
Query:
INSERT INTO rental(titleid, copyid, memberid)
VALUES (98,1,101);
UPDATE title_copy
SET status= RENTED
WHERE title_id = 98
AND copy_id = 1;
DELETE
FROM reservation
WHERE memberid = 101;
SELECT *
FROM title_avail
ORDER BY title, copy_id;
7. Make a modification to one of the tables.
a. Add a PRICE column to the TITLE table to record the purchase price of the video. The
column should have a total length of eight digits and two decimal places. Verify it.
Query:

ALTER TABLE title


ADD (price NUMBER (8, 2));
DESCRIBE title
Output:
TITLE_ID

NOT NULL

NUMBER(10)

TITLE

NOT NULL

VARCHAR2(60)

DESCRIPTION

NOT NULL

VARCHAR2(400)

RATING

VARCHAR2(4)

CATEGORY

VARCHAR2(20)

RELEASE_DATE

DATE

PRICE

NUMBER(8,2)

b. Create a script named lab14_7b.sql that contains update statements that update
each video with a price according to the following list. Run the commands in the
script. Note: Have the TITLE_ID numbers available for this exercise.

Query:
SET ECHO OFF
SET VERIFY OFF
DEFINE price=
DEFINE title_id=
UPDATE title SET price = &price WHERE title_id = &title_id;
SET VERIFY OFF

SET ECHO OFF


Output:

TITLE_ID

TITLE

PRICE

92

Willie and Christmas Too

25

93

Alien Again

35

94

The Glob

35

95

My Day Off

35

96

Miracles on Ice

30

97

Soda Gang

35

98

Interstellar Wars

29

c. Ensure that in the future all titles contain a price value. Verify the constraint.
Query:
ALTER TABLE title
MODIFY (price CONSTRAINT title_price_ nn NOT NULL);
SELECT constraint_name, constraint_type, search _ condition FROM user_constraints
WHERE table_name = 'TITLE';
Output:

CONSTRAINT_NAME
TITLE_TITLE_NN

CON
C

SEARCH_CONDITION
"TITLE" IS NOT NULL

TITLE_DESCRIPTION_NN C

"DESCRIPTION" IS NOT NULL

TITLE_RATING_CK

rating in ('G','PG','R','NC17','NR')

TITLE_CATEGORY_CK

category in
('DRAMA','COMEDY','ACTION','CHILD','SCIFI','DOCUMENTARY')
TITLE_TID_PK

TITLE_PRICE_NN

"PRICE" IS NOT NULL

8. Create a report titled Customer History Report. This report contains each customer's
history of renting videos. Be sure to include the customer name, movie rented, dates of the
rental, and duration of rentals. Total the number of rentals for all customers for the
reporting period. Save the commands that generate the report in a script file named
lab14_8.sql .
Query:

Output:

MEMBER
Carmen Velasquez

LaDoris Ngao

TITLE

BOOK_DAT

Willie and Christmas Too

09/05/11

Alien Again

09/05/13

Interstellar Wars

09/05/14

My Day Off

09/05/12

DURATION
1

Molly Urguhart

Miracles on Ice

09/05/10

You might also like