Professional Documents
Culture Documents
Solution:
declare
n number:=&n;
begin
if mod(n,2)=0
then
dbms_output.put_line('number is even');
else
dbms_output.put_line('number is odd');
end if;
end;
/
Write a PL/SQL program for inserting even numbers in EVEN table and odd number
in ODD table from number 1 to 50. (WINTER -17)
Solution:
DECLARE
BEGIN
IF MOD(i,2)= 0 THEN
ELSE
END IF;
END LOOP;
COMMIT;
END;
Write a PL/SQL block to print the given number is prime or not. (SUMMER-18)
Solution:
DECLARE
NUM NUMBER;
I NUMBER:=1;
C NUMBER:=0;
BEGIN
NUM:=#
FOR I IN 1..NUM
LOOP
IF((MOD(NUM,I))=0)
THEN
C:=C+1;
END IF;
END LOOP;
IF(C>2)
THEN
ELSE
DBMS_OUTPUT.PUT_LINE(NUM||' IS PRIME');
END IF;
END;
/
Write a PL/SQL block to print the sum of Numbers from 1 to 100.(SUMMER-19)
Solution:
DECLARE
A NUMBER;
BEGIN
A:=1;
LOOP
SUM1:=SUM1+A;
A:=A+1;
END LOOP;
END;
Write a PL/SQL block to print the sum of even numbers from 1 to 50.(SUMMER-20)
Solution:
declare
odd number:=0;
even number:=0;
i number;
begin
for i in 1..50
loop
even:=even+i;
else
odd:=odd+i;
end if;
end loop;
end;