[go: up one dir, main page]

0% found this document useful (0 votes)
12 views5 pages

DBMS Assgn5

Dbms assignment

Uploaded by

sudibratag
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)
12 views5 pages

DBMS Assgn5

Dbms assignment

Uploaded by

sudibratag
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/ 5

Assignment No – 5

1. Write a PL/SQL program to print the first 10 fibonacci number.


2. Write a PL/SQL program to invert a number 5639 to 9365.
3. Write a PL/SQL program to calculate the radius and area of a circle for a value of radius varying
from 3 to 7. Store the radius and corresponding values of calculated areas in table
circle(radius,area).
4. Write a PL/SQL program to check whether a given number is palindrome or not.
5. Write a PL/SQL program to check whether a given number is prime or not.
6. Write a PL/SQL program to check whether a given number is even or odd.

1. Print first 10 fibonacci numbers


set serveroutput on;
DECLARE
n NUMBER(10) := 10;
first_fib NUMBER(10) := 0;
second_fib NUMBER(10) := 1;
next_fib NUMBER(10);
BEGIN
DBMS_OUTPUT.PUT_LINE('First ' || n || ' Fibonacci numbers:');
DBMS_OUTPUT.PUT_LINE(first_fib);
DBMS_OUTPUT.PUT_LINE(second_fib);

FOR i IN 3..n LOOP


next_fib := first_fib + second_fib;
DBMS_OUTPUT.PUT_LINE(next_fib);
first_fib := second_fib;
second_fib := next_fib;
END LOOP;
END;
/
2. Invert number 5639 to 9365.
set serveroutput on;
DECLARE
num NUMBER(10) := 5639;
inverted_num NUMBER(10) := 0;
remainder NUMBER(10);
BEGIN
WHILE num > 0 LOOP
remainder := num MOD 10;
inverted_num := inverted_num *10 + remainder;
num := num / 10;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Original Number: 5639');
DBMS_OUTPUT.PUT_LINE('Inverted Number: '|| TO_CHAR(inverted_num));
END;
/

3. Calculate the radius and area of a circle and store them in table Circle(radius, area).
set serveroutput on;
CREATE TABLE circle (
radius NUMBER(10),
area NUMBER(20)
);
DECLARE
radius_var NUMBER(10);
area_var NUMBER(20);
BEGIN
FOR radius_var IN 3..7 LOOP
area_var := ROUND(3.14159 * radius_var * radius_var, 2);
INSERT INTO circle (radius, area) VALUES (radius_var, area_var);
DBMS_OUTPUT.PUT_LINE('Radius: ' || radius_var || ', Area: ' || area_var);
END LOOP;
END;
/
4. Check whether entered number is Palindrome or not.
set serveroutput on;
DECLARE
num NUMBER(10):= &Num; -- Enter the number you want to check
original_num NUMBER(10) := num;
reversed_num NUMBER(10):= 0;
remainder NUMBER(10);
BEGIN
-- Reverse the number
WHILE (num > 0) LOOP
remainder := num MOD 10;
reversed_num := reversed_num * 10 + remainder;
num := num / 10;
END LOOP;

-- Check if the original number is equal to its reverse


IF original_num = reversed_num THEN
DBMS_OUTPUT.PUT_LINE('The number ' || original_num || ' is a palindrome.');
ELSE
DBMS_OUTPUT.PUT_LINE('The number ' || original_num || ' is not a palindrome.');
END IF;
END;
/
5. Check whether entered number is Prime or not.
set serveroutput on;
DECLARE
num NUMBER(10) := &Num;
is_prime BOOLEAN := TRUE;
BEGIN
FOR i IN 2..ROUND(SQRT(num)) LOOP
IF num MOD i = 0 THEN
is_prime := FALSE;
EXIT;
END IF;
END LOOP;
IF is_prime AND num > 1 THEN
DBMS_OUTPUT.PUT_LINE('The number ' || num || ' is a prime number.');
ELSE
DBMS_OUTPUT.PUT_LINE('The number ' || num || ' is not a prime number.');
END IF;
END;
/
6. Check whether entered number is Even or Odd.
set serveroutput on;
DECLARE
num NUMBER(10) := &Num;
BEGIN
IF num MOD 2 = 0 THEN
DBMS_OUTPUT.PUT_LINE('The number ' || num || ' is even.');
ELSE
DBMS_OUTPUT.PUT_LINE('The number ' || num || ' is odd.');
END IF;
END;
/

You might also like