SELECT pkg.pkg_name, pv.pkg_version 
  FROM packages pkg, package_versions pv, 
       (
        SELECT UNIQUE MAX(pv.pv_id) OVER (PARTITION BY pkg.pkg_name) AS pv_id
          FROM packages pkg, package_versions pv
         WHERE pkg.pkg_id = pv.pkg_id
           AND pv.dlocked = 'Y'
           AND pv.v_ext NOT IN ( SELECT ext_name FROM project_extentions WHERE proj_id <> $PROJ_ID$ )
           AND pkg.pkg_id IN ( $PKGID_LIST$ )
       ) latest
 WHERE pkg.pkg_id = pv.pkg_id
   AND pv.pv_id = latest.pv_id   