/*============================================================================*
 |                 Copyright (c) 2008 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET FEEDBACK OFF
SET VERIFY OFF
SET SERVEROUT ON

DECLARE
  
  l_pname varchar2(100)	:=	'&1';
  l_patches varchar2(400) := 'xxasemp-v002083';

  CURSOR csr_patches IS
  SELECT ap.patch_name from xxas_com_applied_patches ap
  WHERE ap.CURRENT_STATUS = 'C'
  AND ROWID = (SELECT MAX(ROWID) 
              FROM XXAS_COM_APPLIED_PATCHES ap1 
              WHERE ap.PATCH_NAME=ap1.PATCH_NAME)
  AND ap.patch_name <> '' || l_pname || ''
  ORDER BY ap.last_update_date DESC;

BEGIN

  OPEN csr_patches;
  FETCH csr_patches INTO l_patches;
  CLOSE csr_patches;

  IF l_patches IS NULL
  THEN
    l_patches := 'xxasemp-v002083';
  ELSE
    dbms_output.put_line(l_patches);
  END IF;

EXCEPTION

 WHEN others THEN
 
  dbms_output.put_line(l_patches);

END;
/
COMMIT;
EXIT;