DBMS Practical
DBMS Practical
EXPERIMENT NO: 5
Algorithm:
1. Declare variables for input number, factorial result, and loop counter.
2. Accept the input number.
3. Initialize the factorial result to 1.
4. Use a loop to multiply numbers from 1 to the input number.
5. Display the factorial result.
Code:
DECLARE
num NUMBER := 5;
factorial NUMBER := 1;
i NUMBER;
BEGIN
FOR i IN 1..num LOOP
factorial := factorial * i;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Factorial of ' || num || ' is ' || factorial);
END;
/
Screenshot:
Sample Input/Output:
Input: 5
Output: Factorial of 5 is 120.
Outcome:
Successfully calculated the factorial of a number using a FOR loop in PL/SQL and displayed the result.
Algorithm:
Code:
DECLARE
i NUMBER;
BEGIN
is_prime := FALSE;
ELSE
IF MOD(num, i) = 0 THEN
is_prime := FALSE;
EXIT;
NAME: CHIRAG DUGAR DATE OF SUBMISSION:19/11/2024
REG NO: 22BAI10161 BRANCH: COMPUTER SCIENCE WITH SPECIALIZATION IN AI/ML
CSE3001-DBMS LABORATORY SHEET-EXERCISE SHEET
END IF;
END LOOP;
END IF;
IF is_prime THEN
ELSE
END IF;
END;
Screenshot:
Sample Input/Output:
Input: 371
Output: 371 is not a prime number.
Outcome:
Successfully determined if a number is prime by iterating over possible divisors and checking for
divisibility.
Algorithm:
Code:
DECLARE
i NUMBER;
BEGIN
END LOOP;
END;
Screenshot:
Sample Input/Output:
Input: chirag
Outcome:
Successfully reversed a given string by iterating over its characters in reverse order and displayed the
reversed string.
EXPERIMENT NO: 6
Algorithm:
Code:
DECLARE
n NUMBER := 10;
total_sum NUMBER := 0;
BEGIN
total_sum := total_sum + i;
END LOOP;
END;
/
Screenshot:
Sample Input/Output:
Input: 10
Outcome:
Successfully calculated the sum of the first N natural numbers using a FOR loop and displayed the
result.
Algorithm:
Code:
DECLARE
num NUMBER := 5;
i NUMBER;
BEGIN
END LOOP;
END;
Output Screenshot:
Sample Input/Output:
Input: 5
Outcome:
Successfully generated and displayed the multiplication table for a given number using a loop in
PL/SQL.
Algorithm:
Code:
NAME: CHIRAG DUGAR DATE OF SUBMISSION:19/11/2024
REG NO: 22BAI10161 BRANCH: COMPUTER SCIENCE WITH SPECIALIZATION IN AI/ML
CSE3001-DBMS LABORATORY SHEET-EXERCISE SHEET
DECLARE
BEGIN
IF MOD(num, 2) = 0 THEN
ELSE
END IF;
END;
Screenshot:
Sample Input/Output:
Input: 5578
Outcome:
Successfully checked whether a number is even or odd using an IF/ELSE statement and displayed the
appropriate result.
AIM: To create a procedure that adds two numbers and returns the result.
Algorithm:
Code:
BEGIN
result := a + b;
END;
DECLARE
res NUMBER;
BEGIN
END;
Screenshot:
Sample Input/Output:
Input: 10, 20
Output: Sum is 30
Outcome:
Successfully created a stored procedure that accepts two input parameters, calculates their sum, and
returns the result using an OUT parameter.
Algorithm:
Code:
BEGIN
IF a > b THEN
max := a;
ELSE
max := b;
END IF;
END;
DECLARE
maxValue NUMBER;
BEGIN
END;
Screenshot:
Sample Input/Output:
Input: 15, 10
Output: Maximum is 15
Outcome:
Successfully created a stored procedure to determine the maximum of two numbers by comparing
them and returned the result using an OUT parameter.
Algorithm:
Code:
BEGIN
END;
BEGIN
GreetUser('Chirag');
END;
Screenshot:
Sample Input/Output:
Input: Chirag
Output: Hello,Chirag
Outcome:
Successfully created a stored procedure that accepts a user’s name as input and displays a
personalized greeting message.
Algorithm:
Code:
BEGIN
END;
DECLARE
areaValue NUMBER;
BEGIN
CircleArea(5, areaValue);
END;
/
Screenshot:
Sample Input/Output:
Input: 5
Outcome:
Successfully created a stored procedure that accepts the radius as input, calculates the area of the
circle using the formula πr², and returns the result using an OUT parameter.