DBMS Lab Reg-19bps1006 Name-Vikrant TH Assignment 9 SQL Screenshots

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

DBMS lab

Reg-19bps1006
Name-vikrant th
ASSIGNMENT 9
Sql screenshots:

1.

3.
4.
5.Function to check whether prime or not.
CREATE OR REPLACE FUNCTION prime(num number)
RETURN number
IS
i number(3);
f number(2);
BEGIN
f:=0;
FOR i IN 2..num 
LOOP
IF mod(num,i)=0
THEN
f:=f+1;
END IF;
END LOOP;
RETURN f;
END;
/

DECLARE
num number(3);
f number(3);
BEGIN
num:='&num';
f:=prime(num);

IF f>1
THEN
dbms_output.put_line('Not Prime');
ELSE
dbms_output.put_line('Prime');
END IF;
END;
/

6.Function to find sum of digits and add its value.


CREATE OR REPLACE FUNCTION fact(n number)
RETURN number is
BEGIN
IF n=1 THEN
RETURN 1;
ELSE
RETURN n*fact(n-1);
END IF;
END;
/

DECLARE
num number;
BEGIN
num:='&num';
dbms_output.put_line('Factorial=' || fact(num));
END;
/

7. Recursive function to print the factorial of a number.

8.
i. Input emp id and display salary.

ii. Delete details of retired employee.


iii. Update salary of all employees.
iv. Number of employees in each department.
declare
dname1 dept.dname%type;
dn dept.dno%type;
procedure dpt(dept out varchar2) is
begin
select dname, count(dno) from dept group by dno;
end;
/

You might also like