declare
lev number;
nspaces number;
begin
lev := &level;
for i in 1..lev
loop
nspaces := round((lev - i) / 2) ;
for j in 1..nspaces
loop
dbms_output.put('*');
end loop;
for j in 1..i
loop
dbms_output.put('9');
end loop;
for j in 1..nspaces
loop
dbms_output.put('*');
end loop;
dbms_output.put_line('');
end loop;
end;
/
fina@ORA7.WORLD> @pr
Enter value for level: 9
old 5: lev := &level;
new 5: lev := 9;
****9****
****99****
***999***
***9999***
**99999**
**999999**
*9999999*
*99999999*
999999999
DECLARE
numero NUMBER := 1;
longueur NUMBER;
BEGIN
DBMS_OUTPUT.enable(1000000);
FOR i IN 1..38 LOOP
DBMS_OUTPUT.put_line( numero);
numero := 10*numero+1;
END LOOP;
END;
08:58:20 SCOTT: ORACLE9I> /
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
11111111111
111111111111
1111111111111
11111111111111
111111111111111
1111111111111111
11111111111111111
111111111111111111
1111111111111111111
11111111111111111111
111111111111111111111
1111111111111111111111
11111111111111111111111
111111111111111111111111
1111111111111111111111111
11111111111111111111111111
111111111111111111111111111
1111111111111111111111111111
11111111111111111111111111111
111111111111111111111111111111
1111111111111111111111111111111
11111111111111111111111111111111
111111111111111111111111111111111
1111111111111111111111111111111111
11111111111111111111111111111111111
111111111111111111111111111111111111
1111111111111111111111111111111111111
11111111111111111111111111111111111111
DECLARE
numero NUMBER := 2;
longueur NUMBER;
BEGIN
DBMS_OUTPUT.enable(1000000);
FOR i IN 1..38 LOOP
DBMS_OUTPUT.put_line( numero);
numero := 10*numero+2;
END LOOP;
END;
08:58:44 SCOTT: ORACLE9I> /
2
22
222
2222
22222
222222
2222222
22222222
222222222
2222222222
22222222222
222222222222
2222222222222
22222222222222
222222222222222
2222222222222222
22222222222222222
222222222222222222
2222222222222222222
22222222222222222222
222222222222222222222
2222222222222222222222
22222222222222222222222
222222222222222222222222
2222222222222222222222222
22222222222222222222222222
222222222222222222222222222
2222222222222222222222222222
22222222222222222222222222222
222222222222222222222222222222
2222222222222222222222222222222
22222222222222222222222222222222
222222222222222222222222222222222
2222222222222222222222222222222222
22222222222222222222222222222222222
222222222222222222222222222222222222
2222222222222222222222222222222222222
22222222222222222222222222222222222222
PL/SQL procedure successfully completed.
DECLARE
numero NUMBER := 9;
longueur NUMBER;
BEGIN
DBMS_OUTPUT.enable(1000000);
FOR i IN 1..38 LOOP
SELECT VSIZE (numero) INTO longueur FROM dual;
DBMS_OUTPUT.put_line( numero);
numero := 10*numero+9;
END LOOP;
END;
08:52:14 SCOTT: ORACLE9I> /
9
99
999
9999
99999
999999
9999999
99999999
999999999
9999999999
99999999999
999999999999
9999999999999
99999999999999
999999999999999
9999999999999999
99999999999999999
999999999999999999
9999999999999999999
99999999999999999999
999999999999999999999
9999999999999999999999
99999999999999999999999
999999999999999999999999
9999999999999999999999999
99999999999999999999999999
999999999999999999999999999
9999999999999999999999999999
99999999999999999999999999999
999999999999999999999999999999
9999999999999999999999999999999
99999999999999999999999999999999
999999999999999999999999999999999
9999999999999999999999999999999999
99999999999999999999999999999999999
999999999999999999999999999999999999
9999999999999999999999999999999999999
99999999999999999999999999999999999999
PL/SQL procedure successfully completed.
1 declare
2 x number:=2;
3 y number;
4 begin
5 for i in 1..30
6 loop
7 --dbms_output.put_line(x);
8 x := x*10 + 2;
9 y := x;
10 end loop;
11 for i in 1..31
12 loop
13 dbms_output.put_line(y);
14 y := round(y/10);
15 end loop;
16* end;
fina@ORA7.WORLD> /
2222222222222222222222222222222
222222222222222222222222222222
22222222222222222222222222222
2222222222222222222222222222
222222222222222222222222222
22222222222222222222222222
2222222222222222222222222
222222222222222222222222
22222222222222222222222
2222222222222222222222
222222222222222222222
22222222222222222222
2222222222222222222
222222222222222222
22222222222222222
2222222222222222
222222222222222
22222222222222
2222222222222
222222222222
22222222222
2222222222
222222222
22222222
2222222
222222
22222
2222
222
22
2
PL/SQL procedure successfully completed.
Search This Blog
Total Pageviews
Saturday, 27 February 2010
Subscribe to:
Post Comments (Atom)
Oracle DBA
anuj blog Archive
- ► 2011 (362)
1 comment:
Nice blog. You have provided so many examples to show how the loop structure works in plsql. This blog is a great source of help to learn about all the constructs of this interesting language. Thanks for putting you efforts.
sap upgrade tool
Post a Comment