Re: sort/order a pl/sql table ?
Date: Wed, 05 Dec 2001 02:27:22 GMT
Message-ID: <eCfP7.180215$Yb.44326671_at_typhoon.tampabay.rr.com>
You can write your own sorting routine for a small table.
CREATE OR REPLACE PACKAGE TST AS
type tabt is table of date index by binary_integer;
PROCEDURE sort_table (ptab IN OUT tabt);
END TST;
/
CREATE OR REPLACE PACKAGE BODY TST AS
PROCEDURE sort_table (ptab IN OUT tabt)
IS
length binary_integer := ptab.count; i binary_integer; j binary_integer; t date; BEGIN i := length - 1; while (i > 0) loop for j in 1 .. i loop if ptab(j) > ptab(j+1) then t := ptab(j); ptab(j) := ptab(j+1); ptab(j+1) := t; end if; end loop; i := i - 1; end loop;
END sort_table;
END TST;
/
"Adam Hapworth" <hap_at_mikomi.org> wrote in message
news:a6cb04db.0111280821.45dd4317_at_posting.google.com...
> I am wondering if there is any way to easily sort the values in a
> pl/sql table. I am building a function that takes a table of holidays
> which I have set up to like so.
>
> Name Null? Type
> ------------------------------- -------- ----
> HOL_NAME NOT NULL VARCHAR2(30)
> HOL_MONTH NUMBER(2)
> STATIC_DAY NUMBER(2)
> WEEKDAY VARCHAR2(20)
> WEEK NUMBER(1)
> IGNORE_START_OF_MON NUMBER(1)
>
> if it is a static date like newyears 1/1 (hol_month = 1 static_day =
> 1)then I don't have a problem geting the next holiday (function I am
> working on). But if I use the dynamic holiday like thanksgiving
> (weekday = thursday week = 4 hol_month = 11). once I generate all of
> the dates for the month I put them into a table of date. When I build
> the cursor I sort them by week and weekday so I get the earlier weeks
> first in order of day. But the issue is when say I have a holiday on
> the 4th mon and one on the 4th tue and the month starts on a tuesday
> then the 4th tuesday is before the 4th monday screwing my next holiday
> test all up. If I could sort a pl/sql table this would be solved.
>
> Thanks for your time
> Adam
>
Received on Wed Dec 05 2001 - 03:27:22 CET