0% found this document useful (0 votes)
22 views2 pages

CSL 333-Set-B

Uploaded by

blueyard38
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)
22 views2 pages

CSL 333-Set-B

Uploaded by

blueyard38
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/ 2

CSL 333 DATABASE MANAGEMENT SYSTEM LAB

Date: 15/11/2024 (Friday), Time: 11:30 am to2:30 pm

SET B

1. Write a PL/SQL program to check whether the number is Armstrong number or not.

using functions.
ANS:

DECLARE

num NUMBER := 153;

result BOOLEAN;

FUNCTION is_armstrong_number(num IN NUMBER)

RETURN BOOLEAN

IS

original_num NUMBER := num;

sum_of_digits NUMBER := 0;

temp_num NUMBER := num;

digit NUMBER;

BEGIN

WHILE temp_num > 0 LOOP

digit := MOD(temp_num, 10);

sum_of_digits := sum_of_digits + POWER(digit, 3);

temp_num := TRUNC(temp_num / 10);

END LOOP;

RETURN sum_of_digits = original_num;

END;

BEGIN

result := is_armstrong_number(num);

IF result THEN

DBMS_OUTPUT.PUT_LINE(num || ' is an Armstrong number.');

ELSE

Downloaded from Ktunotes.in


DBMS_OUTPUT.PUT_LINE(num || ' is not an Armstrong number.');

END IF;

END;

2. Create the following tables and insert values into the tables :

faculty (fno. name, gender, age,salary,dnum)

department (dno, dname, dphone)

course (cuo, cname, credits, odno)

Primary keys are underlined. dnum is a foreign key that identifies the department to

which a faculty belongs. odno is a foreign key identifying the department that offers a

course

a. Increment the salary of male faculty members with age more than 50 by 10%.
ANS:
update faculty set salary = salary*1.1 where age>50 and gender='Male';

b. Display the department name of faculty with highest salary.


ANS:
SELECT d.dname FROM faculty f JOIN department d ON f.dno = d.dnoWHERE f.salary = (SELECT
MAX(salary) FROM faculty);

c. Display the name of departments offering more than 2 courses.


ANS:
SELECT d.dname FROM department d JOIN course c ON d.dno = c.dno GROUP BY d.dname HAVING
COUNT(c.cname) >= 2;

d. Names of departments along with number of courses offered by each of them,

in the increasing order of number of courses.


ANS:
SELECT d.dname, COUNT(cno) AS num_courses FROM department d JOIN course c ON d.dno = c.dno
GROUP BY d.dname ORDER BY num_courses ASC;

Downloaded from Ktunotes.in

You might also like