Professional Documents
Culture Documents
SQL> DECLARE
2 --the upper limit and the lower limit are taken as user inputs.
3 low number(2);
4 high number(2);
5 n number(2);
6 m number(2);
7 c number(20);
8 BEGIN
9 dbms_output.put_line('Enter the lower and higher limit:');
10 low:=&low;
11 high:=&high;
12 --The main operation happens in this loop
13 for n IN low.. high
14 loop
15 c:=0;
16 for m IN 1.. n
17 loop
18 if mod(n, m)=0 then
19 c:=c+1;
20 end if;
21 end loop;
22 --the number of divisors for each number in the range is counted and then
checked.
23 if c<=2 then
24 dbms_output.put_line(n||'\n');
25 end if;
26 end loop;
27
28 END;
29 /
Enter value for low: 10
old 10: low:=&low;
new 10: low:=10;
Enter value for high: 20
old 11: high:=&high;
new 11: high:=20;
SQL> DECLARE
2 low number(2);
3 high number(2);
4 n number(2);
5 m number(2);
6 c number(20);
7 BEGIN
8 dbms_output.put_line('Enter the lower and higher limit:');
9 low:=&low;
10 high:=&high;
11 for n IN low.. high
12 loop
13 c:=0;
14 for m IN 1.. n
15 loop
16 if mod(n, m)=0 then
17 c:=c+1;
18 end if;
19 end loop;
20
21 if c<=2 then
22 dbms_output.put_line(n||' ');
23 end if;
24 end loop;
25
26 END;
27 /
Enter value for low: 10
old 9: low:=&low;
new 9: low:=10;
Enter value for high: 20
old 10: high:=&high;
new 10: high:=20;
Enter the lower and higher limit:
11
13
17
19
8 rows selected.
6 rows selected.
SQL> DECLARE
2 low number(2);
3 high number(2);
4 n number(2);
5 m number(2);
6 c number(20);
7 BEGIN
8 dbms_output.put_line('Enter the lower and higher limit:');
9 low:=&low;
10 high:=&high;
11 for n IN low.. high
12 loop
13 c:=0;
14 for m IN 1.. n
15 loop
16 if mod(n, m)=0 then
17 c:=c+1;
18 end if;
19 end loop;
20
21 if c<=2 then
22 dbms_output.put_line(n||' ');
23 end if;
24 end loop;
25
26 END;
27 /
Enter value for low: 10
old 9: low:=&low;
new 9: low:=10;
Enter value for high: 20
old 10: high:=&high;
new 10: high:=20;
Enter the lower and higher limit:
11
13
17
19