INFORMATICS PRACTICES

OUTPUT QUESTIONS
Home
ASSIGNMENTS
My SQL
FINDING OUT ERRORS
THEORY QUESTIONS
OUTPUT QUESTIONS
BOARD PAPERS

Image by FlamingText.com
Image by FlamingText.com

OUTPUT USING ASSIGNMENT

Find the output of the following program:

DECLARE

A CHAR (3) := ONE;

B REAL := 17.5;

BEGIN

DBMS_OUTPUT. PUT_LINE (A= || A || B= || B);

DECLARE

A INTEGER := 1;

C REAL := 170.5;

BEGIN

DBMS_OUTPUT. PUT_LINE (A = || A || B = || B|| C = ||C) ;

END;

DECLARE

C REAL := 1700.5;

BEGIN

DBMS_OUTPUT. PUT_LINE (A = || A || B = || B|| C = ||C) ;

END;

DBMS_OUTPUT. PUT_LINE (A = || A || B = || B) ;

END;

/

A = ONE B =17.5

A = 1 B =17. 5 C =170.5

A = ONE B =17.5 C =1700.5

A = ONE B =17.5

PL/SQL procedure successfully completed.

 

Find the output of the following program:

declare

na varchar2(25):='CBSE SAMPLE PAPER';

begin

dbms_output.put(substr(na,1,1));

dbms_output.put('.');

dbms_output.put(substr(na,13,1));

dbms_output.put('.');

dbms_output.put(substr(na,-6));

dbms_output.put_line(' ');

end;

/

SQL> /

C.P. PAPER

PL/SQL procedure successfully completed.

OUTPUT USING IF WITH HOST/BIND VARIABLES

Find the output of the following program:

SQL> variable ap number;

SQL> accept gs prompt 'please enter sale amount ' ;

please enter sale amount 1000

SQL> declare

2 vas number(9,2):= &gs;

3 begin

4 if vas>2000 then

5 vas:=vas-500;

6 else

7 vas:=vas-100;

8 end if;

9 :ap:=vas;

10 end;

11 /

old 2: vas number(9,2):=&gs;

new 2: vas number(9,2):=1000;

PL/SQL procedure successfully completed.

SQL> print ap;

AP

---------

900

SQL> accept gs prompt 'please enter sale amount' ;

please enter sale amount3000

SQL> run w

1 declare

2 vas number(9,2):=&gs;

3 begin

4 if vas>2000 then

5 vas:=vas-500;

6 else

7 vas:=vas-100;

8 end if;

9 :ap:=vas;

10* end;

old 2: vas number(9,2):=&gs;

new 2: vas number(9,2):=3000;

PL/SQL procedure successfully completed.

SQL> print ap;

AP

---------

2500

OUTPUT USING FOR

Find the output of the following program:

Declare

i number:=2;

f number:=2;

n number:=&n;

begin

for i in 1..n loop

f := f*I + 2;

dbms_output.put_line( f ||' '||I );

end loop;

end;

Enter value for n: 5

old 4: n number:=&n;

new 4: n number:=5;

4 1

10 2

32 3

130 4

652 5

PL/SQL procedure successfully completed.

 

Find the output of the following program:

declare

text varchar2(20);

x number;

begin

text:='CBSE EXAMINATION';

for x in REVERSE 1..10 loop

dbms_output.put_line(substr(text,x,1));

end loop;

end;

I

M

A

X

E

E

S

B

C

PL/SQL procedure successfully completed.

OUTPUT USING NESTED FOR

Find the output of the following program:

 

DECLARE

I NUMBER;

J NUMBER;

BEGIN

FOR I IN 65..69 LOOP

FOR J IN 65..I LOOP

DBMS_OUTPUT.PUT(CHR(J)||' ');

END LOOP;

DBMS_OUTPUT.NEW_LINE;

END LOOP;

END;

/

A

A B

A B C

A B C D

A B C D E

PL/SQL procedure successfully completed.

 

 

Find the output of the following program:

declare

i number;

j number;

begin

for i in 1..5 loop

for j in 1..i loop

dbms_output.put('c');

end loop;

dbms_output.new_line;

end loop;

end;

c

cc

ccc

cccc

ccccc

 

OUTPUT USING WHILE

Find the output of the following program:

declare

C number:=1;

begin

while c<=10 loop

dbms_output.put_line(C*C);

c:= c+1 ;

end loop;

end;

1

4

9

16

25

36

49

64

81

100

PL/SQL procedure successfully completed.

Find the output of the following program:

 

declare

i number:=1;

s number:=0;

begin

while i<6 loop

dbms_output.put_line(i||' '||i*i);

i:=i+2;

s:=s+i;

end loop;

s:=s/2;

dbms_output.put_line(s);

end;

SQL> /

1 1

3 9

5 25

7.5

PL/SQL procedure successfully completed.

 

Find the output of the following program:

declare

ctr number:=1;

s number:=0;

begin

while ctr<=10 loop

s:=s+ctr;

dbms_output.put_line('sum upto'||ctr||'is'||s);

ctr:=ctr+1;

end loop;

end;

SQL> /

sum upto1is1

sum upto2is3

sum upto3is6

sum upto4is10

sum upto5is15

sum upto6is21

sum upto7is28

sum upto8is36

sum upto9is45

sum upto10is55

PL/SQL procedure successfully completed.

 

Find the output of the following program:

declare

no1 number := 15;

no2 number := 22;

begin

while no2>no1 loop

dbms_output.put_line(no2-no1);

no2:=no2-1;

end loop;

end;

SQL> /

7

6

5

4

3

2

1

PL/SQL procedure successfully completed.

Find the output of the following program:

declare

I number :=1 ;

S number :=0;

begin

while I<5 loop

dbms_output.put_line(I || || I*I );

I:=I+1 ;

s:=s+I ;

end loop;

s:=s+i;

dbms_output.put_line(s );

end;

SQL> /

  1. 1
  2. 4
  3. 9
  4. 16

19

PL/SQL procedure successfully completed.

Find the output of the following program:

Declare

N1 number :=30 ;

N2 number :=40;

begin

while n2>n1 loop

dbms_output.put_line(n1+n2);

n1:= n1+2 ;

end loop;

end;

SQL> /

70

72

74

76

78

PL/SQL procedure successfully completed.

Find the output of the following program:

Declare

A number := 0 ;

b number :=20;

begin

while a<20 loop

dbms_output.put_line(b*20);

a:= a+4;

b:=b-a;

end loop;

end;

SQL> /

40

32

16

-8

-40

PL/SQL procedure successfully completed.

 

Find the output of the following program:

Declare

A number := 7 ;

b number :=5;

begin

while c<10 loop

dbms_output.put_line(A*b));

c:= c+3;

a:=a+6;

end loop;

end;

SQL> /

35

104

PL/SQL procedure successfully completed.

 

 

OUTPUT USING IF & WHILE

Find the output of the following program:

declare

num1 number:=20;

num2 number:=33;

begin

if num2>num1 then

num1:=num1+1;

num2:=num2-1;

while num1<=num2 loop

dbms_output.put_line(num1);

num1 := num1+3;

end loop;

else

if num1>num2 then

num1:=num1-1;

num2:=num2+1;

while num2<=num1 loop

dbms_output.put_line(num2);

num2:=num2+1;

end loop;

end if;

end if ;

end;

/

21

24

27

30

PL/SQL procedure successfully completed.

OUTPUT USING FOR & IF

Find the output of the following program:

 

declare

name varchar2(10);

x number(2);

begin

name:='INFO';

for x in 1..length(name) loop

dbms_output.put_line(lower(substr(name,x,1)));

if mod(x,2)=0 then

dbms_output.put_line(lower(substr(name,x)));

end if;

end loop;

end;

i

n

nfo

f

o

o

PL/SQL procedure successfully completed.

 

 

Find the output of the following program:

declare

name varchar2(10);

x number(2);

begin

name:='ICSKINFO';

for x in 1..length(name)/2 loop

dbms_output.put_line(lower(substr(name,x,1)));

If mod(x,2)=0 then

dbms_output.put_line(UPPER(substr(name,x,1)));

end if;

end loop;

end;

i

c

C

s

k

K

PL/SQL procedure successfully completed.

 

 

 

OUTPUT USING WHILE & IF

Find the output of the following statement:

declare

t number(3) := 0;

s number(3) := 0;

c number(3) := 20;

begin

while c<=80 loop

if c= 40 or c = 60 or c= 80 then

dbms_output.put_line (c || ' ' || s);

t := t+s;

s := 0;

end if;

s := s+c;

c := c+20;

end loop;

dbms_output.put_line(t);

end;

SQL> /

40 20

60 40

80 60

120

PL/SQL procedure successfully completed.

 

Find the output of the following program:

declare

t number(3) := 30;

s number(3) := 10;

c number(3) := 20;

begin

while c<=40 loop

if c=20 or c=40 then

t := t+s;

else

t := t-s;

end if;

dbms_output.put_line(c||' '||t);

s := s+c;

c := c+10;

end loop;

dbms_output.put_line(c||' '||t||' '||s);

end;

SQL> /

20 40

30 10

40 70

50 70 100

PL/SQL procedure successfully completed.

Find the output of the following program:

declare

t number(3) := 0;

s number(3) := 0;

c number(3) := 20;

begin

while c<=60 loop

if c=20 or c=40 or c=60 then

t := t+s;

dbms_output.put_line(c||' '||s);

s := 0;

end if;

s := s + c;

c := c+ 20;

end loop;

dbms_output.put_line(t);

end;

sql> /

20 0

40 20

60 40

60

PL/SQL procedure successfully completed.

 

 

Find the output of the following program:

Declare

W number := 1 ;

begin

while w<4 loop

if w=1 then

dbms_output.put_line( Lower range );

elsif w=2 then

dbms_output.put_line( Middle range );

elsif w=3 then

dbms_output.put_line( Higher range );

end if;

w:= w+1;

end loop;

end;

SQL> /

Lower range

Middle range

Higher range

PL/SQL procedure successfully completed.

 

 

OUTPUT USING IF & FOR

OUTPUT USING FOR &IF & WHILE

OUTPUT USING LOOP

Find the output of the following program:

declare

n number := 679;

s number := 0;

r number:=0;

begin

loop exit when n=0;

s := s*10+r;

r := mod(n,10);

s := s+r;

n := trunc(n/10);

dbms_output.put_line ( n ||' ' || s || ' ' || r);

end loop;

end;

/

67 9 9

6 106 7

0 1073 6

PL/SQL procedure successfully completed.

Find the output of the following program:

declare

n number := 375;

s number := 5;

r number := 20;

begin

loop exit when n=0;

s := s+r;

r := mod(n,10) +trunc(s/10);

n := trunc(n/10);

dbms_output.put_line(s||' ' || r || ' ' || n);

end loop;

end;

SQL> /

25 7 37

32 10 3

42 7 0

PL/SQL procedure successfully completed.

 

Find the output of the following program:

Enter supporting content here