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
There are several ways to do this. One would be to use a pipelined function to return the additional row when the day spanning condition is detected. Another way is to duplicate the rows and then eliminate the ones that don't need to be duplicated and adjust the times for those that do. Here is an example:
Setup: