DMS
DMS
DMS
Write a PL/SQL program that prints numbers from 1 to 10, but skips printing the
number 5 [Use
GOTO statement]
declare
i number:=1;
begin
loop
if i=5 then
i:=i+1;
goto skip;
end if;
dbms_output.put_line(i);
i:=i+1;
<<skip>>
END loop;
end;
/
------------------------------------------
Practical 13:- Implement PL/SQL program based on Exception Handling (Pre -defined
exceptions)
application.
Write a PL/SQL program that asks the user to input two numbers and divide the first
number by
the second. Handle the predefined exception for division by zero and display an
appropriate message if
it occurs.
declare
a number:=10;
b number :=0;
c number;
begin
c:=a/b;
dbms_output.put_line('Division: '||c);
exception
when ZERO_DIVIDE then
dbms_output.put_line('Error: Can not divide by zero');
end;
/
----------------------------------------------
Practical 14:- Implement PL/SQL program based on Exception Handling (User -defined
exceptions).
Write a PL/SQL program that asks for customer Id, when user enters invalid Id, the
exception Invalid-
Id is raised.
declare
id number:=-1;
invalid_id exception;
begin
if id<0 then
raise invalid_id;
else
dbms_output.put_line('Login');
end if;
exception
when invalid_id then
dbms_output.put_line('Error: Id can not be negative');
end;
/
---------------------------------------------------
Practical 16:-Create Implicit and Explicit Cursor
Implicit cursor
create table customers(id number,name varchar(20),salary number);
insert into customers values(1,'Prerana',80000),(2,'Dnyaneshwari',90000);
UPDATE customers set salary=100000 where id=1;
DECLARE
total_rows number(2);
BEGIN
UPDATE customers
SET salary = salary + 5000;
IF sql%notfound THEN
dbms_output.put_line('no customers updated');
ELSIF sql%found THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' customers updated ');
END IF;
END;
/
=========================================
Explict
create table customers(id number,name varchar(20),salary number,address
varchar(20));
insert into customers values(1,'Prerana',80000,'Shirbhavi'),
(2,'Dnyaneshwari',90000,'Bardi');
DECLARE
c_id customers.id%type;
c_name customers.name%type;
c_addr customers.address%type;
CURSOR c_customers is
SELECT id, name, address FROM customers;
BEGIN
OPEN c_customers;
LOOP
FETCH c_customers into c_id, c_name, c_addr;
EXIT WHEN c_customers%notfound;
dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);
END LOOP;
CLOSE c_customers;
END;
----------------------------------------------
Practical 17:-Create Function for Given database
Write a Function to calculate factorial of given no.
DECLARE
result number;
BEGIN
result:=factorial(5);
dbms_output.put_line('Factorial :'||result);
END;
/
---------------------------------------------------
Practical 10:- Implement PL/SQL program using Conditional Statements.
Write a PL/SQL program that asks the user for their age and then prints “You can
vote" if they are
over 18, and "You cannot vote" otherwise.
declare
age int:=&age;
begin
if age>=18 then
dbms_output.put_line('You can vote');
else
dbms_output.put_line('You can not vote');
end if;
end;
/
--------------------------------------------------
declare
num int:=#
fact int:=1;
begin
for i in 1..num loop
fact:=fact*i;
end loop;
dbms_output.put_line('Factorail: '||fact);
end;
/
------------------------------------------------------
Practical 1:- Execute DDL commands to manage Database using SQL.
1. Create a table for stud using attributes Rollno, Studname, Percentage apply
primary key for rollno.
2. Change the stud table structure by adding column City.
3. Increase the size by 10 of studentname column.
------------------------------------------------
Practical 2:- Execute DML Commands to manipulate data using SQL.
1.Create table EMP with attributes EMPNO, ENAME, DNAME, JOB.
2.Insert any 4 records.
3.Change the job of any employee to Manager.
4.Display all records.
-------------------------------------------------------
Practical 9:- Create and manage Views for faster access to relations.
1. Write query of the following :
i. Create view emp_view with attribute emp_no, ename, salary on EMP table.
ii. Update view set ename to Jay having emp_no 101.
iii. Delete the record of the employee where emp_no is 102.
iv. Drop created view.