0% found this document useful (0 votes)
13 views4 pages

ASS6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

ASS6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

HU22CSEN0100515

D.CHANDAN

Assignment 6 : Assignment-7
Write PL/SQL programs for the following

1. To print the sum of digits of a number


DECLARE
num NUMBER := #
digit NUMBER;
sum_digits NUMBER := 0;
BEGIN
WHILE num > 0 LOOP
digit := num MOD 10;
sum_digits := sum_digits + digit;
num := num / 10;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Sum of digits: ' || sum_digits);
END;
/
HU22CSEN0100515
D.CHANDAN

2. To print the reverse of a number


DECLARE
num NUMBER := #
reverse_num NUMBER := 0;
digit NUMBER;
BEGIN
WHILE num > 0 LOOP
digit := num MOD 10;
reverse_num := reverse_num * 10 + digit;
num := num / 10;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Reverse of the number: ' || reverse_num);
END;
/
HU22CSEN0100515
D.CHANDAN

3. To perform arithmetic operation using case statement


DECLARE
num1 NUMBER := &num1;
num2 NUMBER := &num2;
operation CHAR(1) := '&operation';
result NUMBER;
BEGIN
CASE operation
WHEN '+' THEN
result := num1 + num2;
WHEN '-' THEN
result := num1 - num2;
WHEN '*' THEN
result := num1 * num2;
WHEN '/' THEN
result := num1 / num2;
ELSE
DBMS_OUTPUT.PUT_LINE('Invalid operation');
RETURN;
END CASE;
DBMS_OUTPUT.PUT_LINE('Result: ' || result);
END;
/
HU22CSEN0100515
D.CHANDAN

4. To find the factorial of a number


DECLARE
num NUMBER := #
factorial NUMBER := 1;
BEGIN
FOR i IN 1..num LOOP
factorial := factorial * i;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Factorial of ' || num || ' is: ' || factorial);
END;
/

You might also like