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

Assignment - 1 1) WAP To Find The Greatest of Three Numbers

The document contains 8 programs written in PL/SQL to solve common programming problems: 1) Find the greatest of three numbers 2) Check if a number is odd or even 3) Determine a grade based on marks 4) Print the multiplication table of a given number 5) Calculate the factorial of a given number using a while loop 6) Print the Fibonacci series 7) Reverse a given number 8) Reverse a given string

Uploaded by

Vinay Singh
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)
147 views5 pages

Assignment - 1 1) WAP To Find The Greatest of Three Numbers

The document contains 8 programs written in PL/SQL to solve common programming problems: 1) Find the greatest of three numbers 2) Check if a number is odd or even 3) Determine a grade based on marks 4) Print the multiplication table of a given number 5) Calculate the factorial of a given number using a while loop 6) Print the Fibonacci series 7) Reverse a given number 8) Reverse a given string

Uploaded by

Vinay Singh
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/ 5

ASSIGNMENT -1

1) WAP to find the greatest of three numbers.

DECLARE

X NUMBER:=4;

Y NUMBER:=5;

Z NUMBER:=6;

BEGIN

IF X>Y THEN

IF X>Z THEN

DBMS_OUTPUT.PUT_LINE(X||' is greatest');

ELSE

DBMS_OUTPUT.PUT_LINE(Z||' is greatest');

END IF;

ELSIF Y>Z THEN

DBMS_OUTPUT.PUT_LINE(Y||' is greatest');

ELSE

DBMS_OUTPUT.PUT_LINE(z||' is greatest');

END IF;

END;

2.) WAP to check whether the number is odd or even.

DECLARE

X NUMBER:=4;

BEGIN

IF MOD(X,2)=0 THEN

DBMS_OUTPUT.PUT_LINE(X||' is EVEN');

ELSE

DBMS_OUTPUT.PUT_LINE(X||' is ODD');

END IF;
END;

3.)WAP to find the grade. Consider the following:

Marks>80 A Grade

Marks>70 B Grade

Marks>50 C Grade

Marks>40 D Grade

Marks<40 E Grade

DECLARE

GRADE NUMBER:=65;

BEGIN

IF GRADE>80 THEN

DBMS_OUTPUT.PUT_LINE('A grade');

GOTO terminate;

ELSIF GRADE>70 THEN

DBMS_OUTPUT.PUT_LINE('B grade');

GOTO terminate;

ELSIF GRADE>50 THEN

DBMS_OUTPUT.PUT_LINE('C grade');

GOTO terminate;

ELSIF GRADE>40 THEN

DBMS_OUTPUT.PUT_LINE('D grade');

GOTO terminate;

ELSIF GRADE<40 THEN

DBMS_OUTPUT.PUT_LINE('E grade');

GOTO terminate;

END IF;

<<terminate>>

NULL;
END;

4.) WAP to print the table of a given number.

DECLARE

digit NUMBER:=7;

temp NUMBER;

BEGIN

for x IN 1..10

LOOP

temp:=digit*x;

dbms_output.put_line(digit||' X '||x||' = '||temp);

END LOOP;

NULL;

END;

5.) WAP to find out of the factorial of a given number (using while loop).

DECLARE

digit NUMBER:=6;

fact NUMBER:=1;

iterator NUMBER:=1;

BEGIN

while iterator<=digit

LOOP

fact:=fact*iterator;

iterator:=iterator+1;

END LOOP;

dbms_output.put_line('factorial of '||digit||' is '||fact);


END;

6.) WAP to find out the Fibonacci Series.

DECLARE

n1 NUMBER:=0;

n2 NUMBER:=1;

s NUMBER;

BEGIN

dbms_output.put_line(n1||' ');

dbms_output.put_line(n2||' ');

s:=n1+n2;

for i IN 1..8

LOOP

dbms_output.put_line(s||' ');

n1:=n2;

n2:=s;

s:=n1+n2;

END LOOP;

END;

7.) WAP to find the reverse of a number.

DECLARE

n1 NUMBER:=678;

n2 NUMBER:=0;

remain NUMBER:=0;
BEGIN

LOOP

remain:=mod(n1,10);

n2:=n2*10+remain;

n1:=TRUNC(n1/10);

exit when n1=0;

END LOOP;

dbms_output.put_line('the reversed number is '||n2);

END;

8.) WAP to reverse a String.

DECLARE

st varchar(30):='Vinay Singh';

revst varchar(30);

l NUMBER;

BEGIN

l := length(st);

for i IN REVERSE 1..l

loop

revst:= revst || Substr(st,i,1);

END LOOP;

dbms_output.put_line('the reversed string is '||revst);

END;

You might also like