oracle8.1.6 select attr_id from (select attr_id from ab_contact_attrs where sort_key $operator (select sort_key from ab_contact_attrs where attr_id = :attr_id) and contact_id = :contact_id order by sort_key $direction) where rownum = 1 begin ab_contact_attr.swap_sort(attr_id_one => :attr_id, attr_id_two => :other_attr_id); end;