Вы находитесь на странице: 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;

Вам также может понравиться