0% found this document useful (0 votes)
134 views

Assignment 3-4 101715087

This document is a practical activity report submitted by Mridul Mahindra (Roll Number 101715087) for their Database Management Systems course. It contains 5 questions exploring exception handling in PL/SQL including declaring exceptions, initializing exceptions, and exception propagation between inner and outer blocks.

Uploaded by

Mridul Mahindra
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)
134 views

Assignment 3-4 101715087

This document is a practical activity report submitted by Mridul Mahindra (Roll Number 101715087) for their Database Management Systems course. It contains 5 questions exploring exception handling in PL/SQL including declaring exceptions, initializing exceptions, and exception propagation between inner and outer blocks.

Uploaded by

Mridul Mahindra
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/ 17

A Practical Activity Report For

Database Management Systems (UCS310)

Submitted By:

Name: Mridul Mahindra


Roll Number: 101715087
Group: ENC - 4

Submitted To:
Dr. Sidharth Quamara

Depatment of Computer Science and Engineering

THAPAR INSTITUTE OF ENGINEERING & TECHNOLOGY, (DEEMED TO BE


UNIVERSITY), PATIALA, PUNJAB
Lab Assignment 3

Q1.
DECLARE
n emp.name%type;
BEGIN
select name into n from emp where no = 101715087;
dbms_output.put_line('name is ' || n);
EXCEPTION
when no_data_found then
dbms_output.put_line('No Record Found');
when too_many_rows then
dbms_output.put_line('Returned More Than One Record');
END;
/
Output:
Q2.
BEGIN
insert into emp values (101715087, 'Mridul', 2020);
EXCEPTION
WHEN dup_val_on_index THEN
dbms_output.put_line('attempting to duplicate values in a unique column');
WHEN zero_divide THEN
dbms_output.put_line('dividing by zero');
WHEN invalid_number THEN --conversion of character string to number in
sql statement
dbms_output.put_line('conversion of character string to number in sql');
END;
/
Output:
Q3.
INVALID_NUMBER
DECLARE
n number(2);
BEGIN
insert into emp values (101715087, 'Mridul', 'Mahindra');
EXCEPTION
WHEN invalid_number THEN --conversion of character string to number in
sql statement
dbms_output.put_line('conversion of character string to number in sql');
END;
/
Output:
VALUE_ERROR
DECLARE
n number(2);
BEGIN
n := 'Mridul';
EXCEPTION
WHEN value_error THEN
dbms_output.put_line('converting character string into number in
procedural');
END;
/
Output:
Q4.
DECLARE
x EXCEPTION;
PRAGMA EXCEPTION_INIT (x, -01438);
BEGIN
insert into emp values (101715083101715083, 'mayank', 2025);
EXCEPTION
WHEN x THEN
dbms_output.put_line('non-predifined exception raised');
END;
/
Output:
Q5.
DECLARE
zero EXCEPTION;
PRAGMA EXCEPTION_INIT (zero, -01476);
BEGIN
insert into emp values (1/0, 'mayank', 2025);
EXCEPTION
WHEN zero THEN
dbms_output.put_line('dividing by zero');
END;
/
Output:
Lab Assignment 4

Q1.
DECLARE
diff number(4);
e EXCEPTION;
book number(10);
BEGIN
insert into lib values (101715087, 2020, to_date('04/11/2020', 'dd/mm/yyyy'),
to_date('22/11/2020', 'dd/mm/yyyy'));
select (dor - doi) into diff from lib where rno = 101715087;
dbms_output.put_line(diff);
if diff > 15 then
raise e;
else
dbms_output.put_line('successfully executed');
end if;
commit;
EXCEPTION
when e then
select bookno into book from lib where rno = 101715087;
insert into late values (101715087, book);
END;
/
OUTPUT:
Q2.
create table emp (no number(10), name varchar(20), deptID number(10));
insert into emp values (101715087, 'Mridul', 2020);
create table error_info (err_num number(10), err_msg char(100));
DECLARE
n emp.name%type;
err_num number(10);
err_msg char(100);
BEGIN
select name into n from emp where no = 1/0;
dbms_output.put_line('name is ' || n);
EXCEPTION
when others then
err_num := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 100);
insert into error_info values (err_num, err_msg);
dbms_output.put_line('other error');
END;
/
select * from error_info;
OUTPUT:

Q3.
BEGIN
DECLARE
--error handling in declare dection
n number(3) := to_number('Mridul');
BEGIN
dbms_output.put_line(n);
EXCEPTION
WHEN others THEN
dbms_output.put_line('error raised in inner block');
END;
EXCEPTION
WHEN others THEN
dbms_output.put_line('error raised in outer block');
END;
OUTPUT:

Q4.
DECLARE
a exception;
b exception;
BEGIN
DECLARE
n number(10) := 43;
BEGIN
if n > 20 then
raise a;
else
raise b;
end if;
EXCEPTION
WHEN a THEN
dbms_output.put_line('a: error raised in inner block');
raise b; --raising exception in exception section
WHEN b THEN
dbms_output.put_line('b: error raised in inner block');
raise a;
END;
EXCEPTION
WHEN a THEN
dbms_output.put_line('a: error raised in outer block');
WHEN b THEN
dbms_output.put_line('b: error raised in outer block');
END;
/
OUTPUT:
Q5.
DECLARE
a exception;
b exception;
BEGIN
DECLARE
n number(10) := 25;
BEGIN
if n > 20 then
raise a;
else
raise b;
end if;
EXCEPTION
WHEN a THEN
dbms_output.put_line('a: error raised in inner block');
raise b;
WHEN b THEN
dbms_output.put_line('b: error raised in inner block');
raise a;
END;
EXCEPTION
WHEN a THEN
dbms_output.put_line('a: error raised in outer block');
WHEN b THEN
dbms_output.put_line('b: error raised in outer block');
END;
/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy