oracle8.1.6 begin insert into portal_element_map (sort_key, region, portal_id, element_id) select nvl((select max(sort_key) from portal_element_map where region = :region), 1) + rownum, :region, :portal_id, element_id from (select element_id from portal_element_map m where $where order by region,sort_key) end;