Result from pipelined function, always will sorted as "written", or not?

271 views Asked by At

Needed get renumbered result set, for example:

  CREATE OR REPLACE TYPE nums_list IS TABLE OF NUMBER;

  CREATE OR REPLACE FUNCTION generate_series(from_n INTEGER, to_n INTEGER, cycle_max INTEGER)
  RETURN nums_list PIPELINED AS  
      cycle_iteration INTEGER := from_n;
  BEGIN
      FOR i IN from_n..to_n LOOP
          PIPE ROW( cycle_iteration );
          cycle_iteration := cycle_iteration + 1;
          IF cycle_iteration > cycle_max THEN
             cycle_iteration := from_n;
          END IF;
        END LOOP;
        RETURN; 
  END;

  SELECT * FROM TABLE(generate_series(1,10,3));

Question is: there is guarantee, that oracle always will return result in that order? :

1 2 3 1 2 3 1 2 3 1

or maybe sometimes result will unexpected ordered, like this:

1 1 1 1 2 2 ....

?

1

There are 1 answers

0
Ravi On BEST ANSWER

Pipelining negates the need to build huge collections by piping rows out of the function as they are created, saving memory and allowing subsequent processing to start before all the rows are generated

pipelined-table-functions

This means, it will start processing the rows before get fetched completely and that's why you are seeing unpredictable order.