Subject | Order of rows returned by stored procedures |
---|---|
Author | Josef Kokeš |
Post date | 2011-12-08T06:46:50Z |
Hi!
It's been my experience that if I have a stored procedure which returns
rows in a particular order and perform a SELECT on this procedure, the
row order of the SELECT matches that of the procedure. E.g.:
CREATE PROCEDURE test
RETURNS ( value INTEGER )
AS
BEGIN
value = 1;
SUSPEND;
value = 2;
SUSPEND;
value = 3;
SUSPEND;
END
SELECT * FROM test
value
=====
1
2
3
What I would like to know, is this behavior documented or is it just a
random occurence? I know that when SELECTing from tables/views I should
always use ORDER BY if I need the records sorted in a particular order,
but is the same thing true for selecting from stored procedures?
Thanks,
Pepa
It's been my experience that if I have a stored procedure which returns
rows in a particular order and perform a SELECT on this procedure, the
row order of the SELECT matches that of the procedure. E.g.:
CREATE PROCEDURE test
RETURNS ( value INTEGER )
AS
BEGIN
value = 1;
SUSPEND;
value = 2;
SUSPEND;
value = 3;
SUSPEND;
END
SELECT * FROM test
value
=====
1
2
3
What I would like to know, is this behavior documented or is it just a
random occurence? I know that when SELECTing from tables/views I should
always use ORDER BY if I need the records sorted in a particular order,
but is the same thing true for selecting from stored procedures?
Thanks,
Pepa