You are on page 1of 5

S. S.

Agrawal Institute of Engineering & Technology, Navsari


Computer Engineering Department

GTU Asked Program Solution

Subject Name: Database Management Systems-3130703


Write a PL/SQL block to print the given number is odd or even. (SUMMER-20)

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

FOR i IN 1..50 LOOP

IF MOD(i,2)= 0 THEN

INSERT INTO EVEN VALUES(i);

ELSE

INSERT INTO ODD VALUES(i);

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

DBMS_OUTPUT.PUT_LINE(NUM||' NOT A PRIME');

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;

SUM1 NUMBER :=0;

BEGIN

A:=1;

LOOP

SUM1:=SUM1+A;

EXIT WHEN (A=100);

A:=A+1;

END LOOP;

DBMS_OUTPUT.PUT_LINE('SUM BETWEEN 1 TO 100 IS '||SUM1);

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

if(i mod 2=0) then

even:=even+i;

else

odd:=odd+i;

end if;

end loop;

dbms_output.put_line('the sum of 50 even no is'||even);

dbms_output.put_line('the sum of 50 odd no is'||odd);

end;

You might also like