DBMSLabManua_Final
DBMSLabManua_Final
DBMS
LAB Manual
Prepared by
TABLE OF CONTENTS
S. No Topic Page No
1 LAB OBJECTIVES 3
2 INTRODUCTION 4
3 SQL INTRODUCTION 5
4 SQL COMMANDS 6
5 SYNTAX’S OF COMMAND 7
6 CREATE,INSERT,UPDATE, DELETE, RENAME, TRUNCATE, ON TABLES 9
7 CREATING AND DROPING OF VIEWS 18
8 TRIGGERS 20
9 INTRODUCTION TO PL/SQL 23
10 CREATION OF FORMS 31
11 GENERATING REPORTS 36
12 REFERRENCES 43
13 VIVA VOICE QUESTIONS AND ANSWERS 43
LAB OBJECTIVES
A vast majority of the software applications being built use some kind of a data store mechanism
to permanently store the data generated/used by the software. Database management systems are
complex software systems that provide a wide variety of functionality for users to structure,
organize and access data quickly and efficiently. Database systems have been there since the early
1970’s but have grown in complexity and size. Relational database management systems use
relational algebra as the basis for representation of data. RDBMS as relational database
management systems are the most popular and widely used DBMS in the market place.
In this lab, you would be exposed to one popular RDBMS. The broad one line objective of the lab
is to get familiar with the functionality and support provided by commercially popular RDBMS
and understand how to use it to meet your data storage and organization requirements.
• You learn SQL (Structured Query Language) which would provide functionality to:
o Learn how to create tables which are fundamental storage blocks of data.
o Learn how to place constraints on data that is entered on tables to ensure data
integrity.
o Learn how to add, change and remove data from tables.
o Learn how to select a subset of the data you want to see from the collection of
tables and data.
o Learn how to combine table and group multiple rows of data in table.
• You learn PL/SQL which would provide the ability to do iterative programming at
database level to:
o Write programming blocks with conditionals, assignments, loops, etc
o Exception Handling.
o Transaction oriented programs
o Stored procedures, functions, packages.
o Cursors which would allow row wise access of data.
o Triggers which would allow you define pre and post actions when something
changes in the database tables.
At the end of the lab, you should be comfortable using any popular RDBMS for data access
and updating and should be comfortable writing PL/SQL programs at database level using
Oracle.
INTRODUCTION
RDBMS is one of the most widely used pluggable software components in most enterprise
software applications. Though RDBMS applications have been there since the early 1970s, they
have improved tremendously in terms of their features, the size of data they can hold, and the
complexity over the last 20 years.
Oracle is one of the very widely used commercial RDBMS systems and at this point is the market
leader as far as RDBMS is concerned. Oracle9i is RDBMS software which supports SQL – 1999.
It also supports programming language extension to SQL called PL/SQL which is Oracle
proprietary and is very popular to do program development at the database server level. Other
popular DBMS software like Sybase and SQL Server support their own programming extensions
to SQL – 1999.
SQL
SQL (Structured Query Language) is a standard supported by all the popular relational database
management systems in the market place. The basis data structure in RDBMS is a table. SQL
provides you the features to define tables, define constraints on tables, query for data in table, and
change the data in table by adding, modifying, and removing data. SQL also supports grouping of
data in multiple rows, combining tables and other features. All these put together, SQL is a high-
level query language standard to access and alter data in RDBMS.
SELECT clause
FROM clause
WHERE clause
• GROUP BY
• HAVING
Data Definition Language (DDL): To do with altering the structure of data base.
• Create tables.
• Create Indexes on tables.
• Alter tables
• Add constraints to tables.
• Drop tables.
• Truncate tables.
• Drop indexes.
• Create sequences.
Data Manipulation Language (DML): To do with adding, updating, and deleting data from tables.
• Insert Data
• Update Data
• Delete Data
• Merge Tables.
As you can see from above, SQL gives you all the tools needed to define your database in the form
of table, define integrity constraint rules on table to ensure data integrity, change the database as
needed and control permissions on tables at a very fine granular level.
SQL – 1999 is the standard which is supported by all commercial database vendors. If your
queries are using SQL – 1999 standard, they will run all RDBMS servers. In addition to the SQL –
1999 standard, most commercial databases have their own extensions to SQL supported by them.
In the interest of portability, it would be good if we stick with SQL – 1999 standard in our
querying no matter what RDBMS we are using unless we have a strong reason to go for additional
features not included in SQL – 1999 standard.
SQL COMMANDS
DDL
Data Definition Language (DDL) statements are used to define the database structure or schema.
DDL Commands: Create , Alter ,Drop , Rename, Truncate
DML
Data Manipulation Language (DML) statements are used for managing data within schema objects
DCL
Data Control Language (DCL) statements is used to create roles, permissions, and referential
integrity as well it is used to control access to database by securing it.
TCL
Transaction Control (TCL) statements are used to manage the changes made by DML statements.
It allows statements to be grouped together into logical transactions.
SYNTAX’S OF COMMANDS
CREATE TABLE
ALTER A TABLE
DROP TABLE
TRUNCATE TABLE
INSERT
( OR )
UPDATE
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value;
DELETE
SELECT
SELECT column_name(s)
FROM table_name;
OUTPUT:-TABLE CREATED
OUTPUT:-
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
OUTPUT:-Table renamed.
OUTPUT:-
OUTPUT:-Table altered.
OUTPUT:-
OUTPUT:-Table dropped.
(NOT NULL)
Table created.
1 row created.
SQL> /
Enter value for rollno: 502
Enter value for name: ABI
Enter value for branch: CSE
old 1: INSERT INTO STUD VALUES(&ROLLNO,'&NAME','&BRANCH')
new 1: INSERT INTO STUD VALUES(502,'ABI','CSE')
1 row created.
(UNIQUE)
Table created.
1 row created.
SQL> /
Enter value for rollno: 502
Enter value for name: ABI
Enter value for branch: CSE
old 1: INSERT INTO STUD VALUES(&ROLLNO,'&NAME','&BRANCH')
new 1: INSERT INTO STUD VALUES(502,'ABI','CSE')
1 row created.
SQL> /
Enter value for rollno: 502
Enter value for name: BHAVYA
Enter value for branch: CSE
old 1: INSERT INTO STUD VALUES(&ROLLNO,'&NAME','&BRANCH')
new 1: INSERT INTO STUD VALUES(502,'BHAVYA','CSE')
INSERT INTO STUD VALUES(502,'BHAVYA','CSE')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C001290) violated
(PRIMARY KEY)
Table created.
1 row created.
SQL> /
Enter value for rollno: 502
Enter value for name: ABI
Enter value for branch: CSE
old 1: INSERT INTO STUD VALUES(&ROLLNO,'&NAME','&BRANCH')
new 1: INSERT INTO STUD VALUES(502,'ABI','CSE')
1 row created.
SQL> /
Enter value for rollno: 502
Enter value for name: BHAVYA
Enter value for branch: CSE
old 1: INSERT INTO STUD VALUES(&ROLLNO,'&NAME','&BRANCH')
(CHECK)
Table created.
1 row created.
SQL> /
Enter value for rno: 565
Enter value for name: rohit
Enter value for sal: 35000
old 1: insert into stud values(&rno,'&name',&sal)
( FOREIGN KEY )
SOL>create table adm(stuid number(6) constraint stuid_pk primary key,sname varchar2(15),per
number(5));
Table created.
1 row created.
SQL> /
Enter value for stuid: 2
Enter value for sname: rohit
Enter value for per: 89
old 1: insert into adm values(&stuid,'&sname',&per)
new 1: insert into adm values(2,'rohit',89)
1 row created.
SQL> /
Enter value for stuid: 3
Enter value for sname: sachin
Enter value for per: 99
old 1: insert into adm values(&stuid,'&sname',&per)
new 1: insert into adm values(3,'sachin',99)
1 row created.
SQL> /
Enter value for stuid: 4
Enter value for sname: naveen
Enter value for per: 70
old 1: insert into adm values(&stuid,'&sname',&per)
1 row created.
Table created.
1 row created.
SQL> /
Enter value for stuid: 5
Enter value for branch: cse
Enter value for sec: b
old 1: insert into course values(&stuid,'&branch','&sec')
new 1: insert into course values(5,'cse','b')
insert into course values(5,'cse','b')
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.SID_FK) violated - parent key not found
1 row deleted.
1 row deleted.
OUTPUT:-
OUTPUT:-
View created.
OUTPUT:-
OUTPUT:-
1 row updated.
OUTPUT:-
OUTPUT:-
OUTPUT:-
Table dropped.
OUTPUT:-
ERROR at line 1:
ORA-04063: view "SCOTT.EMP22" has errors
TRIGGERS
Example:
A trigger called check_sal which runs every time a new employee is getting inserted to enforce
some rules on what should be the minimum salary.
Elements in a Trigger:
• Trigger timing
o For table: BEFORE, AFTER
o For view: INSTEAD OF
• Trigger event: INSERT, UPDATE, OR DELETE
• Table name: On table, view
• Trigger Type: Row or statement
• When clause: Restricting condition
• Trigger body: PL/SQL block
“Before triggers” execute the trigger body before the triggering DML event on a table. These are
frequently used to determine whether that triggering statement should be allowed to complete.
This situation enables you to eliminate unnecessary processing of the triggering statement and it
eventual rollback in cases where an exception is raised in the triggering action.
“After triggers” are used when the triggering statement is to be completed before the triggering
action and to perform a different action on the same triggering statement if a BEFORE trigger is
already present.
“Instead of Triggers” are used to provide a transparent way of modifying views that cannot be
modified directly through SQL DML statements because the view is not inherently modifiable.
You can write INSERT, UPDATE, and DELETE statements against the view. The INSTEAD OF
trigger works invisibly in the background performing the action coded in the trigger body directly
on the underlying tables.
Trigger Components:
o Statement: The trigger body executes once for the triggering event. This is the default. A
statement trigger fires once, even if no rows are affected at all.
o Row: The trigger body executes once for each row affected by the triggering event. A row
trigger is not executed if the triggering event affects no rows.
Trigger Body:
The trigger body is a PL/SQL block or a call to a procedure.
Syntax:
Example: To write a TRIGGER to ensure that DEPT TABLE does not contain duplicate of
null values in DEPTNO column.
INPUT
CREATE OR RELPLACE TRIGGER trig1 before insert on dept for each row
DECLARE
a number;
BEGIN
if(:new.deptno is Null) then
raise_application_error(-20001,'error::deptno cannot be null');
else
select count(*) into a from dept where deptno=:new.deptno;
if(a=1) then
raise_application_error(-20002,'error:: cannot have duplicate deptno');
end if;
end if;
END;
RESULT:
SQL> @trigger
Trigger created.
SQL> select * from dept;
DEPTNO DNAME LOC
--------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> insert into dept values(&deptnp,'&dname','&loc');
Enter value for deptnp: null
Enter value for dname: marketing
Enter value for loc: hyd
old 1: insert into dept values(&deptnp,'&dname','&loc')
new 1: insert into dept values(null,'marketing','hyd')
insert into dept values(null,'marketing','hyd')
ERROR at line 1:
ORA-20001: error::deptno cannot be null
ORA-06512: at "SCOTT.TRIG1", line 5
ORA-04088: error during execution of trigger 'SCOTT.TRIG1'
SQL> /
Enter value for deptnp: 10
Enter value for dname: manager
Enter value for loc: hyd
old 1: insert into dept values(&deptnp,'&dname','&loc')
new 1: insert into dept values(10,'manager','hyd')
insert into dept values(10,'manager','hyd')
ERROR at line 1:
ORA-20002: error:: cannot have duplicate deptno
ORA-06512: at "SCOTT.TRIG1", line 9
ORA-04088: error during execution of trigger 'SCOTT.TRIG1'
SQL> /
Enter value for deptnp: 50
Enter value for dname: MARKETING
Enter value for loc: HYDERABAD
old 1: insert into dept values(&deptnp,'&dname','&loc')
new 1: insert into dept values(50,'MARKETING','HYDERABAD')
1 row created.
SQL> select * from dept;
DEPTNO DNAME LOC
--------- -------------- -------------
INTRODUCTION TO PL/SQL
PL/SQL is the procedural extension to SQL with design features of programming languages. Data
manipulation and query statements of SQL are included within procedural units of code.
Benefits of PL/SQL:
PL/SQL can improve the performance of an application. The benefits differ depending on the
execution environment:
• PL/SQL can be used to group SQL statements together within a single block and to send
the entire block to the server in a single call thereby reducing networking traffic. Without
PL/SQL, the SQL statements are sent to the Oracle server one at a time. Each SQL
statement results in another call to the Oracle server and higher performance overhead. In a
network environment, the overhead can become significant.
• PL/SQL can also operate with Oracle server application development tools such as Oracle
forms and Oracle reports.
Every unit of PL/SQL comprises one or more blocks. These blocks can be entirely separate or
nested one within another. The basic units (procedures, functions, and anonymous blocks) that
make up a PL/SQL program are logical blocks which can contain any number of nested sub-
blocks. Therefore one block can represent a small part of another block, which in turn can be part
of the whole unit of code.
Identifiers/Variables:
In PL/SQL, you can use identifiers to do the following:
• Declare variables, cursors, constants and exceptions and then use them in SQL and
procedural statements.
• Declare variables belonging to scalar, reference, composite and large object (LOB) data
types.
• Declare variables dynamically based on the data structure of tables and columns in the
database.
Errors:
• Process Oracle server error with exception-handling routines.
• Declare user-defined error conditions and process them with exception-handling routines.
Example:
DECLARE
v_variable VARCHAR2(5);
BEGIN
SELECT column_name
INTO v_variable
FROM table_name;
EXCEPTION
WHEN exception_name THEN
-
-
-
END;
Anonymous:
- No name.
- Starts with DECLARE statement.
Procedure:
- No return.
- PROCEDURE name IS
Function:
- Returns a value
- FUNCTION name RETURN data-type IS
Programming Constructs:
- Declaring Variables:
o Identifier [CONSTANT] data-type [NOT NULL]
[:= | DEFAULT expr];
- Assignment:
o Identifier := expr;
- IF Statement:
o IF condition THEN
Statements;
[ELSE IF condition THEN
Statements;]
[ELSE
Statements;]
END IF;
- CASE Statement:
o CASE selector
WHEN expression1 THEN result1
WHEN expression2 THEN result2
.
.
.
WHEN expression THEN resultn
[ELSE resultn1;]
END;
- BASIC Loops:
o LOOP
Statement 1;
.
.
.
EXIT [WHEN condition];
END LOOP;
- WHILE Statement:
o WHILE condition LOOP
Statement1;
.
.
.
END LOOP;
- FOR Statement:
o FOR counter IN [REVERSE]
Lower_bound..upper_bound LOOP
Statement1;
.
.
.
END LOOP;
declare
a number;
d number:=0;
sum1 number:=0;
begin
a:=&a;
while a>0
loop
d:=mod(a,10);
sum1:=sum1+d;
a:=trunc(a/10);
end loop;
dbms_output.put_line('sum is'|| sum1);
end;
OUTPUT:
SQL> @ SUMOFDIGITS.sql
16 /
Enter value for a: 564
old 7: a:=&a;
new 7: a:=564;
sum is15
declare
a number(10);
b number(10);
begin
a:=&a;
b:=&b;
dbms_output.put_line('THE PREV VALUES OF A AND B WERE');
dbms_output.put_line(a);
dbms_output.put_line(b);
a:=a+b;
b:=a-b;
a:=a-b;
dbms_output.put_line('THE VALUES OF A AND B ARE');
dbms_output.put_line(a);
dbms_output.put_line(b);
end;
OUTPUT:
SQL> @ SWAPPING.SQL
17 /
Enter value for a: 5
old 5: a:=&a;
new 5: a:=5;
Enter value for b: 3
old 6: b:=&b;
new 6: b:=3;
THE PREV VALUES OF A AND B WERE
5
3
THE VALUES OF A AND B ARE
3
5
declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=&c;
if a=b and b=c and c=a then
dbms_output.put_line('ALL ARE EQUAL');
elsif a>b and a>c then
dbms_output.put_line('A IS GREATER');
elsif b>c then
dbms_output.put_line('B IS GREATER');
else
dbms_output.put_line('C IS GREATER');
end if;
end;
OUTPUT:
SQL> @ GREATESTOF3.sql
17 /
Enter value for a: 8
old 6: a:=&a;
new 6: a:=8;
Enter value for b: 9
old 7: b:=&b;
new 7: b:=9;
Enter value for c: 7
old 8: c:=&c;
new 8: c:=7;
B IS GREATER
declare
java number(10);
dbms number(10);
co number(10);
se number(10);
es number(10);
ppl number(10);
total number(10);
avgs number(10);
per number(10);
begin
dbms_output.put_line('ENTER THE MARKS');
java:=&java;
dbms:=&dbms;
co:=&co;
se:=&se;
es:=&es;
ppl:=&ppl;
total:=(java+dbms+co+se+es+ppl);
per:=(total/600)*100;
if java<40 or dbms<40 or co<40 or se<40 or es<40 or ppl<40 then
dbms_output.put_line('FAIL');
if per>75 then
dbms_output.put_line('GRADE A');
elsif per>65 and per<75 then
dbms_output.put_line('GRADE B');
elsif per>55 and per<65 then
dbms_output.put_line('GRADE C');
else
dbms_output.put_line('INVALID INPUT');
end if;
dbms_output.put_line('PERCENTAGE IS '||per);
dbms_output.put_line('TOTAL IS '||total);
end;
OUTPUT:
SQL> @ GRADE.sql
31 /
Enter value for java: 80
old 12: java:=&java;
new 12: java:=80;
Enter value for dbms: 70
old 13: dbms:=&dbms;
new 13: dbms:=70;
Enter value for co: 89
old 14: co:=&co;
new 14: co:=89;
Enter value for se: 72
old 15: se:=&se;
new 15: se:=72;
declare
a number;
t number;
arm number;
d number;
begin
a:=&a;
t:=a;
arm:=0;
while t>0
loop
d:=mod(t,10);
arm:=arm+power(d,3);
t:=trunc(t/10);
end loop;
if arm=a then
dbms_output.put_line('given no is an armstrong no'|| a);
else
dbms_output.put_line('given no is not an armstrong no');
end if;
end;
OUTPUT:
SQL> @ ARMSTRONGNUM.sql
Enter value for a: 407
old 7: a:=&a;
new 7: a:=407;
given no is an armstrong no407
SQL> /
Enter value for a: 406
old 7: a:=&a;
new 7: a:=406;
given no is not an armstrong no
Introduction
Use Form Builder to simplify for the creation of data-entry screens, also known as Forms.
Forms are the applications that connect to a database, retrieve information requested by the
user, present it in a layout specified by Form designer, and allow the user to modify or add
information. Form Builder allows you to build forms quickly and easily.
In this Hands-On, you learn how to: Create a Data block for the “Customer” table, Create a
layout, Use “content” canvas, Use “execute query”, Navigate a table, Use next, previous
record, Enter query, Manipulate table’s record, Insert, Update, Delete and Save record.
Form Builder Tool
Open the "Form Builder" tool.
Welcome window
You will get the ‘Welcome to the Form Builder’ window. If you don’t want to get this
window anymore uncheck the ‘Display at startup’ box. You can start your work with any of
the following options:
· Use the data Block Wizard
· Build a new form manually
· Open an existing form
· Build a form based on a template
The default is ‘Use the data Block Wizard.’ If you want to build a new form manually, click
on "Cancel” or check ‘Build a new form manually’ and click ‘OK.’
Connect to database
In the ‘Object Navigator’ window, highlight "Database Objects." Go to the Main menu and
choose "File," then "Connect."
In the ‘Connect’ window, login in as “scott” password “tiger,” then click “CONNECT.”
Notice that the box next to ‘Database Objects’ is not empty anymore and it has a ‘+’ sign in
it. That will indicate that this item is expandable and you are able to see its entire objects.
Click on the ‘+’ sign next to the ‘Database Objects’ to expand all database schemas.
Create a Module
In the ‘Object Navigator’ window, highlight module1. This is a default name. Go to the Main
menu and choose “File,” select “Save as” to store the new object in the “iself” folder and
save it as customer data entry. "c:_de." In this example the ‘DE’ abbreviation stands for Data
Entry.
Create a Data Block
In the ‘Object Navigator’ window, highlight "Data Blocks,” and click on the "create” icon.
The ‘Create’ icon is in the vertical tool bar in the ‘Object Navigator’ window. It is a green ‘+’
sign. If you drag your cursor on the icon a tooltip will show ‘Create.’
New Data Block
In the ‘New Data Block’ window, choose the default option “Data Block Wizard” and click "OK."
Welcome Data Block
In the ‘Welcome Data Block Wizard’ window click on the “NEXT” icon.
Type of Data Block
Select the type of data block you would like to create by clicking on a radio button. Select the
default option ‘Table or View’ and then click “NEXT” again.
Selecting Tables
Click on “browse.” In the ‘Tables’ window, highlight the "cust11” table; then click "OK."
Selecting columns for the Data Block Wizard
To choose all columns, click on the two arrow signs in the ‘Data Block Wizard’ window. To
choose selected columns, click on the one arrow sign. And then select all columns, and click
“next.”
Layout Wizard
End of the Data Block Wizard and beginning of the Layout Wizard In the ‘Congratulations’
screen, use the default checkmark radio button (Create the data block, then call the Layout
Wizard), and click "Finish." You can also use the Data Block Wizard to modify your existing data
block. Simply select the data block in the Object Navigator and click the Data Block Wizard
toolbar button, or choose ‘Data Block wizard’ from the ‘Tools’ menu.
Welcome screen
In the ‘Welcome to the Layout Wizard’ window, click ”Next.”
Selecting canvas
In the ‘Layout Wizard’ window, select the "new canvas" option. Canvas is a place that you will
have your objects such as columns, titles, pictures, etc. If you have already had your canvas, select
the canvas and then click on the next. The following are different types of canvases: Content,
Stacked, Vertical Toolbar, Horizontal Toolbar, and Tab.
Think of the ‘Content’ canvas as one flat place to have all your objects. In the stacked canvas,you
can have multiple layers of objects and it is the same as the tab canvas. You use the vertical or
horizontal toolbar canvases for your push buttons. Check the different types of canvases by
clicking on the ‘down arrow’ box next to the ‘Type’ field. Select "content," then click “Next.”
Record layout
Type the "Frame Title" and click "next." Checkmark the ‘Display Scrollbar’ box when you use
multiple records or the ‘Tabular’ option.
Congratulation Screen
In the ‘Congratulations’ window, click "Finish." You will see the output layout screen. Make some
window adjustments and then run the form. To run the form, click on the ‘Run’ icon. The ‘Run’
icon is on the horizontal toolbar in the ‘CUSTOMER_DE’ canvas. The object module should be
compiled successfully before executing the Form.
Execute Query
Click on the "Execute Query" icon below the main menu. If you drag the cursor on the toolbar in
the ‘Forms Runtime’ window, a tooltip will be displayed and you see ‘Execute Query.’ So to
know all your option, drag your cursor to view all the icon descriptions.
Next Record
Click on the "Next Record" icon to navigate to the next record.
Previous Record
Click on the "Previous Record" icon to navigate to the previous record. This is an easy way to
navigate through the “Customer” table.
Enter Query
Click on the "Enter Query" icon to query selected records.
Insert Record
Click "Insert Record" to add new customer. All items on the forms will be blanked. You can either
type all the customer information or duplicate it from pervious record.
Duplicate Record
To duplicate the previous record, go to the main menu and select the ‘Record’ sub-menu. A drop
down menu will be displayed. Select the ‘Duplicate’ option in the sub-menu. Apply the changes.
Remember in this stage, your record was inserted but not committed yet.
Next and Previous Record
Click "next record" and "previous record" to navigate through the records and the one was added.
Save transactions
Click "Save" to commit the insert statement.
Delete Record
Click "Remove Record" to delete the record.
Lock a Record
You can also lock the record.
Exit from Form Runtime
Exit the FORM Runtime. If you have not committed any transaction, you will be prompted to
save changes. Click “YES” to save changes.
Click “OK” for acknowledgement.
Don’t forget to save the Form.
Object wizard
as desired.
Click “NEXT” again to go to the Template tab, and choose a template for your report. Your
report will inherit the template’s colors, fonts, line widths, and structure.
Use the default template and click “finish.”
Running a report
Now, you should have your output report on the screen.
Resize an object
Maximize the output report and format the report layout. To resize an object , select it and
drag its handler to the preferred size.
Move an object
To move an object, select and drag it while the cursor is on the object.
This is a simple report.
Navigate through the output
To navigate through the output report in the Report Editor - Live Pre-viewer, click on the
"next page" or "previous page" icon on the horizontal toolbar.
Do the same with the "first page" or "last page" icon.
Use the “zoom in” and “zoom out” icon to preview the report.
Know report’s functions
To know each icon functionalities, drag your cursor on it and a tooltip will display its
function.
Change Format Mask
To change the "format mask" of a column, the column should be selected. Then go to the
toolbar and click on the “$” icon, "add decimal place," and the “right justify” format to the all
currency columns (Todays Low, Todays High, and current price)
Select the “traded today” column, and click on the ‘,0’ icon (apply commas), and make it
right justify.
Also, you can change any attributes of field by opening its property palette. To open an
object’s property palette, right click on it and select the Property Palette option.
Right click on the "trade date" column and open its "property palette."
Change the date "Format Mask" property and make it “year 2000 complaint (MM-DD-RR).”
Creating reports
REFERENCES
Web-Sites:
www.otn.oracle.com
Database Systems Instructor: Prof. Samuel Madden Source: MIT Open Courseware
(http://ocw.mit.edu)
Books:
1. Database Management Systems, Korth & Sudharshan.
2. Database Management Systems, Raghuram Krishnan.
3. Database Management Systems, Elmasri & Navathe.
1. What is database?
A database is a logically coherent collection of data with some inherent meaning,
representing some aspect of real world and which is designed, built and populated with data
for a specific purpose.
2. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other
words it is general-purpose software that provides the users with the processes of defining,
constructing and manipulating the database for various applications.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. Advantages of DBMS?
-> Redundancy is controlled.
-> Unauthorised access is restricted.
-> Providing multiple user interfaces.
-> Enforcing integrity constraints.
-> Providing backup and recovery.
5. Disadvantage in File Processing System?
-> Data redundancy & inconsistency.
-> Difficult in accessing data.
-> Data isolation.
-> Data integrity.
-> Concurrent access is not possible.
-> Security Problems.
6. Describe the three levels of data abstraction?
The are three levels of abstraction:
-> Physical level: The lowest level of abstraction describes how data are stored.
-> Logical level: The next higher level of abstraction, describes what data are stored in
should persist even if the system crashes before all its changes are reflected on disk. This
property is called durability.
60. What do you mean by atomicity and aggregation?
Atomicity:
Either all actions are carried out or none are. Users should not have to worry about the effect
of incomplete transactions. DBMS ensures this by undoing the actions of incomplete
transactions.
Aggregation:
A concept which is used to model a relationship between a collection of entities and
relationships. It is used when we need to express a relationship among relationships.
61. What is a Phantom Deadlock?
In distributed deadlock detection, the delay in propagating local information might cause the
deadlock detection algorithms to identify deadlocks that do not really exist. Such situations
are called phantom deadlocks and they lead to unnecessary aborts.
62. What is a checkpoint and When does it occur?
A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can
reduce the amount of work to be done during restart in the event of subsequent crashes.
63. What are the different phases of transaction?
Different phases are
-> Analysis phase
-> Redo Phase
-> Undo phase
64. What do you mean by flat file database?
It is a database in which there are no programs or user access languages. It has no cross-file
capabilities but is user-friendly and provides user-interface management.
65. What is "transparent DBMS"?
It is one, which keeps its Physical Structure hidden from user.
66. Brief theory of Network, Hierarchical schemas and their properties
Network schema uses a graph data structure to organize records example for such a database
management system is CTCG while a hierarchical schema uses a tree data structure example
for such a system is IMS.
67. What is a query?
A query with respect to DBMS relates to user commands that are used to interact with a data
base. The query language can be classified into data definition language and data
manipulation language.
68. What do you mean by Correlated subquery?
Subqueries, or nested queries, are used to bring back a set of rows to be used by the parent
query. Depending on how the subquery is written, it can be executed once for the parent
query or it can be executed once for each row returned by the parent query. If the subquery is
executed for each row of the parent, this is called a correlated subquery.
A correlated subquery can be easily identified if it contains any references to the parent
subquery columns in its WHERE clause. Columns from the subquery cannot be referenced
anywhere else in the parent query. The following example demonstrates a non-correlated
subquery.
E.g. Select * From CUST Where '10/03/1990' IN (Select ODATE From ORDER Where
CUST.CNUM = ORDER.CNUM)
69. What are the primitive operations common to all record management systems?
Addition, deletion and modification.
70. Name the buffer in which all the commands that are typed in are stored
‘Edit’ Buffer
71. What are the unary operations in Relational Algebra?
PROJECTION and SELECTION.
72. Are the resulting relations of PRODUCT and JOIN operation the same?
No.
PRODUCT: Concatenation of every row in one relation with every row in another.
JOIN: Concatenation of rows from one relation and related rows from another.
73. What is RDBMS KERNEL?
Two important pieces of RDBMS architecture are the kernel, which is the software, and the
data dictionary, which consists of the system-level data structures used by the kernel to
manage the database
You might think of an RDBMS as an operating system (or set of subsystems), designed
specifically for controlling data access; its primary functions are storing, retrieving, and
securing data. An RDBMS maintains its own list of authorized users and their associated
privileges; manages memory caches and paging; controls locking for concurrent resource
usage; dispatches and schedules user requests; and manages space usage within its tablespace
structures.
74. Name the sub-systems of a RDBMS
I/O, Security, Language Processing, Process Control, Storage Management, Logging and
Recovery, Distribution Control, Transaction Control, Memory Management, Lock
Management
75. Which part of the RDBMS takes care of the data dictionary? How
Data dictionary is a set of tables and database objects that is stored in a special area of the
database and maintained exclusively by the kernel.
76. What is the job of the information stored in data-dictionary?
The information in the data dictionary validates the existence of the objects, provides access
to them, and maps the actual physical storage location.
77. Not only RDBMS takes care of locating data it also
determines an optimal access path to store or retrieve the data
76. How do you communicate with an RDBMS?
You communicate with an RDBMS using Structured Query Language (SQL)
78. Define SQL and state the differences between SQL and other conventional
programming Languages
SQL is a nonprocedural language that is designed specifically for data access operations on
normalized relational database structures. The primary difference between SQL and other
conventional programming languages is that SQL statements specify what data operations
should be performed rather than how to perform them.
79. Name the three major set of files on disk that compose a database in Oracle
There are three major sets of files on disk that compose a database. All the files are binary.
These are
-> Database files
-> Control files
-> Redo logs
The most important of these are the database files where the actual data resides. The control
files and the redo logs support the functioning of the architecture itself.
All three sets of files must be present, open, and available to Oracle for any data on the
database to be useable. Without these files, you cannot access the database, and the database
administrator might have to recover some or all of the database using a backup, if there is
one.
80. What is an Oracle Instance?
The Oracle system processes, also known as Oracle background processes, provide functions
for the user processes—functions that would otherwise be done by the user processes
themselves
Oracle database-wide system memory is known as the SGA, the system global area or shared
global area. The data and control structures in the SGA are shareable, and all the Oracle
background processes and user processes can use them.
The combination of the SGA and the Oracle background processes is known as an Oracle
instance
81. What are the four Oracle system processes that must always be up and running for
the database to be useable
The four Oracle system processes that must always be up and running for the database to be
useable include DBWR (Database Writer), LGWR (Log Writer), SMON (System Monitor),
and PMON (Process Monitor).
82. What are database files, control files and log files. How many of these files should a
database have at least? Why?
Database Files
The database files hold the actual data and are typically the largest in size. Depending on
their sizes, the tables (and other objects) for all the user accounts can go in one database file —but
that's not an ideal situation because it does not make the database structure very
flexible for controlling access to storage for different users, putting the database on different
disk drives, or backing up and restoring just part of the database.
You must have at least one database file but usually, more than one files are used. In terms of
accessing and using the data in the tables and other objects, the number (or location) of the
files is immaterial.
The database files are fixed in size and never grow bigger than the size at which they were
created Control Files
The control files and redo logs support the rest of the architecture. Any database must have at
least one control file, although you typically have more than one to guard against loss. The
control file records the name of the database, the date and time it was created, the location of
the database and redo logs, and the synchronization information to ensure that all three sets
of files are always in step. Every time you add a new database or redo log file to the
database, the information is recorded in the control files.
Redo Logs
Any database must have at least two redo logs. These are the journals for the database; the
redo logs record all changes to the user objects or system objects. If any type of failure
occurs, the changes recorded in the redo logs can be used to bring the database to a consistent
state without losing any committed transactions. In the case of non-data loss failure, Oracle
can apply the information in the redo logs automatically without intervention from the DBA.
The redo log files are fixed in size and never grow dynamically from the size at which they
were created.
83. What is ROWID?
The ROWID is a unique database-wide physical address for every row on every table. Once
assigned (when the row is first inserted into the database), it never changes until the row is
deleted or the table is dropped.
The ROWID consists of the following three components, the combination of which uniquely
identifies the physical storage location of the row.
-> Oracle database file number, which contains the block with the rows
-> Oracle block address, which contains the row
-> The row within the block (because each block can hold many rows)
The ROWID is used internally in indexes as a quick means of retrieving rows with a
particular key value. Application developers also use it in SQL statements as a quick way to
access a row once they know the ROWID
84. What is Oracle Block? Can two Oracle Blocks have the same address?
Oracle "formats" the database files into a number of Oracle blocks when they are first created
—making it easier for the RDBMS software to manage the files and easier to read data into
the memory areas.
The block size should be a multiple of the operating system block size. Regardless of the
block size, the entire block is not available for holding data; Oracle takes up some space to
manage the contents of the block. This block header has a minimum size, but it can grow.
These Oracle blocks are the smallest unit of storage. Increasing the Oracle block size can
improve performance, but it should be done only when the database is first created.
Each Oracle block is numbered sequentially for each database file starting at 1. Two blocks
can have the same block address if they are in different database files.
85. What is database Trigger?
A database trigger is a PL/SQL block that can defined to automatically execute for insert,
update, and delete statements against a table. The trigger can e defined to execute once for
the entire statement or once for every row that is inserted, updated, or deleted. For any one
table, there are twelve events for which you can define database triggers. A database trigger
can call database procedures that are also written in PL/SQL.
86. Name two utilities that Oracle provides, which are use for backup and recovery.
Along with the RDBMS software, Oracle provides two utilities that you can use to back up
and restore the database. These utilities are Export and Import.
The Export utility dumps the definitions and data for the specified part of the database to an
operating system binary file. The Import utility reads the file produced by an export,
recreates the definitions of objects, and inserts the data
If Export and Import are used as a means of backing up and recovering the database, all the
changes made to the database cannot be recovered since the export was performed. The best
you can do is recover the database to the time when the export was last performed.
87. What are stored-procedures? And what are the advantages of using them.
Stored procedures are database objects that perform a user defined operation. A stored
procedure can have a set of compound SQL statements. A stored procedure executes the SQL
commands and returns the result to the client. Stored procedures are used to reduce network
traffic.
88. How are exceptions handled in PL/SQL? Give some of the internal exceptions' name
PL/SQL exception handling is a mechanism for dealing with run-time errors encountered
during procedure execution. Use of this mechanism enables execution to continue if the error
is not severe enough to cause procedure termination.
The exception handler must be defined within a subprogram specification. Errors cause the
program to raise an exception with a transfer of control to the exception-handler block. After
the exception handler executes, control returns to the block in which the handler was defined.
If there are no more executable statements in the block, control returns to the caller.
User-Defined Exceptions
PL/SQL enables the user to define exception handlers in the declarations area of subprogram
specifications. User accomplishes this by naming an exception as in the following example:
ot_failure EXCEPTION;
In this case, the exception name is ot_failure. Code associated with this handler is written in
the EXCEPTION specification area as follows:
EXCEPTION
when OT_FAILURE then
out_status_code := g_out_status_code;
out_msg := g_out_msg;
The following is an example of a subprogram exception:
EXCEPTION
when NO_DATA_FOUND then
g_out_status_code := 'FAIL';
RAISE ot_failure;
Within this exception is the RAISE statement that transfers control back to the ot_failure
exception handler. This technique of raising the exception is used to invoke all user-defined
exceptions.
System-Defined Exceptions
Exceptions internal to PL/SQL are raised automatically upon error. NO_DATA_FOUND is a
system-defined exception. Table below gives a complete list of internal exceptions.
PL/SQL internal exceptions.
PL/SQL internal exceptions.
Exception Name Oracle Error
CURSOR_ALREADY_OPEN ORA-06511
DUP_VAL_ON_INDEX ORA-00001
INVALID_CURSOR ORA-01001
INVALID_NUMBER ORA-01722
LOGIN_DENIED ORA-01017
NO_DATA_FOUND ORA-01403
NOT_LOGGED_ON ORA-01012
PROGRAM_ERROR ORA-06501
STORAGE_ERROR ORA-06500
TIMEOUT_ON_RESOURCE ORA-00051
TOO_MANY_ROWS ORA-01422
TRANSACTION_BACKED_OUT ORA-00061
VALUE_ERROR ORA-06502
ZERO_DIVIDE ORA-01476
In addition to this list of exceptions, there is a catch-all exception named OTHERS that traps
all errors for which specific error handling has not been established.