-1

Just trying to insert values into table using loop.

The code for loop is next

DECLARE
ID_src number;
BEGIN
  FOR i IN 1..10000
  LOOP
    ID_src := i;
       INSERT INTO src_facts values (ID_src);
  END LOOP;
END;

From my view output should be:

1
2
3
...
10000

But I reviewed unpredictable result. It is:

enter image description here

Can you explain what am I doing wrong?

Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124
  • 1
    Do you mean that the table data isn't sorted 1,2,3,...,10000? There is no reason why it should be, or should be returned in sorted order - unless you explicitly sort it using ORDER BY. In SQL Developer you can click on the column heading to sort the data. Tables are not inherently sorted. – Tony Andrews Mar 16 '16 at 11:23

1 Answers1

1

The result is not unpredictable. You just need order by:

select *
from src_facts
order by id_src;

SQL tables represent unordered sets. Unless you include an ORDER BY, there is no guarantee of the order of the rows in the result set.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786