0% found this document useful (0 votes)
77 views32 pages

11zon - New DBMS Lab File - 2023

The document provides the course file details for the Database Management Systems Lab course for the second year second semester. It includes details like the vision and mission of the institute, syllabus, program outcomes, course objectives and outcomes, time table, lesson plan, student list, programs and outputs, internal and external marks, result analysis and attainment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views32 pages

11zon - New DBMS Lab File - 2023

The document provides the course file details for the Database Management Systems Lab course for the second year second semester. It includes details like the vision and mission of the institute, syllabus, program outcomes, course objectives and outcomes, time table, lesson plan, student list, programs and outputs, internal and external marks, result analysis and attainment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

DADI INSTITUTE OF ENGINEERING &TECHNOLOGY

(Approved by A.I.C.T.E., New Delhi & Permanently Affiliated to JNTU GV)


Accredited by NAAC with ‘A’ Grade and Inclusion u/s 2(f) & 12(B) of UGC Act
An ISO 9001:2015, ISO 14001:2015 & ISO 45001:2018 Certified Institute.
NH-16, Anakapalle – 531002, Visakhapatnam, A.P.
Website: www.diet.edu.in,9963694444 E-mail: [email protected], [email protected]

LAB COURSE FILE

Academic Year : 2022-2023

Year & Semester : II-II

Course : B.Tech

Branch : CSE

Name of the Lab : Database Management Systems Lab

Name of the Faculty : Mr. S. Syam Kumar

Designation : Assistant Professor

Signature of Faculty Signature of the HOD


CONTENTS

1. Vision and Mission of the Institute and Department

2. Syllabus of the Course

3. PO, PEOs & PSO statements

4. Course Objectives & Outcomes

5. Lab Time Table

6. Lesson Plan

7. Roll List

8. Programs & Output

9. Internal Marks

10.External Marks

11. Result Analysis

12. CO-PO Attainment Sheet


INSTITUTE VISION & MISSION

VISION

To evolve into a premier technical institution ensuring academic excellence and


promoting innovational research.

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

DEPARTMENT VISION & MISSION

VISION

To contribute to the society through excellence in scientific and knowledge-based


education by utilizing the potential of Computer Science and Engineering with a deep
passion for Technology, Culture and Values.

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

PO1 Engineering An ability to apply knowledge of mathematics


knowledge (including probability, statistics and discrete
mathematics), science, and engineering for solving
Engineering problems and modelling
PO2 Problem Analysis An ability to design, simulate and conduct experiments,
as well as to analyze and interpret data including
hardware and software components

PO3 Design / An ability to design a complex electronic system or


development process to meet desired specifications and needs
of solutions
PO4 Conduct An ability to identify, formulate, comprehend, analyze,
investigations of design synthesis of the information to solve complex
complex engineering problems and provide valid conclusions.
problems
PO5 Modern tool usage An ability to use the techniques, skills and modern
engineering tools necessary for engineering practice

PO6 The engineer An understanding of professional, health, safety,


and society legal, cultural and social responsibilities

PO7 Environment The broad education necessary to understand the impact


and sustainability of engineering solutions in a global, economic,
environmental and demonstrate the knowledge need for
sustainable development
PO8 Ethics Apply ethical principles, responsibility and norms of the
engineering practice

PO9 Individual and team An ability to function on multi-disciplinary teams.


work
PO1 Communication An ability to communicate and present effectively

PO11 Project management An ability to use the modern engineering tools,


and finance techniques, skills and management principles to do work
as a member and leader in a team, to manage projects in
multi-disciplinary environments

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

Program Specific outcomes


PSO1:
 To understand the design aspects of operating system
 To study the process management concepts & Techniques
 To study the storage management concepts
 To familiarize students with the Linux environment
 To learn the fundamentals of shell scripting/programming

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

POs & PSO REFERENCE:

Engineering Environment & Problem Solving


PO1 PO7 PSO1
Knowledge Sustainability Skills
PO2 Problem Analysis PO8 Ethics PSO2 Professional Skills
Design &
Individual & Team
PO3 Development of PO9
Work
solutions
Conduct Investigations Communication
PO4 PO10
of Complex Problems Skills
Project
PO5 Modern Tools Usage PO11 Management &
Finance
PO6 Engineer & Society PO12 Life Long Learning
COURSE OBJECTIVES AND OUTCOMES
COURSE OBJECTIVES:
 To understand the design aspects of operating system
 To study the process management concepts & Techniques To study the storage management
concepts
 To familiarize students with the Linux environment
 To learn the fundamentals of shell scripting/programming

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

1: Slight (Low) 2: Moderate (Medium) 3: Substantial (High) - :None

ADDITIONAL EXPERIMENTS

PL/SQL Program to Find Factorial of a Number


1

PL/SQL Program to Find Reverse of a Number


2
Experiment-1
1) Creation, altering and dropping of tables and inserting rows into a table (use constraints while
creating tables) examples using SELECT command.
Create table st

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)

Insert into table st


SQL> insert into st values(101,'sai','a');
1 row created.
SQL> insert into st values(102,'ayisha','a+');
1 row created.

Select from table st


SQL> select * from st;
SID SNAME SGRAD

101 sai a
102 ayisha a+

Drop table st SQL> drop table st;


Table dropped.

Then check select then table will not exist


SQL> select * from st; select * from st

* 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:

To Create employee table:

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.

SQL> INSERT INTO EMPLOYEE VALUES('SMITH',NULL,1111,'03-NOV-2016','BJD','M',2000,NULL,10)


1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('ALLEN',NULL,2222,'03-NOV-2016','SBC','M',3000,1111,20)


1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('MARTIN',NULL,3333,'03-NOV-2016','HYD','M',4000,1111,30)


1 row created.

Like this we can insert the values into the table. To view data in the table following query is used

SQL> SELECT *FROM EMPLOYEE;

FNAME LNAME SSN BDATE ADDRESS G SALARY SUPER_SSN DNO


-------- --------- ----- -------- ----------- --- --------- ------------- -----
SMITH 1111 01-JAN-06 BZA M 2000 10 ALLEN 2222 12-DEC-04 SBC M 3000 1111 20 MARTIN 3333 15-
DEC-07 HYD M 4000 1111 20
JONES 4444 28-SEP-05 TNU M 1500 2222 10
BLAKE 5555 04-SEP-04 VZA M 2500 2222 10 TURNER 6666 21-OCT-99 GNT M 6000 3333 20

SQL> INSERT INTO DEPENDENT VALUES (1111,'SMITH',’G’)


1 row is created.

SQL> INSERT INTO DEPENDENT VALUES (2222,'POOJA',’F’)


1 row is created.

SQL> INSERT INTO DEPENDENT VALUES (3333,'MARTIN',’M’)


1 row is created.

SQL> INSERT INTO DEPENDENT VALUES (3333,'RAJA',’M’)


1 row is created.
To Create dependent table:

SQL> CREATE TABLE DEPENDENT (


ESSN NUMBER (4) REFERENCES EMPLOYEE (SSN),
DEPENDENT_NAME VARCHAR2 (20),
GENDER CHAR (1),
B_DATE DATE,
RELATIONSHIP VARCHAR2 (20), PRIMARY KEY (ESSN, DEPENDENT_NAME) );

Table created.

To view data in the dependent table as follows.

SQL>SELECT * FROM DEPENDENT;

ESSN DEPENDENT_NAME G B_DATE RELATIONSHIP


------ ---------------------- --- ------- ---------------------
1111 SMITH M
2222 POOJA F
3333 MARTIN M
3333 RAJA M

1.ALL:

Retrieve the names of employees whose salary is greater than the salary of all the employees in department 10

SQL> SELECT FNAME,


LNAME FROM EMPLOYEE WHERE SALARY> ALL ( SELECT SALARY FROM EMPLOYEE WHERE
DNO=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

SQL> SELECT e.FNAME, e.LNAME FROM EMPLOYEE e WHERE e.SSN IN ( SELECT


ESSN FROM DEPENDENT WHERE e.GENDER=GENDER AND e.FNAME =
DEPENDENT_NAME);

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

SQL> SELECT e.FNAME, e.LNAME FROM EMPLOYEE e WHERE EXISTS (SELECT


*FROM DEPENDENT WHERE e.SSN=ESSN AND e.GENDER=GENDER AND
e.FNAME = DEPENDENT_NAME);

FNAME LNAME
--------- -----------
SMITH
MARTIN

5.NOT EXISTS :

Retrieve the names of employees who have no dependents

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.

Create table product

SQL> create table product(pno int ,pname varchar(30),price float,quantity int);


Table created.

Insert into product

SQL> insert into product values(1,'dairy milk',60,2);


1 row created.

SQL> insert into product values(2,'good day',25,4);


1 row created.

SQL> insert into product values(3,'boost',10,6);


1 row created.

SQL> insert into product values(4,'maggi',5,10);


1 row created.

SQL> insert into product values(5,'book',20,20);


1 row created.

Select from product

SQL> select * from product;

PNO PNAME PRICE QUANTITY

1 dairy milk 60 2
2 good day 25 4
3 boost 10 6
4 maggi 5 10
5 book 20 20

Count function

SQL> select count(price) from product;

COUNT(PRICE)
5
SQL> select count(quantity) from product;

COUNT(QUANTITY)
5

Sum function

SQL> select sum(price) from product;

SUM(PRICE)
120

SQL> select sum(quantity) from product;

SUM(QUANTITY)
42

Avg function

SQL> select avg(price) from product;

AVG(PRICE)
24

SQL> select avg(quantity) from product;

AVG(QUANTITY)
8.4

Max function

SQL> select max(price) from product;

MAX(PRICE)
60

SQL> select max(quantity) from product;

MAX(QUANTITY)
20

Min function

SQL> select min(price) from product;


MIN(PRICE)
5

SQL> select min(quantity) from product;


MIN(QUANTITY)
2
Group by

Create table employ(sid int,name varchar(20),dept varchar(10),sal float);

Table created

Select * from employ

Sid name dept sal


1 ayisha ece 6000
2 sindhu it 50000
3 sai it 80000
4 lalli ece 8000

SQL>select dept,sum(sal) from employ group by dept; Dept

sum(sal)
It 130000
Ece 14000

Having

SQL>select dept,sum(sal) from employ group by dept having sum(sal)>25000;

Dept sum(sal)
It 130000

Creating views

Create table st(sid int,sname varchar(10));

Create table marks(sid int,sub1 int,sub2 int,sub3 int);

Create view stu as

Select st.sid,st.sname,marks.sub1,marks.sub2,marks.sub3 From st,marks


Where st.sid=marks.sid;

Select * from stu;

Sid sname sub1 sub2 sub3


101 sai 100 90 95
Experiment-4

Queries using Conversion functions (to_char,to_number and to_date),stringfunctions(Concatenation,


lpad, rpad, ltrim, rtrim, lower,upper, initcap, length, substr and instr), datefunctions (Sysdate,
next_day, add_months,last_day, months_between, least, greatest, trunc,round, to_char, to_date)

Conversion functions 1.to_char

Create table db(dob date)

Select to_char(dob,’month dd,year’);


To_char(dob,’month dd,year’)

May 21,nineteen ninety-six

2. to_number

SQL> select to_number('234.87') from dual;

TO_NUMBER('234.87')

234.87

3. to_date

SQL> select to_date('jan 21 1998','month dd,yy') from dual;

TO_DATE('
21-JAN-98

String functions 1.lower


SQL> select lower('SAI') from dual;

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

SQL> select sysdate from dual;


SYSDATE
20-NOV-15

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

SQL> select add_months(sysdate,2) from dual;

ADD_MONTH
20-JAN-16

5. months_between

SQL> select months_between('20-nov-2015','20-jan-2016') from dual;

MONTHS_BETWEEN('20-NOV-2015','20-JAN-2016')

6. least
SQL> select least(10,11,12) from dual;

LEAST(10,11,12)
10

SQL> select least('s','f','a') from dual;


L
a

7. greatest

SQL> select greatest(10,11,12) from dual;

GREATEST(10,11,12)
12

SQL> select greatest('s','f','a') from dual; G


-
S
8. ground
SQL> select round(21.088) from dual;

ROUND(21.088)
21

SQL> select trim(21.088) from dual;

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)

Create table student (sid, sname, sclass);

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

PL/SQL procedure successfully completed.


ii) Insert data into student table and use COMMIT, ROLLBACK and SAVEPOINT in PL/SQL
block.

Create table stu(name varchar(10),branch varchar(10)); Insert into stu values(‘sai’,’it’);

Savepoint h;

Savepoint created

SQL> set serveroutput on;

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;

(2) SEARCHED CASE EXPRESSION:

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:

This returns the first non-NULL expression among its arguements.


syntax:
coalesce("expression1","expression2",...);

(4) NULL IF:


Takes two arguements.If the two arguments are equal,then NULL is returned.otherwise the first arguement
is returned.
syntax:

select column_name, NULLIF(argument1, argument2) from ttabe_name:

(5) PROGRAM FOR CASE:

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.

2) AIM: Simple loop to get sum of 100 numbers


Declare
a number;
s1 number default 0; begin
a:=1;
loop s1:=s1+a;
exit when(a=100); a:=a+1;
end loop;
dbms_output.put_line('sum between 1 to 100 is' || s1); end;
/
output:
sum between 1 to 100 is5050
PL/SQL procedure successfully completed.

3) AIM: While Loop for sum of 100 odd numbers Program:

SQL> declare n number;


endvalue number; sum1 number default 0;
begin endvalue:=&endvalue; n:=1;
while(n<endvalue) loop sum1:=sum1+n; n:=n+2;
end loop;
dbms_output.put_line('sum of odd numbers between 1 and ' || endvalue || 'is' || sum1); end;
/
Output:
Enter value for endvalue: 19 old 6: endvalue:=&endvalue;
new 6: endvalue:=19;
sum of odd numbers between 1 and 19 is 81
PL/SQL procedure successfully completed.

4) AIM: if else for finding maximum of three numbers Program:


SQL> declare a number;
b number; c number; begin a:=&a;
b:=&b;
c:=&c; if(a>b)and(a>c)then
dbms_output.put_line(' a is maximum'); elsif(b>a)and(b>c)then dbms_output.put_line('b is maximum'); else
dbms_output.put_line('c is maximum'); end if;
end;
/
Output:
Enter value for a: 10 old 6: a:=&a;
new 6: a:=10; Enter value for b: 4 old 7: b:=&b;
new 7: b:=4; Enter value for c: 19 old 8: c:=&c;
new 8: c:=19;

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.

->create table enquiry(enqno1 number,fname varchar2(30));


->insert into enquiry values(111,'sai');
->insert into enquiry values(112,'sindhu');

/*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.

->create table dept(deptno int,dname varchar(10));


->insert into dept values(1219,'sai');

/*program*/

create or replace function getname(dno number) return varchar2 as


fname1 varchar2(30); begin
select dname into fname1 from dept
where deptno=dno; return(fname1);
exception
when no_data_found then
raise_application_error(-20100,'The dno is present');
end;
/

/*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.

(1) create a table dept1


->create tabke dept1(dname varchar2(10),deptno number);
->insert into dept values('accounting',10);
->insert into dept values('hr',20);

(2) create a table dept

->create table dept(dno number,vt varchar2(10),dloc varcar2(20));

(3) creating package header


create or replace package test is

procedure savedept
(dno in number,dloc in varchar);
end;
/
(4) creating package body

create or replace package body test is


function getdno(dno in number) return varchar
is
dnum varchar(20); begin
select dname into dnum from dept where deptno=dno;
return dnum; end;
procedure savedept
(dno in number,dloc in varchar) is
vt varchar(20) begin vt:=getno(dno);
insert into dept values(dno,vt,dloc); exception
when dup_val_on_index then raise_application_error(-2007,'duplicate');
end;
end;
/
(5) Executing procedure

exec test.savedept(10,'vijayawada');

(6) Display the table

->select * from dept;


Experiment-11
11) Develop programs using features parameters in a CURSOR, FOR UPDATE CURSOR, WHERE
CURRENT of clause and CURSOR variables.
CURSORS

AIM: create an employ table and retrieve the name of employ whose salary is Greater than 25000 by
PL/SQL

Create table employ(eid,ename,salary);

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

PL/SQL procedure successfully completed.


Experiment-12

12) Develop programs using before and after triggers, row and statement triggers and instead of
triggers.

(1) Create a trigger

create or replace trigger trg2 after insert or delete or update on dept1


for each row when(new.deptno>0)

begin
dbms_output.put_line('trigger fired'); end;
/
(2) Insert

->insert into dept values('sindhu',30);


*trigger fired*
*1 row created*
(3) UPADTE

->udpate dept1 set deptno=19 where dname='sindhu';


*trigger fired*
*1 row updated*
(4) DELETE

->delete from dept where deptno=30;


*trigger fired*
*1 row deletd*

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.

sql> insert into teacher values('t101','sunitha','mca','29-jun-06','associate


professor','vijayawada',9985061308,23000,'mca');
1 row created.

sql>insert into teacher values('t102','fred smith','mtech','07-mar-03','associate


professor','guntur',9985063445,36000,'mba');
1 row created.

sql>insert into teacher values('t103','jack barnes','btech','27-jun07','professor','tenali',9985012345,27000,'mtech');


1 row created.
sql>insert into teacher values('t104','jane doe','mca','04-jul-06','assistant
professor','vijayawada',9985045678,29000,'btech');
1 row created.

to show the query execution timing use the following query


sql> set timing on;

retrieve details of teacher before creation of index.

sql> select *from teacher;

staf staff_name qualificat hiredate job address ph_num salary department


---- ---------------- -------------- ---------- ----- ----------- ---------- --------- --------------
t101 sunitha mca 29-06-06 associate professor vijayawada 9985061308 23000 mca
t102 fred smith mtech 07-mar-03 associate professor guntur 9985063445 36000 mba
t103 jack barnes btech 27-jun-07 professor tenali 9985012345 27000 mtech
t104 jane doe mca 04-jul-06 assistant professor vijayawada 9985045678 29000 btech

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

2) PL/SQL Program to Find Reversal of a Number

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

You might also like