/* Reasons for Release */
/* Does not pick REMOVED dependencies */
SELECT pv.PV_ID,
	   pkg.pkg_name,
	   pv.pkg_version,
	   pv.COMMENTS
  FROM PACKAGES pkg,
  	   PACKAGE_VERSIONS pv,
	   (
		/* Original Product */
		SELECT 2 AS seq,
			   dep.dpv_id
		  FROM PACKAGE_DEPENDENCIES dep
		 WHERE dep.PV_ID = :PROD_ID
		MINUS
		/* Previous Version */ 
		SELECT 2 AS seq,
			   dep.dpv_id
		  FROM PACKAGE_DEPENDENCIES dep
		 WHERE dep.PV_ID = :OLD_PROD_ID  
           AND :PROD_ID != :OLD_PROD_ID 
		UNION
	   	/* Product itself */
		SELECT 1 AS seq,
			   TO_NUMBER( :PROD_ID ) FROM DUAL
	   ) diff
 WHERE pv.pkg_id = pkg.pkg_id
   AND diff.dpv_id = pv.pv_id	
ORDER BY diff.seq, UPPER(pkg.pkg_name)
