Reputation: 3168
I had generate 1 round numbers:
set serveroutput on
declare
i number(9);
x number(9) := 0;
begin
for i in 0..7 loop
DBMS_OUTPUT.PUT_LINE(x);
x:=x+1;
end loop;
end;
Result is: 0, 1, 2, 3....7
My next round should generate numbers: 10, 11, 12....17
Total output should looks as below:
0 1 2 3 4 5 6 7
10 11 12 13 14 15 16 17
20 21 22 23 24 25 26 27
...
80 81 82 83 84 85 86 87
How can I jump 3 between each round? I will increase my counter till 81.
Upvotes: 1
Views: 545
Reputation: 30565
The Logic is: if i mod 10 = 7 then increment by 3 otherwise increment by one. Thus,
set serveroutput on
declare
i number(9);
x number(9) := 0;
begin
for i in 0..100 loop
DBMS_OUTPUT.PUT_LINE(x);
IF mod(i,10) = 7 THEN
x := x +3;
ELSE
x:=x+1;
END IF;
end loop;
end;
Upvotes: 0
Reputation: 94894
Looks like you want to output 9 times 7 numbers. That is one loop running 9 times and inside a loop that runs 7 times, I'd say. E.g.
begin
for i in 0..8 loop
for j in 0..7 loop
dbms_output.put(i * 10 + j);
dbms_output.put(' ');
end loop;
dbms_output.put_line('');
end loop;
end;
Upvotes: 1
Reputation: 1612
set serveroutput on
declare
i number(9);
y number(9);
x number(9) := 0;
z number(9) := 0;
begin
for y in 0..8 loop
for i in 0..7 loop
DBMS_OUTPUT.PUT_LINE(x);
x := z+i+1;
end loop;
z := z + 10;
x := z;
end loop;
end;
Upvotes: 1
Reputation: 142705
How about such a WHILE
loop?
SQL> set serveroutput on
SQL> declare
2 i number := 0;
3 begin
4 while i < 30
5 loop
6 dbms_output.put_line (i);
7
8 i := i + case when substr (to_char (i), -1) >= 7 then 3 else 1 end;
9 end loop;
10 end;
11 /
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17
20
21
22
23
24
25
26
27
PL/SQL procedure successfully completed.
SQL>
Upvotes: 0