流水线函数的结果,总是会排序为 "written",或者不是?
Result from pipelined function, always will sorted as "written", or not?
需要重新编号的结果集,例如:
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));
问题是:可以保证 oracle 总是会 return 产生那个顺序吗? :
1
2
3
1
2
3
1
2
3
1
或者有时结果会出乎意料地排序,像这样:
1
1
1
1
2
2
....
?
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
这意味着,它将在完全获取之前开始处理行,这就是您看到不可预测的顺序的原因。
需要重新编号的结果集,例如:
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));
问题是:可以保证 oracle 总是会 return 产生那个顺序吗? :
1
2
3
1
2
3
1
2
3
1
或者有时结果会出乎意料地排序,像这样:
1
1
1
1
2
2
....
?
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
这意味着,它将在完全获取之前开始处理行,这就是您看到不可预测的顺序的原因。