Skip to content

Latest commit

 

History

History
87 lines (69 loc) · 1.57 KB

Ex-10.md

File metadata and controls

87 lines (69 loc) · 1.57 KB

PL/SQL Conditional and Iterative Statements

1. Get FARENHEIT and convert into CELSIUS

DECLARE
   fahrenheit NUMBER;
   celsius NUMBER;
BEGIN
   DBMS_OUTPUT.PUT('Enter temperature in Fahrenheit: ');
   fahrenheit := &fahrenheit;
   
   celsius := (fahrenheit - 32) * 5/9;
   
   DBMS_OUTPUT.PUT_LINE('Temperature in Celsius: ' || celsius);
END;

2. Write a pl/sql program to find SUM OF EVEN INTEGERS

DECLARE
   sum NUMBER = 0;
BEGIN
   FOR i IN 1..10 LOOP
      IF i MOD 2 = 0 THEN
         sum = sum + i;
      END IF;
   END LOOP;

   DBMS_OUTPUT.PUT_LINE('Sum of even integers from 1 to 10: ' || sum);
END;

3. Write a pl/sql program to find GREATEST OF THREE NUMBERS USING IF ELSEIF

DECLARE
   a NUMBER := &a;
   b NUMBER := &b;
   c NUMBER := &c;
   max NUMBER;
BEGIN
   max := a;
   
   IF b > max THEN
      max := b;
   END IF;
   
   IF c > max THEN
      max := c;
   END IF;
   
   DBMS_OUTPUT.PUT_LINE('The greatest of ' || a || ', ' || b || ', and ' || c || ' is ' || max);
END;

4. Write a pl/sql program to find a number is ODD OR EVEN

DECLARE
  num NUMBER;
BEGIN
  num := #
  
  IF num MOD 2 = 0 THEN
     DBMS_OUTPUT.PUT_LINE(num || ' is even');
  ELSE
     DBMS_OUTPUT.PUT_LINE(num || ' is odd');
  END IF;
END;

5. Write a pl/sql program to find a 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;