11zon - New DBMS Lab File - 2023
11zon - New DBMS Lab File - 2023
Course : B.Tech
Branch : CSE
6. Lesson Plan
7. Roll List
9. Internal Marks
10.External Marks
VISION
MISSION
To impart high quality technical and professional education, to uplift the living
standards
of the youth by focusing on employability, higher education and research
To bridge the gap between industry and academia by introducing add on courses
based on
industrial and academic needs
To develop responsible citizens through disciplined career and acceptance of
ethical values
To be a student centric Institute imbibing experiential, innovative and lifelong
learning
VISION
MISSION
To offer State-of-Art education in Computer Science and Engineering
To provide strong theoretical foundation complemented with extensive practical
training
To impart Software, Communication and Leadership Skills to the students for
giving solutions to the Global Challenges
To inculcate Value-based, Socially Committed Professionalism to the cause of
overall development of Students and Society
SYLLABUS OF THE COURSE
II Year – I1 Semester L T P C
0 0 3 1.5
DATABASE MANAGEMENT SYSTEM LAB
LIST OF EXPERIMENTS:
1) Creation, altering and droping of tables and inserting rows into a table (use constraints while
creating tables) examples using SELECT command.
2) Queries (along with sub Queries) using ANY, ALL, IN, EXISTS, NOTEXISTS, UNION,
INTERSET, Constraints. Example:- Select the roll number and name of the student who secured
fourth rank in the class.
3) Queries using Aggregate functions (COUNT, SUM, AVG, MAX and MIN), GROUP BY,
HAVING and Creation and dropping of Views.
4) Queries using Conversion functions (to_char, to_number and to_date), string functions
(Concatenation, lpad, rpad, ltrim, rtrim, lower, upper, initcap, length, substr and instr), date
functions (Sysdate, next_day, add_months, last_day, months_between, least, greatest, trunc, round,
to_char, to_date)
5) i) Create a simple PL/SQL program which includes declaration section, executable section and
exception –Handling section (Ex. Student marks can be selected from the table and printed for those
who secured first class and an exception can be raised if no records were found)
ii) Insert data into student table and use COMMIT, ROLLBACK and SAVEPOINT in PL/SQL
block.
6) Develop a program that includes the features NESTED IF, CASE and CASE expression. The
program can be extended using the NULLIF and COALESCE functions.
7) Program development using WHILE LOOPS, numeric FOR LOOPS, nested loops using ERROR
Handling, BUILT –IN Exceptions, USE defined Exceptions, RAISEAPPLICATION ERROR.
8) Programs development using creation of procedures, passing parameters IN and OUT of
PROCEDURES.
9) Program development using creation of stored functions, invoke functions in SQL Statements and
write complex functions.
10) Develop programs using features parameters in a CURSOR, FOR UPDATE CURSOR, WHERE
CURRENT of clause and CURSOR variables.
11) Develop Programs using BEFORE and AFTER Triggers, Row and Statement Triggers and
INSTEAD OF Triggers
12) Create a table and perform the search operation on table using indexing and non indexing
techniques.
Additional Experiments:
13) PL/SQL Program to Find Factorial of a Number
14) PL/SQL Program to Find Reverse of a Number
PO, PEOs & PSO statements
PROGRAM OUTCOMES (POs) FOR UG COURSES
Program Outcomes
PO12 Life-long learning A recognition of the need for, and an ability to engage in,
to resolve contemporary issues and acquire lifelong
learning
PROGRAM EDUCATIONAL OBJECTIVES:
Program Educational Objectives of the UG in COMPUTER SCIENCE
& ENGINEERING are:
PEO 1.
PEO 2.
PEO 3.
PEO 4
PEO 5
PSO2:
To use Unix utilities and perform basic shell control of the utilities
To use the Unix file system and file access control
To use of an operating system to develop software
Students will be able to use Linux environment efficiently
Solve problems using bash for shell scripting
COURSE OUTCOMES:
To use Unix utilities and perform basic shell control of the utilities
To use the Unix file system and file access control
To use of an operating system to develop software
Students will be able to use Linux environment efficiently
Solve problems using bash for shell scripting
CO PO PO PO PO PO PO PO PO PO PO PO PO PSO PSO
1 2 3 4 5 6 7 8 9 10 11 12 1 2
C411.1 3 3 2 1 - - - 1 2 1 - - 1
C411.2 3 2 1 2 2 1 1 1 2 - - 1 1
C411.3 3 3 2 2 2 1 1 1 3 - - 2
C411.4 3 3 2 1 2 1 1 - 1 1
C411.5 3 3 2 2 2 1 1 1 1 - - 2
ADDITIONAL EXPERIMENTS
SQL> create table st(sid int primary key,sname varchar(20),sdept varchar(20),sgrade varchar(5));
Table created.
Alter table st by dropping column SQL> alter table st drop column sdept;
Table altered.
Desc st
SQL> desc st;
Name Null? Type
SID NOT NULL NUMBER(38) SNAME VARCHAR2(20)
SGRADE VARCHAR2(5)
101 sai a
102 ayisha a+
* ERROR at line 1:
ORA-00942: table or view does not exist
Experiment-2
Queries (along with sub-Queries) using ANY, ALL, IN, EXISTS, NOTEXISTS, UNION, INTERSET,
Constraints. Example: - Select the roll number and name of the student who secured fourth rank in the
class.
PROGRAM:
Sql> create table employee( Fname varchar2(20), Lname varchar2(20), Ssn number(4) primary key, B_date date,
Address varchar2(30), Gender char(1), Salary number(7,2), Super_ssn references employee(ssn), Dno number(4)
Table created.
Like this we can insert the values into the table. To view data in the table following query is used
Table created.
1.ALL:
Retrieve the names of employees whose salary is greater than the salary of all the employees in department 10
FNAME LNAME
-------- ---------
ALLEN
MARTIN
TURNER
2.ANY:
Retrieve the names of employees whose salary is greater than the salary of any one of the employees in
department 10
SQL> SELECT FNAME, LNAME FROM EMPLOYEE WHERE SALARY> ANY( SELECT SALARY
FROM EMPLOYEE WHERE DNO=10);
FNAME LNAME
-------- -----------
TURNER
MARTIN
ALLEN
BLAKE
SMITH
3.IN :
Retrieve the name of each employee who has a dependent with the firstname and same gender as the employee
FNAME LNAME
-------- ---------
SMITH
MARTIN
4.EXISTS :
Retrieve the name of each employee who has a dependent with the firstname and same gender as the employee
FNAME LNAME
--------- -----------
SMITH
MARTIN
5.NOT EXISTS :
SQL> SELECT FNAME, LNAME FROM EMPLOYEE WHERE NOT EXISTS (SELECT *
FROM DEPENDENT WHERE SSN=ESSN);
FNAME LNAME
------- ---------
ALLEN
Experiment-3
Queries using Aggregate functions (COUNT,SUM, AVG, MAX and MIN), GROUP BY, HAVING
and Creation and dropping of Views.
1 dairy milk 60 2
2 good day 25 4
3 boost 10 6
4 maggi 5 10
5 book 20 20
Count function
COUNT(PRICE)
5
SQL> select count(quantity) from product;
COUNT(QUANTITY)
5
Sum function
SUM(PRICE)
120
SUM(QUANTITY)
42
Avg function
AVG(PRICE)
24
AVG(QUANTITY)
8.4
Max function
MAX(PRICE)
60
MAX(QUANTITY)
20
Min function
Table created
sum(sal)
It 130000
Ece 14000
Having
Dept sum(sal)
It 130000
Creating views
2. to_number
TO_NUMBER('234.87')
234.87
3. to_date
TO_DATE('
21-JAN-98
LOW
---
sai
2. upper
SQL> select upper('sai') from dual;
UPP
--- SAI
3. concat
SQL> select concat('hello','sai') from dual;
CONCAT('
Hello sai
4. initcap
SQL> select initcap('sai') from dual;
INI
---
Sai
5. length
SQL> select length('sai') from dual;
LENGTH('SAI')
3
6. instr
SQL> select instr('ruhanika','a') from dual;
INSTR('RUHANIKA','A')
4
7. substr
SQL> select substr('ruhanika',5) from dual;
SUBS
nika
8. lpad
SQL> select lpad('ruhanika',10,'****') from dual;
LPAD('RUHA
**ruhanika
9. rpad
SQL> select rpad('ruhanika',10,'****') from dual;
RPAD('RUHA
ruhanika**
10. ltrim
SQL> select ltrim(' ruhanika') from dual;
LTRIM('R
ruhanika
11. rtrim
SQL> select rtrim(' ruhanika ') from dual;
RTRIM('RUHANIK
ruhanika
date functions
1.sysdate
2. last_day
SQL> select last_day(sysdate) from dual;
LAST_DAY(
30-NOV-15
3. next_day
SQL> select next_day('20-nov-2015','friday') from dual;
NEXT_DAY(
27-NOV-15
4. add_months
ADD_MONTH
20-JAN-16
5. months_between
MONTHS_BETWEEN('20-NOV-2015','20-JAN-2016')
6. least
SQL> select least(10,11,12) from dual;
LEAST(10,11,12)
10
7. greatest
GREATEST(10,11,12)
12
ROUND(21.088)
21
TRIM(2
21.088
Experiment-5
5) i)Creation of simple PL/SQL program which includes declaration section, executable section and
exception –Handling section (Ex. Student marks can be selected from the table and printed for those
who secured first class and an exception can be raised if no records were found)
Program:
declare
stu_id number; stu_name varchar(20);
cursor stu_cur is select sid,
sname from student where sclass='first';
Begin
Open stu_cur;
Loop
fetch stu_cur into stu_id,stu_name; exit
when stu_cur%notfound;
dbms_output.put_line('student_id: '|| stu_id || 'student_name:'|| stu_name);
end loop;
close stu_cur;
end;
/
Output:
student_id: 1
student_name:abhi
student_id: 2
student_name:sai
student_id: 5
student_name:ish
Savepoint h;
Savepoint created
SQL> begin
savepoint g;
insert into stu values('ruhi','cse');
exception
when dup_val_on_index then rollback to g;
commit;
end;
/
SQL>Rollback to h;
Rollback completed
Experiment-6
6) Develop a program that includes the features Nested if,Case and case expression.The Program can
be extended using the NULL if, and COALESCE functions.
(1) CASE:
Syntax:
Select case("column_name") when "value1" then "result1" when "value2" then "result2"
....
[else "resultN"] end
from "table-name";
program:
select store_name,case store_name when 'Newyork' then sales*2
when 'chicago' then sales*3 else sales
end
"new sales" txn_date
from store_information;
program:
select store_name,txn_date,case
when sales>=8000 then 'congrats get a gift coupon' when sales>=2000 then 'Thanks for shopping'
else 'Good day' end
"sales status"
from store_information;
(3) COALESCE:
Declare
Grade char(1); begin grade=’a’; case
When grade=’a’ then dbbms_output.put_line(‘Excellent’);
When grade =’b’ then dbms_output.put_line(‘very good’);
When grade=’c’ then dbms_output.put_line(‘goog’);
When grade=’d’ then dbms_output.put_line(‘fair’);
When grade=’f’ then dbms_output.put_line(‘poor’);else
Dbms_output.put_line(‘No such grade’); end case; end;
Experiment-7
7) Program development using WHILE LOOPS, numeric FOR LOOPS, nested loops using ERROR
Handling, BUILT –IN Exceptions, USE defined Exceptions, RAISE- APPLICATION ERROR.
PL/SQL
1) AIM: Addition at run time
Declare
a number; b number; c number; Begin a:=&a;
b:=&b;
c:=&c;
dbms_output.put_line('sum of' || a || 'and' || b || 'is' || c); end;
/
output:
Enter value for a: 10 old 6: a:=&a;
new 6: a:=10; Enter value for b: 10
old 7: b:=&b;
new 7: b:=10; Enter value for c: 10 old 8: c:=&c;
new 8: c:=10; sum of10and10is10
PL/SQL procedure successfully completed.
c is maximum
PL/SQL procedure successfully completed.
5) AIM: select column from table employ by using memory variable Program:
Declare
Mvsalary number(10,2); Begin
Select salary into mvsalary From
Employ
Where ename=’sai’;
Dbms_output.put_line(‘the salary of employ is’ || to_char9mvsalary));
End;
/
Output:
The salary of employ is 50000
PL/SQL procedure successfully completed.
Experiment-8
8) AIM: Programs development using creation of procedures, passing parameters IN and OUT of
procedures.
/*program*/
create procedure findname(enquiryno1 IN number,fname1 OUT varchar2) is
fname2 varchar2(30); begin
select fname into fname2 from enquiry
where enqno1=enquiryno1; fname1:=fname2; exception
when no_data-found then
raise_application_error(-20100,
'The given number is not present'); end;
/
/*calling procedure*/
declare
enqno2 number(5); fname2 varchar2(30);
begin
enqno2:=111; findname(enqno2,fname2);
dbms_output.put_line(fname2); end;
/
output: sai
Experiment-9
9) Program development using creation of stored functions, invoke functions in SQL statements and
write complex functions.
/*program*/
/*calling function*/
declare
fname2 varchar2(30); deptno2 number(5); begin
deptno:=1219;
fname2:=getname(dno); dbms_output.put_line(fname2);
end;
/
output: sai
Experiment-10
10) Program development using creation of package specification, package bodies, private objects,
package variables and cursors and calling stored packages.
procedure savedept
(dno in number,dloc in varchar);
end;
/
(4) creating package body
exec test.savedept(10,'vijayawada');
AIM: create an employ table and retrieve the name of employ whose salary is Greater than 25000 by
PL/SQL
Program:
declare
emp_rec varchar(30); cursor emp_cur is select ename
from employ where salary>25000;
Begin
Open emp_cur;
Loop
fetch emp_cur into emp_rec; exit when emp_rec%notfound; dbms_output.put_line(emp_rec);
end loop;
close emp_cur;
end;
/
Output:
Sindhu Sai Satya
12) Develop programs using before and after triggers, row and statement triggers and instead of
triggers.
begin
dbms_output.put_line('trigger fired'); end;
/
(2) Insert
12) Create a table and perform the search operation on table using indexing and non-indexing techniques.
sol: sql> create table teacher(staff_id varchar2(4) primary key, staff_name varchar2(30), qualification
varchar2(10), hiredate date, job varchar2(30), address varchar2(15), ph_num number(10), salary number(7, 2),
department varchar2(10));
table created.
4 rows selected.
elapsed: 00:00:00.18
ADDITIONAL EXPERIMENTS
Experiment-1
1)PL/SQL Program to Find Factorial of a Number
declare
n number;
fac number:=1;
i number;
begin
n:=&n;
for i in 1..n
loop
fac:=fac*i;
end loop;
dbms_output.put_line('factorial='||fac);
end;
/
Output
Enter value for n: 10 old 7: n:=&n; new 7: n:=10; factorial=3628800
Experiment-2
declare
n number;
i number;
rev number:=0;
r number;
begin
n:=&n;
while n>0
loop
r:=mod(n,10);
rev:=(rev*10)+r;
n:=trunc(n/10);
end loop;
dbms_output.put_line('reverse is '||rev);
end;
/
Output
Enter value for n: 4578
old 8: n:=&n;
new 8: n:=4578;
reverse is 8754