The question is which of the pdate
s for a module
do you want to use for ordering purposes?
If you are happy to use the largest, you could use:
select module from logging order by max(pdate);
--- EDIT
I think I get it now - you probably want something like this:
select module
from( select module,
sum(module_step) over (order by pdate rows unbounded preceding)
as batch_number,
pdate
from( select module,
case lag(module) over (order by pdate) when module then 0
else 1 end as module_step,
pdate from logging) )
group by module, batch_number
order by batch_number;
If the definition of toptab
will potentially be different in different environments (which is, of course, a separate issue that needs addressing), your options would generally be to either create an object type that does have a defined order and BULK COLLECT
into that or to define a different collection for each column that you specify as the targets of your BULK COLLECT
.
For the object approach, you'd define an object
CREATE TYPE toptab_like_object
AS OBJECT (
col1 number,
col2 number,
...
colN number
);
and then use that object rather than the %ROWTYPE
in your code
DECLARE
TYPE t_toptab_list IS TABLE OF toptab_like_object;
l_data t_toptab_list;
BEGIN
SELECT toptab_like_object( ... ) -- many columns, with some manipulation, etc.
BULK COLLECT INTO l_data
FROM a,b,c,d
WHERE ... -- join and filter, etc.
END;
You could also define a different collection for each column (you could probably define a much smaller number of collection types)
DECLARE
TYPE t_col1_list IS TABLE OF toptab.col1%TYPE;
TYPE t_col2_list IS TABLE OF toptab.col2%TYPE;
...
TYPE t_colN_list IS TABLE OF toptab.colN%TYPE;
l_col1 t_col1_list;
l_col2 t_col2_list;
...
l_colN t_colN_list;
BEGIN
SELECT ... -- many columns, with some manipulation, etc.
BULK COLLECT INTO l_col1, l_col2, ... l_colN
FROM a,b,c,d
WHERE ... -- join and filter, etc.
END;
Best Answer
So the query (which would work if under 4000 bytes) is