DBMS Lab Manual (Final)
DBMS Lab Manual (Final)
1|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
2|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
SYLLABUS
4|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Web References
1. www.oracle-developer.net
2. www.oracle.com/DBA
COs/POs/PSOs Mapping
Program Specific
Program Outcomes(POs)
COs Outcomes(PSOs)
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
1 3 3 2 3 2 2 1 - 2 1 - 2 2 3 2
2 3 2 3 3 2 2 1 - 2 1 - - 3 3 3
3 3 3 3 3 2 2 2 - 2 1 - - 3 2 3
4 3 2 3 3 2 2 1 - 2 1 - - 3 3 3
5 3 3 3 3 2 2 2 - 2 1 - - 3 2 3
Evaluation Method
Marks 15 5 5 15 10 50 100
5|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Each practical which student is performing in the lab should have the following details:
a) Program Name
b) Aim
c) Table Description or Schema
d) Queries / PL/SQL Code
e) Output
f) Result
g) Viva questions
6|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Conduction of Practical 15
Record Work 05
Viva Voce 05
Model Practical Examination 15
Attendance 10
Total 50
Queries/PL/SQL Code 20
Viva Voice 10
Total 50
NOTE:
Internal marks (50 marks) + External marks (50 marks) = Total marks given to the students (100 Marks)
Experiments given to perform can be from any section of the lab.
The pattern of Model Practical Examination will be similar to the End Semester practical Examination.
7|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
TABLE OF INDEX
EX.NO EXERCISE NAME PAGE NO.
SQL
1. SQL Basic Commands 22
2. Data Definition Language 24
2.a DDL without Constraint 26
2.b DDL with Constraint 29
3. Data Manipulation Language 34
4. Data Query Projection Statements 40
5. Data Query Selection Statements 43
6. Aggregate Functions 47
7. SQL Joins 50
8. Built in Functions 57
9. Set Operations 61
10. Nested Queries 65
11. Views 69
12. Transaction Control Language 73
13. Data Control Language 77
PL/SQL
14. Simple PL/SQL programs 81
15. Cursor 84
16. Triggers 87
Content beyond the Syllabus
17 Student Information System using C#.net and Oracle Database 93
18 NoSQL Database Operations: CRUD (Library) : MongoDB 101
8|Page
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Oracle Database
11.1.0.6 Active Data Guard, Secure Files, Exadata
11g Release 1
Real Application Testing, Database Vault, Online Indexing, Advanced
Oracle Database
10.2.0.1 Compression, Data Guard Fast-Start Failover, Transparent Data
10g Release 2
Encryption
Oracle Database Automated Database Management, Automatic Database Diagnostic
10.1.0.2
10g Release 1 Monitor, Grid infrastructure, Oracle ASM, Flashback Database
Oracle9i Database
9.2.0.1 Advanced Queuing, Data Mining, Streams, Logical Standby
Release 2
Oracle9i Database 9.0.1.0 Oracle Real Application Clusters (RAC), Oracle XML DB
Oracle8i Database 8.1.5.0 Native internet protocols and Java, Virtual Private Database
Oracle8 Database 8.0.3 Recovery Manager, Partitioning. First version available for Linux.
Oracle 7.3 7.3.0 Object-relational database
Oracle 7.2 7.2.0 Shared Server, XA Transactions, Transparent Application Failover
Oracle 7.1 7.1.0 Parallel SQL Execution. First version available for Windows NT.
PL/SQL stored procedures, Triggers, Distributed 2-phase commit,
Oracle7 7.0.12
Shared Cursors, Cost-Based Optimizer
Oracle 6.2 6.2.0 Oracle Parallel Server
Row-level locking, scalability / performance, online backup and
Oracle v6 6.0.17 recovery, B*Tree indexes, PL/SQL executed from compiled programs
(C etc). First version available for Novell Netware 386
5.0.22 Support for client/server computing and distributed database systems.
Oracle v5
(5.1.17) First version available for OS/2. Correlated sub-queries
Oracle v4 4.1.4.0 Multiversion read consistency. First version available for MS-DOS
Concurrency control, data distribution, and scalability. Re-written in C
Oracle v3 3.1.3
for portability to other operating systems, including UNIX
First commercially available SQL RDBMS. Basic SQL queries, simple
join and CONNECT BY joins. Written in assembly language for
Oracle v2 2.3
the PDP-11 to run in 128KB of RAM Ran on PDP-11 and VAX/VMS
in PDP-11 compatibility mode.
10 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
SQL Overview
SQL (Structured Query Language) is a standardized language used for managing and manipulating
relational databases. It allows users to perform various operations on the data stored in a database, such as
querying, updating, inserting, and deleting data.
History of SQL
• 1970: Dr. Edgar F. Codd, a computer scientist at IBM, proposed the relational model for databases
in his seminal paper, "A Relational Model of Data for Large Shared Data Banks."
• 1974-1975: SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce. Initially
named SEQUEL (Structured English Query Language), it was designed to manipulate and retrieve
data stored in IBM's original quasi-relational database management system, System R.
• 1979: Relational Software, Inc. (now Oracle Corporation) introduced the first commercially
available implementation of SQL, Oracle V2.
• 1986: The American National Standards Institute (ANSI) adopted SQL as the standard relational
database query language. The International Organization for Standardization (ISO) followed suit in
1987.
• 1992: SQL-92 (or SQL2), an expanded version of the SQL standard, was released.
• 1999 and Beyond: Subsequent versions, such as SQL: 1999 (SQL3), SQL:2003, SQL:2008,
SQL:2011, and SQL:2016, introduced additional features and improvements, including support for
XML, triggers, recursive queries, and more.
Purpose of SQL
1. Data Querying: Retrieve specific data from one or more tables.
2. Data Manipulation: Insert, update, and delete data.
3. Data Definition: Create and modify database structures such as tables, indexes, and views.
4. Data Control: Control access to data and database objects using permissions and roles.
5. Transaction Control: Manage transactions to ensure data integrity.
Applications of SQL
1. Business Intelligence and Analytics:
o Retrieve and analyze large datasets to generate business insights.
o Use aggregate functions to compute metrics like sums, averages, and counts.
2. Web Development:
o Back-end data management for web applications.
o Retrieve and display dynamic content based on user input.
3. Database Administration:
o Create and manage database structures.
o Perform backup and recovery operations.
o Monitor and optimize database performance.
4. Data Warehousing:
o Extract, transform, and load (ETL) processes for data warehousing.
o Manage large-scale data storage and retrieval.
5. Application Development:
o Embed SQL queries in application code to interact with databases.
o Use SQL in stored procedures, triggers, and functions to automate database operations.
11 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
13 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
14 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
16 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
17 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
DBMS_OUTPUT.PUT_LINE('Empl
oyee ID: ' || v_employee_id);
END;
LOCK TABLE
Locks a table or
table_name IN LOCK TABLE employees IN
39. LOCK TABLE table partitions in
{SHARE|EXCLUSIVE} EXCLUSIVE MODE;
a specified mode.
MODE;
COMMENT ON
TABLE table_name IS COMMENT ON TABLE employees
'comment'; IS 'Employee details';
Adds comments to
40. COMMENT COMMENT ON COMMENT ON COLUMN
a table or column.
COLUMN employees.salary IS 'Employee
table_name.column_nam salary in USD';
e IS 'comment';
SELECT ROWID, first_name,
Represents the SELECT ROWID,
last_name
41. ROWID unique address of column1, column2
FROM employees
a row in a table. FROM table_name;
WHERE department_id = 10;
CREATE
CREATE MATERIALIZED VIEW
MATERIALIZED
Stores the result of emp_mv AS
VIEW view_name AS
Materialized a query physically SELECT department_id, COUNT(*)
42. SELECT column1,
Views for performance AS emp_count
column2, ...
improvement. FROM employees
FROM table_name
GROUP BY department_id;
WHERE condition;
Partitioning CREATE TABLE CREATE TABLE sales (
Types: table_name ( sale_id NUMBER,
• Range Divides a table column1 datatype, sale_date DATE,
Partitioning into smaller, more column2 datatype, amount NUMBER
43. • List manageable ... ) PARTITION BY RANGE
Partitioning
pieces. ) PARTITION BY (sale_date) (
• Hash
Partitioning RANGE (column) ( PARTITION p1 VALUES LESS
• Composite PARTITION p1 THAN (TO_DATE('2021-01-01',
18 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
19 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
20 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
STRUCTURED QUERY
LANGUAGE (SQL)
21 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 1
SQL Basic Commands
Create a Employee database and perform the following SQL basic commands.
• Create the emp table with columns for employee number, name, date of birth, salary, and
designation.
• Insert a new employee with employee number 100, name 'Ram', date of birth '1996-04-21',
salary 50000, and designation 'Manager'.
• Update the salary of all employees by adding 1000
• Delete the record of the employee with employee number 100
//Create table
CREATE TABLE emp
(
empno NUMBER,
empname VARCHAR2(255),
DOB DATE,
salary NUMBER,
designation VARCHAR2(20)
);
//Describe Table
SQL> desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NUMBER
EMPNAME VARCHAR2(255)
DOB DATE
SALARY NUMBER
DESIGNATION VARCHAR2(20)
// Insert values
INSERT INTO emp(empno,empname, DOB, designation) VALUES(100,'Ram', ‘21-Apr-1996’,
50000,'Manager');
INSERT INTO emp(empno,empname, DOB, designation) VALUES(101,'Meera', ‘20-July-1994’,
25000,'Clerk');
22 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// Display values
SELECT * FROM emp;
EMPNO EMPNAME DOB SALARY DESIGNATION
100 Ram 21-Apr-1996 50000 Manager
101 Meera 20-July-1994 25000 Clerk
// Modify values
UPDATE emp SET salary = salary + 1000;
// Delete values
DELETE FROM emp WHERE empno = 100;
Result:
Thus all the above basic SQL commands have been executed successfully and the output was
verified.
23 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 2
DDL (Data Definition Language) consists of statements used to define, manage, and manipulate
database objects such as tables, indexes, views, sequences, and so on. These statements enable
database administrators and developers to create, alter, and drop database objects as needed.
DDL Statements
• CREATE TABLE
• ALTER TABLE
• DROP TABLE
1. CREATE Statement
2. Alter Table
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table
a. To Add a column
3. Drop Table
The TRUNCATE TABLE statement is used to remove all records from a table, but it does not delete the
table itself.
25 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
(Without constraint)
- Table Created
a. ADD
b. MODIFY
// To alter the table emp by modifying the size of the attribute department
ALTER TABLE emp MODIFY department VARCHAR2 (100);
c. DROP
// To alter the table emp by deleting the attribute department
ALTER TABLE emp DROP(department);
d. RENAME
// To alter the table emp by renaming the attribute empno to emplno
ALTER TABLE emp RENAME COLUMN empno TO emplno;
27 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Table Dropped
DESC empnew;
Object to be described could not be found.
Result:
Thus all the above DDL SQL commands have been executed successfully and the output was verified.
28 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
(With constraint)
Constraints Types
• NOT NULL
• UNIQUE
• PRIMARY KEY
• FOREIGN KEY (REFERENCE KEY)
• CHECK
• DEFAULT
1. CREATE THE TABLE
A. ADD
//To alter the table student by adding new primary key constraint to the examID attribute
Table Altered
30 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
B. MODIFY
//To alter the table student by modifying not null constraint to studentid column
Table altered.
//To alter the table student by modifying defualt constraint to Total column as 0
Table altered.
31 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
C. RENAME
// To alter the table student by renaming constraint for primary key examid column from pr to ps
Table altered.
D. DROP
32 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Table altered.
//To alter the table student by adding new unique key constraint to the examID attribute
Table altered.
Result:
Thus all the above DDL SQL commands have been executed successfully and the output was
verified.
33 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 3
DATA MANIPULATION LANGUAGE (DML)
DML (Data Manipulation Language) statements are used to manipulate data within tables. These
statements allow users to insert, update, delete, and retrieve data from database tables.
DML Statements
• Insert into
• Update
• Delete
1. Insert into
a. Direct Substitution
2. Update
Syntax
UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value;
3. Delete Query
Syntax
34 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
1. INSERT
Direct substitution
1 row created.
1 row created.
1 row created.
1 row created.
35 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
INSERT INTO exam(examid, studentid, department, mark1, mark2, mark3, mark4, mark5)
VALUES (2222,101,'IT',98,87,83,99,87);
Macro Substitution
INSERT INTO exam VALUES (&examid, &studentid, &department, &mark1, &mark2, mark3, &mark4,
&mark5)
Enter the value for examid: 5555
Enter the value for studentid: 106
Enter the value for department: CSE
Enter the value for mark1: 82
Enter the value for mark2: 85
Enter the value for mark3: 87
Enter the value for mark4: 91
Enter the value for mark5: 85
36 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
2. UPDATE
37 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
EXAMID STUDENTID DEPARTMENT MARK1 MARK2 MARK3 MARK4 MARK5 TOTAL AVERAGE
GRADE
2222 101 IT 98 87 83 99 87 454 90.8 -
- -
3333 104 IT 99 82 84 89 100 454 90.8 -
- -
4444 108 IT 92 85 83 91 87 438 87.6 -
- -
5555 106 CSE 82 85 87 91 85 430 86 -
- -
//To set the grade in the table exam
EXAMID STUDENTID DEPARTMENT MARK1 MARK2 MARK3 MARK4 MARK5 TOTAL AVERAGE
GRADE
2222 101 IT 98 87 83 99 87 454 90.8
A
3333 104 IT 99 82 84 89 100 454 90.8
A
4444 108 IT 92 85 83 91 87 438 87.6
B
5555 106 CSE 82 85 87 91 85 430 86
B
38 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
3. DELETE
EXAMID STUDENTID DEPARTMENT MARK1 MARK2 MARK3 MARK4 MARK5 TOTAL AVERAGE
GRADE
3333 104 IT 99 82 84 89 100 454 90.8
A
4444 108 IT 92 85 83 91 87 438 87.6
B
5555 106 CSE 82 85 87 91 85 430 86
B
//To inserted the same record in table exam for further use
EXAMID STUDENTID DEPARTMENT MARK1 MARK2 MARK3 MARK4 MARK5 TOTAL AVERAGE
GRADE
2222 101 IT 98 87 83 99 87 454 90.8
A
3333 104 IT 99 82 84 89 100 454 90.8
A
4444 108 IT 92 85 83 91 87 438 87.6
B
5555 106 CSE 82 85 87 91 85 430 86
B
Result:
Thus all the above DML SQL commands have been executed successfully and the output was
verified.
39 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex. No: 4
DATA QUERY PROJECTION STATEMENTS
Data query projection refers to the process of selecting specific columns or expressions from tables or
views. Projection statements are primarily achieved using the SELECT statement, which allows you to
specify the columns or expressions you want to retrieve from the database.
DESC student;
40 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
2. SELECT MULTICOLUMN
// To display the college of the student from the table student by avoiding repeated values.
COLLEGE
MEC
MIT
IIT
SMVEC
41 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
SNAME||STUDENTID
RUPESH101
BALA102
HEMESH104
SAIVAISHNAVI106
RISHA108
// To display the records from the table student who belongs to mec college.
// To display the student id and student name from the table student who belongs to IIT college
STUDENTID SNAME
102 BALA
104 HEMESH
// To display the student name and department from the table student who belongs to 5th sem.
SNAME DEPARTMENT
RUPESH IT
HEMESH IT
SAI VAISHNAVI CSE
RISHA IT
Result:
Thus all the above Data Query Projection SQL commands have been executed successfully and the
output was verified.
42 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex. No: 5
DATA QUERY SELECTION STATEMENT
Data query selection involves using SQL (Structured Query Language) to retrieve specific data from one or
more tables. The primary statement used for data query selection is the SELECT statement, which allows
you to specify the columns to retrieve, the tables to retrieve them from, and any conditions that filter the
rows returned.
SELECTION COMMANDS
• Between…and
• In
• Not in
• Like
• Relational Operators
• Logical Operators
DESC student;
43 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select
// To display the student id, student name and department of the student whose the semester in
between 5 and 6
// To display the student id, student name and department of the student whose in CSE and IT
department
44 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// To display the student id, student name and department of the student whose not in CSE
department
// To display the student id and student name of the student whose name starts letters 'R' from the
table student
STUDENTID SNAME
101 RUPESH
108 RISHA
// To display the student id and student name of the student whose name end with 'H' from the table
student
STUDENTID SNAME
101 RUPESH
104 HEMESH
// To display the student id and student name of the student whose name has letters 'sh' from the
table
student
STUDENTID SNAME
101 RUPESH
104 HEMESH
106 VAISHU
108 RISHA
45 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// To display the student id, student name of the student whose the student id greater than 105
STUDENTID SNAME
106 SAIVAISHNAVI
108 RISHA
// To display the student id, student name of the student whose the student id greater than 105 and cse
department
SELECT studentid, sname FROM student WHERE studentid > 105 AND department=’CSE’;
STUDENTID SNAME
106 SAIVAISHNAVI
Result:
Thus all the above Data Query Selection SQL commands have been executed successfully and the
output was verified.
46 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Aggregate functions are SQL functions that perform a calculation on a set of values and return a single
value. These functions are commonly used with SELECT statements in conjunction with the GROUP BY
clause to summarize data across rows.
➢ Order By
➢ Group By
➢ Aggregate Functions : MAX, MIN, SUM, AVG, COUNT
DESC student;
1. ORDER BY
// To display the department, sem and student name from the table student based on department in
ascending order.
// To display the department, sem and student name from the table student based on department in
descending order.
SELECT department, sem, sname FROM student ORDER BY department DESC, sem DESC, sname
DESC;
2. GROUP BY
DEPARTMENT SUM_DEPARTMENT
CSE 430
IT 1346
48 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
3. AGGREGATE FUNCTIONS
STUDENTS_REGISTERED
RANK_1
90.8
LAST_RANK
86
DEPARTMENT SUM_DEPARTMENT
CSE 430
IT 1346
DEPARTMENT AVERAGE
IT 448.66667
CSE 430
Result:
Thus all the above Aggregate function SQL commands has been executed successfully and the
output were verified.
49 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 7
SQL JOINS
Joins are used to combine rows from two or more tables based on a related column between them.
Joins allow you to retrieve data that spans multiple tables, providing a way to link information
together based on common attributes or relationships. Oracle supports different types of joins,
including inner joins, outer joins (left outer join, right outer join, full outer join), cross joins, and self
joins.
Join Types
1. INNER JOIN
2. OUTER JOIN
a. LEFT OUTER JOIN
b. RIGHT OUTER JOIN
c. FULL OUTER JOIN
3. SELF JOIN
4. EQUI JOIN
5. NON EQUI JOIN
// INNER JOIN
SELECT *
FROM cseitstudent
INNER JOIN Placement
ON cseitstudent.studentID=placement.StudentID;
SELECT *
FROM cseitstudent
LEFT OUTER JOIN placement
ON cseitstudent.studentID=placement.studentID;
52 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
SELECT *
FROM cseitstudent
RIGHT OUTER JOIN placement
ON cseitstudent.studentID=placement.studentID;
53 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
SELECT *
FROM cseitstudent
FULL OUTER JOIN placement
ON cseitstudent.studentID=placement.studentID;
//SELF JOIN
//TABLE CREATION
//EQUI JOIN
55 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
STUDENTID SNAME
105 eshwar
105 eshwar
105 eshwar
104 nirmal
104 nirmal
103 sheela
Result:
Thus all the above Joins SQL commands have been executed successfully and the output was
verified.
56 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 8
BUILT IN FUNCTIONS
Built-in functions provide a wide range of capabilities to manipulate and operate on data within SQL
queries. These functions can be categorized into several types based on their purposes, including string
functions, numeric functions, date functions, conversion functions, and aggregate functions.
DUAL TABLE:
The DUAL table is a special one-row, one-column table present by default. It serves a variety of purposes,
primarily acting as a placeholder for performing calculations or querying system-level functions without
needing to specify an actual table. Here’s a detailed explanation of the DUAL table and its usage:
1. String Functions: String functions in Oracle are used to manipulate character strings, such as extracting
substrings, concatenating strings, converting case, and trimming spaces.
TRIM: Removes leading or trailing characters (or spaces by default) from a string.
SELECT TRIM(' hello ') AS result FROM dual; -- Outputs 'hello'
57 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
INSTR: The INSTR function searches for a substring within a string and returns its starting position.
SELECT INSTR('Hello World', 'World') AS result FROM dual; -- Outputs 7
REPLACE: The REPLACE function replaces occurrences of a substring within a string with another
substring.
SELECT REPLACE('Hello World', 'World', 'Universe') AS result FROM dual; -- Outputs 'Hello Universe'
INITCAP: The INITCAP function capitalizes the first letter of each word in a string and converts all
other letters to lowercase.
SELECT INITCAP('hello world') AS result FROM dual; -- Outputs 'Hello World'
LPAD and RPAD: These functions pad a string with a specified character (or space by default) to
reach a desired length.
SELECT LPAD('Hello', 10, '*') AS result FROM dual; -- Outputs '*****Hello'
SELECT RPAD('Hello', 10, '*') AS result FROM dual; -- Outputs 'Hello*****'
LTRIM and RTRIM: These functions remove leading (left) or trailing (right) characters (or spaces
by default) from a string.
SELECT LTRIM(' Hello ') AS result FROM dual; -- Outputs 'Hello '
SELECT RTRIM(' Hello ') AS result FROM dual; -- Outputs ' Hello'
ASCII and CHR: ASCII: Returns the ASCII value of the first character in a string.
SELECT ASCII('A') AS result FROM dual; -- Outputs 65
TRANSLATE: The TRANSLATE function replaces characters in a string with specified characters.
SELECT TRANSLATE('Hello', 'elo', 'abc') AS result FROM dual; -- Outputs 'Habbc'
2. Numeric Functions: Numeric functions in Oracle are used to perform operations on numeric data types,
such as rounding numbers, calculating absolute values, and generating random numbers.
58 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
CEIL: The CEIL function returns the smallest integer greater than or equal to a specified number.
SELECT CEIL(3.14) AS result FROM dual; -- Outputs 4
FLOOR: The FLOOR function returns the largest integer less than or equal to a specified number.
SELECT FLOOR(3.14) AS result FROM dual; -- Outputs 3
TRUNC: The TRUNC function truncates a number to a specified number of decimal places.
SELECT TRUNC(3.14159, 2) AS result FROM dual; -- Outputs 3.14 (truncates to 2 decimal places)
SIGN: The SIGN function returns the sign of a number as -1 for negative, 0 for zero, and 1 for
positive.
SELECT SIGN(-10) AS result FROM dual; -- Outputs -1
GREATEST: The GREATEST function returns the greatest value from a list of expressions.
SELECT GREATEST(10, 20, 15, 5) AS result FROM dual; -- Outputs 20 (returns the largest value)
LEAST: The LEAST function returns the smallest value from a list of expressions.
SELECT LEAST(10, 20, 15, 5) AS result FROM dual; -- Outputs 5 (returns the smallest value)
EXP: The EXP function returns e raised to the power of a specified number.
SELECT EXP(1) AS result FROM dual; -- Outputs approximately 2.71828 (e raised to the power of 1)
3. Date Functions: Date functions in Oracle are used for manipulating date and time values, such as
extracting parts of a date, calculating differences between dates, and formatting dates.
LAST_DAY: The LAST_DAY function returns the last day of the month for a given date.
SELECT LAST_DAY(SYSDATE) AS result FROM dual; -- Returns the last day of the current month
NEXT_DAY: The NEXT_DAY function finds the next specified day of the week after a given date.
SELECT NEXT_DAY(SYSDATE, 'FRIDAY') AS result FROM dual; -- Finds the next Friday after the
current date
EXTRACT: The EXTRACT function retrieves a specific part (year, month, day, hour, minute, etc.)
from a date value.
SELECT EXTRACT(YEAR FROM hire_date) AS hire_year FROM employees; -- Extracts the year from
hire_date column
TRUNC: The TRUNC function truncates a date to a specified unit (day, month, year, etc.), effectively
removing the time portion.
SELECT TRUNC(SYSDATE, 'MM') AS start_of_month FROM dual; -- Truncates current date to start of
the month
SELECT TRUNC(SYSDATE, 'YYYY') AS start_of_year FROM dual; -- Truncates current date to start of
the year
Result:
Thus all the above Built in commands in SQL have been executed successfully and the output was
verified.
60 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 9
SET OPERATIONS
Set operations allow you to combine the results of two or more queries into a single result set. Oracle
supports several set operations: UNION, UNION ALL, INTERSECT, and MINUS. These operations
are useful for combining and comparing datasets from multiple queries.
• UNION: The UNION operator combines the results of two or more queries and removes duplicate
rows from the result set.
• UNION ALL: The UNION ALL operator also combines the results of two or more queries,
including all rows (including duplicates) from each query.
• INTERSECT: The INTERSECT operator returns rows that are common between the results of two
queries. It effectively performs an intersection of two result sets.
• MINUS: The MINUS operator returns rows from the first query that are not present in the result of
the second query. It effectively performs a set difference operation.
// Consider the tables Student
DESC student;
61 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
DESC exam;
Column Data Type Length Precision Scale Primary Key Nullable Default Comment
EXAMID NUMBER 22 - - - - - -
STUDENTID NUMBER 22 - - - - - -
DEPARTMENT CHAR 5 - - - - - -
MARK1 NUMBER 22 - - - - - -
MARK2 NUMBER 22 - - - - - -
MARK3 NUMBER 22 - - - - - -
MARK4 NUMBER 22 - - - - - -
MARK5 NUMBER 22 - - - - - -
TOTAL NUMBER 22 - - - - - -
AVERAGE NUMBER 22 - - - - - -
GRADE CHAR 1 - - - - - -
62 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// To display student id using union - displays all values without duplicates from student and exam
SELECT studentid FROM student
UNION
SELECT studentid FROM exam;
STUDENTID
101
102
104
106
108
// To display student id using union all - displays all values with duplicates from student and exam
STUDENTID
101
102
104
106
108
108
104
101
106
// To display student id using intersect - displays common values in both the tables without
duplicates from student and exam
STUDENTID
101
104
106
108
63 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// To display student id using minus - displays the values that minus the student id of student from
exam
STUDENTID
102
Result:
Thus all the above SQL Set Operation queries has been executed successfully and the output was
verified.
64 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 10
NESTED QUERIES
Nested queries (also known as subqueries) are queries that are embedded within another SQL statement,
allowing you to retrieve data based on the results of another query. Nested queries can be used in SELECT,
INSERT, UPDATE, or DELETE statements.
Q2:Select the employee details whose salary is less than employee LINGAM salary.
STUDENTID SNAME
102 reenu
103 sheela
104 nirmal
105 eshwar
65 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
STUDENTID SNAME
101 reema
Q5:Select student name and department who are all placed in the company INFOSYS.
SNAME DEPARTMENT
reenu IT
sheela CSE
nirmal IT
Q6:Select student name and department who are not placed in the company INFOSYS.
SNAME DEPARTMENT
eshwar CSE
reema IT
Q7:Select studentID, company, salary whose salary is less than either 23,000 or 28,000.
SELECT studentID, company, salary FROM placement WHERE SALARY < SOME (23000, 28000);
Q8:Select studentID, company, salary whose salary is less than both 23,000 and 28,000.
SELECT studentID, company, salary FROM placement WHERE salary < ALL(23000,28000);
66 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// EXISTS
Q9:Select the student placement details where any one of them salary is greater than 20,000.
// NOT EXISTS
Q10:Select the employee details where any one of them salary is not greater than 20,000.
no data found
In Oracle SQL, when using nested queries (subqueries) within a SELECT statement that includes HAVING,
WHERE, GROUP BY, and ORDER BY clauses, the order of execution is generally as follows:
1. FROM clause: The data is first retrieved from the tables specified in the FROM clause, including any
joins or subqueries that appear there.
2. WHERE clause: Rows that meet the conditions specified in the WHERE clause are filtered from the
result set obtained from the FROM clause. This reduces the number of rows to be processed further.
67 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
3. GROUP BY clause: If a GROUP BY clause is present, the rows are then grouped based on the
columns specified in this clause. Aggregate functions (like SUM, AVG, COUNT, etc.) can be applied to
these groups to calculate summary values.
4. HAVING clause: The HAVING clause filters groups of rows based on the conditions specified,
similar to how the WHERE clause filters individual rows. It operates on the grouped data after the
GROUP BY clause has been applied.
5. SELECT clause: Finally, the SELECT clause specifies which columns or expressions are to be
included in the final result set. This clause operates on the grouped and filtered data obtained from
the previous steps.
6. ORDER BY clause: If an ORDER BY clause is present, the final result set is then sorted according to
the specified criteria.
Example: Retrieve the department IDs and their average salaries from the employees table where the salary
exceeds 50,000. Group the results by department ID and display only those departments where the average
salary is greater than 70,000. Arrange the output in descending order of department IDs.
Result:
Thus all the above SQL nested queries has been executed successfully and the output was verified.
68 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No: 11
VIEWS
In Oracle Database, a view is a virtual table that presents data from one or more underlying tables (or
views) to users. Views are defined by SQL queries and can simplify complex queries, provide data security,
and enhance data integrity by abstracting the underlying structure of tables.
Creating a View
To create a view in Oracle, you use the CREATE VIEW statement followed by a query that defines the
view's structure and data:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE conditions;
// View creation
69 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// To display the records in placement table (After inserted a new record in base tables)
// To display the records in studetails view (After deleted a new record in view)
71 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// To display the records in placement table (After deleted a new record in view)
SELECT * FROM placement;
// To display the records in studetails view (After updated a new record in view)
// To display the records in placement table (After deleted a new record in view)
Result:
Thus all the above SQL View queries has been executed successfully and the output was verified.
72 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No. 12
Transaction Control Language (TCL)
TCL commands
• COMMIT
• ROLLBACK
• SAVE POINT
Commit
It tells the DBMS to make permanent changes made to temporary copies of the data updating the
permanent database tables to updated temporary copies.
Syntax:
SQL> COMMIT;
Rollback
It tells the DBMS to undo any changes made to the DBMS after the most recent commit.
Syntax:
SQL> ROLLBACK;
Save point:
Save point are like markers to divide a very lengthy transaction to smaller ones. They are used to
identify a point n transaction to which we can later ROLLBACK. Thus save point is used in conjunction
with ROLLBACK to ROLLBACK portions of the current transaction.
Syntax:
SQL> SAVEPOINT<name>;
city VARCHAR2(30)
designation VARCHAR2(30),
);
Commit
//Select
SELECT * FROM empp;
EMP_ID EMP_NAME CITY DESIGNATION SALARY
100 James Bangalore Modleader 20000
101 Ganesh Chennai Engineer 21000
102 Priya Calculate Manager 50000
103 Kamal Coimbatore Projlead 40000
104 Vishnu Bombay Ceo 15000
105 Kirthika Chennai Accountant 15000
COMMIT;
- COMMIT complete.
Rollback
//Insert
//Select
SELECT * FROM empp;
EMP_ID EMP_NAME CITY DESIGNATION SALARY
100 James Bangalore Modleader 20000
101 Ganesh Chennai Engineer 21000
102 Priya Calculate Manager 50000
103 Kamal Coimbatore Projlead 40000
104 Vishnu Bombay Ceo 15000
105 Kirthika Chennai Accountant 15000
106 John Puducherry manager 25000
ROLLBACK;
- ROLLBACK complete.
74 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select
//Commit:
COMMIT
COMMIT COMPLETE.
//Select
ROLLBACK
ROLLBACK COMPLETE.
//Select
SELECT * FROM empp;
EMP_ID EMP_NAME CITY DESIGNATION SALARY
100 James Bangalore Modleader 20000
101 Ganesh Chennai Engineer 21000
102 Priya Calculate Manager 50000
103 Kamal Coimbatore Projlead 40000
104 Vishnu Bombay Ceo 15000
75 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Save point:
SAVEPOINT s1;
SAVEPOINT created.
SAVEPOINT s2;
SAVEPOINT created.
//Select
//Rollback
ROLLBACK to s2;
Result:
Thus all the above TCL commands has been executed successfully and the output was verified.
76 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex.No. 13
Data Control Language (DCL)
DCL (Data Control Language) consists of statements that control access to data within the database. DCL
statements primarily deal with privileges, roles, and permissions, allowing database administrators (DBAs)
to manage security and access control effectively. The main DCL statements in Oracle include GRANT,
REVOKE.
DCL Commands
• GRANT: The GRANT statement in Oracle is used to give specific privileges to users or roles.
Privileges can include the ability to perform SELECT, INSERT, UPDATE, DELETE, and other
operations on tables and views, as well as execute procedures and sequences.
• REVOKE: The REVOKE statement in Oracle is used to revoke previously granted privileges from
users or roles.
77 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
// Display values
SELECT * FROM emp;
EMPNO EMPNAME DOB SALARY DESIGNATION
100 John 21-Apr-1996 50000 Manager
101 Greg 20-July-1994 2500 Clerk
78 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Revoke the ALL access of table emp from the user staff
REVOKE ALL ON student.emp FROM staff;
REVOKE succeeded
Result:
Thus all the above DCL commands has been executed successfully and the output was verified.
79 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
PL/SQL (Programming
Language / SQL)
80 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex. No: 14
SIMPLE PROGRAMS
PL Block Structure
//Syntax
DECLARE
BEGIN
-----
-----
END;
SET SERVEROUTPUT ON
DECLARE
BEGIN
dbms_output.put_line(‘BASIC PLSQL PROGRAM’);
END;
/
//OUTPUT:
//For Loop
DECLARE
n NUMBER
BEGIN
dbms_output.put_line(‘FOR LOOP’);
n:=&n;
for i in 1..n
loop
dbms_output.put_line(i);
end loop;
END;/
81 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//OUTPUT:
//WHILE LOOP:
DECLARE
n NUMBER;
i NUMBER:=0;
BEGIN
dbms_output.put_line(‘WHILE LOOP’);
n:=&n;
while i<=n
loop
dbms_output.put_line(i);
i:=i+2;
end loop;
END;
/
//OUTPUT:
82 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Table creation:
CREATE TABLE employee
(
eid INT NOT NULL,
ename VARCHAR(10) NOT NULL,
age INT NOT NULL,
sal NUMBER
);
//Select:
DECLARE
name VARCHAR(10);
salary NUMBER;
BEGIN
SELECT ename, sal INTO name,salary FROM employee
WHERE eid = 102;
dbms_output.put_line(‘Customer : ’ ||name);
dbms_output.put_line(‘ Salary : ’ ||salary);
END;
/
//OUTPUT:
Customer: Raja
Salary : 27000
PL/SQL procedure successfully completed.
Result:
Thus all the above PL/SQL Programs has been executed successfully and the output was verified.
83 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex:No: 15
CURSOR
Cursors are used to retrieve and process rows returned by a SQL query. There are two types of cursors
based on their declaration and usage: implicit cursors and explicit cursors.
Implicit Cursor
An implicit cursor is automatically created by Oracle whenever a SQL statement is executed, and there is
no explicit declaration of a cursor by the programmer. Implicit cursors are used for single-row queries,
typically when fetching a single value or row into variables.
Key Points:
• Automatically Managed: Oracle manages implicit cursors automatically behind the scenes.
• Limited Functionality: Suitable for simple queries that retrieve a single row or execute DML
statements.
• Example: Fetching a single employee's salary based on employee ID using SELECT INTO
statement.
Example:
DECLARE
v_salary NUMBER;
BEGIN
SELECT salary INTO v_salary
FROM employees
WHERE employee_id = 101;
Explicit Cursor
An explicit cursor is explicitly declared and defined by the programmer to manage multiple rows returned
by a query. Explicit cursors provide more control over the result set and are used when handling queries
that return multiple rows.
Key Points:
• Declared by Programmer: Explicitly declared using DECLARE CURSOR statement before opening
and fetching rows.
• Manual Control: Requires explicit commands (OPEN, FETCH, CLOSE) to manage the cursor's
lifecycle.
• Example: Iterating through all employees' salaries to calculate the total.
84 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Syntax
DECLARE
CURSOR cursor_name IS SELECT * FROM table_name;
BEGIN
OPEN CURSOR_NAME;
LOOP
-------
-------
END LOOP;
END;
//Table creation:
//Select:
85 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Cursor creation:
DECLARE
CURSOR c IS SELECT * FROM student;
m student%rowtype;
tot NUMBER;
res CHAR(5);
average NUMBER;
BEGIN
OPEN c;
LOOP
FETCH c INTO m;
EXIT WHEN c%NOTFOUND;
tot:=m.m1+m.m2+m.m3;
average:=tot/3;
UPDATE student SET total=tot WHERE sid=m.sid;
UPDATE student SET cgpa=average WHERE sid=m.sid;
IF (m.m1>49 AND m.m2>49 AND m.m3>49 ) THEN
res:=’PASS’;
ELSE
res:=’FAIL’;
END IF;
UPDATE student SET result=res WHERE sid=m.sid;
END LOOP;
END;
/
//OUTPUT:
Result:
Thus all the above PL/SQL Programs has been executed successfully and the output was verified.
86 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex:No: 16
TRIGGERS
A trigger is a PL/SQL block that is automatically executed (or fired) when certain events occur on a
particular table or view. Triggers are used to enforce business rules, automate actions, and maintain data
integrity. Here are the key aspects and types of triggers in Oracle:
//Syntax - Trigger
END;
87 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select:
eid NUMBER,
ename VARCHAR2(10),
idate DATE,
nsal NUMBER,
);
//Trigger Creation-logsal:
// Select-employ:
//Select –emplog:
//Table creation:
89 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select:
//Table creation:
90 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select:
Result:
Thus all the above PL/SQL Programs has been executed successfully and the output was verified.
91 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
92 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex No: 17
//Table creation
//Form design
93 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
namespace exam
{
public partial class Form1 : Form
{
OracleConnection conn = new OracleConnection("Data Source=XE;User
Id=system;Password=password;");
OracleCommand cmd;
public Form1()
{
InitializeComponent();
}
{
try
{
String g;
if (male.Checked == true)
g = "male";
else
g="female";
conn.Open();
cmd = new OracleCommand("Insert into
rest = "Fail";
total.Text = t.ToString();
cgpa.Text = c.ToString();
res.Text = rest;
}
97 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Output
//Select
//Insert
98 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select
//Delete
99 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
//Select
//Report
Result:
Thus the above Student Information System Application has been created successfully using SQL
queries and the output was verified.
100 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Ex No: 18
MongoDB is a popular NoSQL database that uses a document-oriented data model. It stores data in flexible,
JSON-like documents, meaning fields can vary from document to document, and data structure can be
changed over time.
CRUD stands for Create, Read, Update, and Delete. These operations are fundamental in database
management and are used to manipulate data stored in databases. Here’s an explanation of each CRUD
operation:
1. Create (C)
Purpose: The Create operation is used to insert new data records (or documents, in the case of NoSQL
databases like MongoDB) into a database.
Key Points:
Data Integrity: Ensures that new records adhere to any constraints or rules defined by the database schema.
Primary Keys: Generates or assigns unique identifiers (e.g., primary keys) for new records.
Examples: Inserting a new user profile, adding a new product to an inventory, or creating a new document
in a NoSQL collection.
2. Read (R)
Purpose: The Read operation retrieves data from a database, allowing users or applications to view and
access existing records.
Key Points:
Querying: Read involves executing queries to fetch specific records or sets of records from a database.
Data Retrieval: Retrieves data based on various criteria, such as filtering, sorting, or aggregating.
Efficiency: Ensures efficient retrieval of data using indexes and query optimization techniques.
Examples: Fetching user details by username, retrieving product information based on category, or reading
all documents from a collection.
101 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
3. Update (U)
Purpose: The Update operation modifies existing data records within a database.
Key Points:
Modification: Update involves changing the values of one or more fields in existing records.
Atomicity: Ensures that updates are either applied completely or not at all (atomic operations).
Examples: Changing a user's email address, updating the price of a product, or modifying fields in a
document.
4. Delete (D)
Purpose: The Delete operation removes existing data records from a database.
Key Points:
Removal: Delete involves permanently removing records from a database table or collection.
Data Integrity: Maintains referential integrity by handling cascading deletes or enforcing constraints.
Recovery: Often soft deletes (marking records as inactive) are used to maintain audit trails.
Examples: Deleting a customer account, removing an expired product listing, or purging outdated
documents.
Data Management: CRUD operations form the backbone of data management systems, enabling
applications to create, retrieve, update, and delete data efficiently.
User Interfaces: Most applications (web, mobile, desktop) use CRUD operations to interact with backend
databases, allowing users to perform actions on data.
APIs: RESTful APIs commonly map CRUD operations to HTTP methods: Create (POST), Read (GET),
Update (PUT/PATCH), and Delete (DELETE).
102 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
103 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
• If not, you can start it manually by opening a command prompt and running mongod.
Step 8: Verify the MongoDB Server
• Open a command prompt.
• Type mongo to start the MongoDB shell and connect to the running MongoDB instance.
• You should see the MongoDB shell prompt (>), indicating that you are connected to the MongoDB
server.
CODE
// Switch to the library database
use library
Result:
Thus the above MongoDB Application has been created successfully using NoSQL queries and
the output was verified.
104 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
PRACTICE QUESTIONS
105 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
APPLICATIONS
PRACTICE QUESTIONS
1. Insurance Database
Consider the insurance database given below. The primary keys are made bold and the data types
are specified.
1) Create the above tables by properly specifying the primary keys and foreign keys.
2) Enter at least five tuples for each relation.
3) Demonstrate how you
a.Update the damage amount for the car with specific regno in the accident with report number 12 to 25000.
b.Add a new accident to the database.
4) Find the total number of people who owned cars that were involved in accidents in the year 2008.
5) Find the number of accidents in which cars belonging to a specific model were involved.
2. Consider the following relations for a order processing database application in a company.
CUSTOMER( custno:int , cname:string , city:string )
ORDER( orderno:int , odate:date , custno:int , ord_amt:int )
ORDER_ITEM( orderno:int , itemno:int , quantity:int )
ITEM( itemno:int , unitprice:int )
SHIPMENT( orderno:int , warehouseno:int , ship_date:date )
WAREHOUSE( warehouseno:int , city:string )
1)Create the above tables by properly specifying the primary keys and foreign keys.
2) Enter at least five tuples for each relation.
3) Produce a listing: custname ,No_of_orders , Avg_order_amount , where the middle column is the total
number of orders by the customer and the last column is the average order amount for that customer.
4) List the orderno for orders that were shipped from all the warehouses that the company has in a specific
city.
5) Demonstrate the deletion of an item from the ITEM table and demonstrate a method of handling the rows
in the ORDER_ITEM table that contains this particular item.
106 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
3. Consider the following database of student enrollment in courses and books adopted for that
course.
STUDENT( regno:string , name:string , major:string , bdate:date )
COURSE( courseno:int , cname:string , dept:string )
ENROLL( regno:string , courseno:int , sem:int , marks:int )
BOOK_ADOPTION( courseno:int , sem:int , book_isbn:int )
TEXT( book_isbn:int , book_title:string , publisher:string , author:string )
1)Create the above tables by properly specifying the primary keys and foreign keys.
2) Enter atleast five tuples for each relation.
3) Demonstrate how you add a new text book to the database and make this book to be adopted by some
department.
4) Produce a list of text books (includes courseno ,book_isbn , book_title ) in the alphabetical order for
courses offered by the 'CS' department that use more than two books.
5) List any department that has all its books published by a specific publisher.
107 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
4) Find all the customers who have an account at all the branches located in a specific city.
5) Demonstrate how you delete all account tuples at every branch located in a specific city.
The product can sale to a particular client and each client have it own unique client number, client
name, client addresses, city, pin code, state and total balance to be required to paid.
Each client order to buy product from the salesman. In the order, it has unique sales order number, sales
order date, client number, salesman number (unique), billed whole payment by the party or not and its
delivery date.
The salesman have the salesman_no, name, addresses, city, pin code, state, salary of the sales man,
delivery date, total quantity ordered, and product rate.
108 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
8. Patient registration form should include Registration number, Patient name, Address, Gender, Bed
number, date of registration, refer doctor id etc.
Doctor information should include Doctorcode, Doctor Name, Specialization etc.
Lab test information should include Test name, test number, test date, results, patient Registration number
and referred doctor’s code.
Queries:
a. Display the details of patients admitted on date ’14-Oct-2021’
b. Change the name of the patient to ‘Ram’ as name is ‘rajesh’.
c. Display the details of the patients and lab test results performed on ‘20-jul-21’.
d. Display the number of patients taking treatment under doctor =’ABC’.
e. Retrieve the name of doctor who is taking care of maximum number of patients.
9. Payroll system
Create necessary schema with proper attributes for payroll system and Write the queries for the following
1. List all the employees of CSE department.
2. Retrieve all the employees who have the gross salary greater than or equal to Rs-21,000.
3. Find the DA, TA, HRA of the employee name ‘Ramesh’.
4. Find the max salary of an employee department wise.
5. List the employees who are joined between ’10-APR-21’ to ’2-OCT-21’.
109 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
VIVA QUESTIONS
110 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
VIVA QUESTIONS
Basic Concepts:
1. What is Oracle Database?
o Oracle Database is a relational database management system developed by Oracle
Corporation.
2. Explain the architecture of Oracle Database.
o Oracle Database architecture includes the instance and the database. The instance consists of
memory structures and background processes, while the database includes physical data files
and control files.
3. Differentiate between SQL and PL/SQL.
o SQL (Structured Query Language) is used for querying and manipulating data in Oracle
Database. PL/SQL (Procedural Language/Structured Query Language) is Oracle's procedural
extension to SQL, used for writing code blocks, procedures, and functions.
4. What are the types of Oracle Database users?
o Types include database administrators (DBAs), application developers, and end-users.
5. Explain the concept of a tablespace.
o A tablespace is a logical storage unit in Oracle Database where schema objects are stored.
6. What is a schema in Oracle Database?
o A schema is a collection of database objects (tables, views, etc.) owned by a particular
database user.
SQL Basics:
7. Write a query to retrieve all columns from a table named employees.
o SELECT * FROM employees;
8. Explain the GROUP BY clause in SQL.
o GROUP BY is used with aggregate functions to group the result set based on one or more
columns.
9. What is a subquery? Provide an example.
o A subquery is a query nested within another query. Example: SELECT * FROM employees
WHERE department_id IN (SELECT department_id FROM departments WHERE
location_id = 1700);
PL/SQL:
10. What is a stored procedure?
o A stored procedure is a named PL/SQL block stored in the database that performs one or
more tasks.
11. How do you declare a variable in PL/SQL?
o DECLARE variable_name datatype;
12. Explain the CURSOR in PL/SQL.
o A CURSOR is a pointer used to fetch rows from a result set one at a time.
111 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Advanced Topics:
13. What are indexes in Oracle Database?
o Indexes are database objects used to speed up the retrieval of rows by providing fast access
to rows in a table.
14. Explain the concept of data concurrency.
o Data concurrency refers to the ability of multiple users to access and modify data
simultaneously without interference.
15. What are triggers in Oracle Database?
o Triggers are PL/SQL blocks executed automatically in response to events such as INSERT,
UPDATE, or DELETE operations on a table.
Performance Tuning:
16. What are the different types of joins in SQL?
o Types include INNER JOIN, LEFT JOIN (or LEFT OUTER JOIN), RIGHT JOIN (or
RIGHT OUTER JOIN), and FULL JOIN (or FULL OUTER JOIN).
17. How do you optimize SQL queries in Oracle Database?
o Optimization techniques include using indexes, rewriting complex queries, and analyzing
execution plans.
Data Management:
18. Explain the process of backing up and recovering Oracle Database.
o Backups can be done using tools like RMAN (Recovery Manager) and Data Pump.
Recovery involves restoring data files and applying redo logs.
19. What is data integrity in Oracle Database?
o Data integrity ensures the accuracy, validity, and consistency of data stored in Oracle
Database through constraints (e.g., NOT NULL, UNIQUE, FOREIGN KEY).
Security:
20. How do you grant privileges in Oracle Database?
o GRANT privilege_name TO user_or_role;
21. Explain roles in Oracle Database.
o Roles are named groups of privileges that can be granted to users.
Miscellaneous:
22. What are the different types of triggers in Oracle Database?
o Types include BEFORE triggers, AFTER triggers, and INSTEAD OF triggers.
23. How do you manage transactions in Oracle Database?
o Transactions are managed using COMMIT to save changes and ROLLBACK to undo
changes.
24. What is the purpose of the EXPLAIN PLAN statement?
o EXPLAIN PLAN displays the execution plan of a SQL statement without executing it,
showing how Oracle Database will execute the statement.
112 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
Advanced SQL:
25. What are analytic functions in Oracle?
o Analytic functions compute aggregate values based on a group of rows and return a single
result for each row.
26. Explain the MERGE statement in Oracle.
o MERGE statement performs insert, update, or delete operations on a target table based on
the results of a join with a source table.
27. What is the purpose of the WITH clause (common table expression) in Oracle SQL?
o The WITH clause allows you to define temporary result sets within a SQL statement,
making complex queries easier to read and maintain.
PL/SQL Procedures and Functions:
28. What is a stored function in PL/SQL?
o A stored function is a PL/SQL block that returns a single value. It can be called in SQL
queries or other PL/SQL blocks.
29. Differentiate between PROCEDURE and FUNCTION in PL/SQL.
o A PROCEDURE is a PL/SQL block that performs a specific task, whereas a FUNCTION
returns a single value and can be used in SQL queries.
30. How do you handle exceptions in PL/SQL?
o Exceptions in PL/SQL are handled using EXCEPTION blocks, which specify actions to take
when errors occur during execution.
Database Administration:
31. What are the different types of backups available in Oracle Database?
o Types include full backup, incremental backup, and archive log backup.
32. Explain the roles of DBA_USERS and DBA_TABLES views in Oracle Database.
o DBA_USERS view provides information about all users in the database, while
DBA_TABLES view lists all tables accessible to the DBA.
Indexes and Performance Tuning:
33. What factors should you consider when creating indexes in Oracle Database?
o Considerations include the columns frequently used in queries, cardinality (uniqueness of
data), and storage implications.
34. How does the optimizer determine the execution plan for a SQL statement in Oracle
Database?
o The optimizer analyzes statistics, indexes, and constraints to generate an execution plan
based on cost estimates.
Data Integrity and Constraints:
35. Explain the purpose of referential integrity constraints in Oracle Database.
o Referential integrity constraints (foreign keys) ensure that relationships between tables are
enforced, maintaining data consistency.
113 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
36. What is the difference between PRIMARY KEY and UNIQUE constraints?
o PRIMARY KEY constraint uniquely identifies each record in a table, while UNIQUE
constraint ensures that all values in a column are distinct.
Views and Materialized Views:
37. What are views in Oracle Database?
o Views are virtual tables derived from one or more tables or other views. They provide a way
to present data in a customized manner.
38. Explain the difference between views and materialized views in Oracle.
o Views are virtual and do not store data, while materialized views store the results of a query
as a physical table, refreshing periodically.
Security and Authorization:
39. How do you revoke privileges from a user in Oracle Database?
o REVOKE privilege_name FROM user_or_role;
40. Explain the concept of database auditing in Oracle.
o Database auditing involves monitoring and recording database activities to ensure
compliance and track unauthorized access.
Transaction Management:
41. What is a savepoint in Oracle Database?
o A savepoint marks a point in a transaction to which you can roll back if necessary, without
rolling back the entire transaction.
Backup and Recovery:
42. Describe the steps to recover a database using RMAN (Recovery Manager).
o Steps include restoring data files and applying archived redo logs to bring the database to a
consistent state.
Data Pump and Import/Export:
43. What is Oracle Data Pump?
o Oracle Data Pump is a high-speed data movement utility for importing, exporting, and
maintaining large databases.
Data Dictionary Views:
44. Explain the purpose of V$SESSION and V$SQL views in Oracle Database.
o V$SESSION view provides information about active sessions in the database, while V$SQL
view displays information about SQL statements executed.
Performance Monitoring:
45. How do you monitor performance using Oracle Enterprise Manager (OEM)?
o OEM provides graphical tools for monitoring database performance metrics such as CPU
usage, memory usage, and SQL execution times.
114 | P a g e
DBMS LAB MANUAL – R2023, Department of Information Technology, SMVEC.
Prepared by Mrs.N.Kalaiselvi, Mr.P.Praveenkumar, Mr.A. Ranjeeth, AP/IT, SMVEC
115 | P a g e