As DaPi suggested before, using a work table and pl/sql is much simplier.