Professional Documents
Culture Documents
: Date:
Advanced DBMS (CS604) Rev No.: Nil Rev. Date: Nil
Clause: Nil Page: 1 of 51
Lab Maual
Table of Contents
1 System Requirements 4
2 Lab Objectives 4
Experiment Manual
(2) While entering into the LAB students should carry ID cards.
(4) Students should come with the record note book into the laboratory.
(6) After completing the laboratory exercise, make sure to shut-down the system properly.
DONT’S
(4) Students bringing pen drive or other secondary storage device inside the laboratory.
System Requirements
1. Intel based desktop PC of Intel Core I-5 or faster processor with at least 2-4 GB RAM and
Lab Objectives
2. Build Database and then table, perform update, rename and delete operation on that data .
4. Implementing PL/SQL.
Practical – 1
Create a Database and create a table “Employee” with the fields (empno, ename, job, mgr,
hiredate,sal,comm, deptno) and perform INSERT operation
Practical- 2
Create a Database and create a table “Employee” with the fields (empno, ename, job, mgr,
hiredate,sal,comm, deptno) and perform INSERT operation
Solution:SQL UPDATE statement is used to change the data of the records held by tables.
Which rows is to be update, it is decided by a condition. To specify condition, we use WHERE
clause.
SELECT empno,ename,sal
FROM emp;
Practical- 3
Create a Database and create a table “Employee” with the fields (empno, ename, job, mgr,
hiredate,sal,comm, deptno) and perform Delete operation.
Solution:The DELETE statement is used to delete rows from a table. If you want to remove a
specific row from a table you should use WHERE condition.
Practical – 4
Create a Database and create a table “Employee2” with the fields (empno, ename, job,
mgr, hiredate,sal,comm, deptno) and perform Rename operation.
Solution:SQL RENAME TABLE syntax is used to change the name of a table. Sometimes, we
choose non-meaningful name for the table. So it is required to be changed.
desc EMPLOYEE2;
alter table EMPLOYEE2 rename to EMP;
desc EMP;
OUTPUT:
Practical- 5
Create a table “Employee”with the fields (empno, ename, job, mgr, hiredate,sal,comm,
deptno) in the already existing database and perform various join operations of the
database
Solution: The SQL JOIN clause takes records from two or more tables in a
database and combines it together. In the SQL outer JOIN all the content of the
both tables are integrated together either they are matched or not.Left outer
join (also known as left join): this join returns all the rows from left table combine
with the matching rows of the right table. If you get no matching in the right table it
returns NULL values.Right outer join (also known as right join): this join returns
all the rows from right table are combined with the matching rows of left table .If
you get no column matching in the left table .it returns null value.
Create table Employee (emp_id int, e_name varchar(30),age int, dep_id int,Salary int,);
desc Employee;
Output: Showing structure of the table
Select Employee.emp_id,Employee.e_name,Department.dep_name
From Employee
INNER JOIN Department
ON Employee.dep_id=Department.dept_id;
Output:
Practical-6
Write a program in PLSQL to perform the initialization of Variables in PL/SQL
Declare
a integer:=30;
b integer:=40;
c integer;
f real;
Begin
c:=a+b;
dbms_output.put_line('Value of c: ' || c);
f := 100.0/3.0;
dbms_output.put_line('Value of f: ' || f);
END;
Output:
Practical-7
Write a Program in PLSQL to show the Scope of Global and Local Variables
Solution: PL/SQL allows nesting of blocks. A program block can contain another
inner block. If you declare a variable within an inner block, it is not accessible to
an outer block. There are two types of variable scope:
Local Variable: Local variables are the inner block variables which are not
accessible to outer blocks.
Global Variable: Global variables are declared in outermost block.
DECLARE
-- Global variables
num1 number := 195;
num2 number := 285;
BEGIN
dbms_output.put_line('Outer Variable num1: ' || num1);
dbms_output.put_line('Outer Variable num2: ' || num2);
DECLARE
-- Local variables
num1 number := 395;
num2 number := 185;
BEGIN
dbms_output.put_line('Inner Variable num1: ' || num1);
dbms_output.put_line('Inner Variable num2: ' || num2);
END;
END;
Output:
Practical- 8
Write a Program in PLSQL by using PLSQL Constants
Solution:A constant is a value used in a PL/SQL block that remains unchanged throughout the
program. It is a user-defined literal value. It can be declared and used instead of actual values.
Output:
Practical -9
Write a Program in PLSQL to create a Function and perform calling of the function
Solution: The PL/SQL Function is very similar to PL/SQL Procedure. The main difference
between procedure and a function is, a function must always return a value
Output:
Practical-10
Write a Program in PLSQL to print the Maximum of the Two Numbers using Functions:
Solution:
DECLARE
a number;
b number;
c number;
FUNCTION findMax(x IN number, y IN number)
RETURN number
IS
z number;
BEGIN
IF x > y THEN
z:= x;
ELSE
Z:= y;
END IF;
RETURN z;
END;
BEGIN
a:= 23;
b:= 45;
c := findMax(a, b);
dbms_output.put_line(' Maximum of (23,45): ' || c);
END;
Output:
Practical- 11
Write a PLSQL Program to illustrate the concept of various Control Statements (Loops).
Solution:The PL/SQL loops are used to repeat the execution of one or more
statements for specified number of times. These are also known as iterative
control statements. There are 4 types of PL/SQL Loops.
Basic Loop / Exit Loop
While Loop
For Loop
Cursor For Loop
PL/SQL exit loop is used when a set of statements is to be executed at least once
before the termination of the loop. There must be an EXIT condition specified in
the loop, otherwise the loop will get into an infinite number of iterations.
DECLARE
i NUMBER := 1;
BEGIN
LOOP
EXIT WHEN i>10;
DBMS_OUTPUT.PUT_LINE(i);
i := i+1;
END LOOP;
END;
Output:
BEGIN
FOR k IN 1..10 LOOP
-- note that k was not declared
DBMS_OUTPUT.PUT_LINE(k);
END LOOP;
END;
Output:
DECLARE
i INTEGER := 1;
BEGIN
WHILE i <= 10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i+1;
END LOOP;
END;
Output: