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

SET FEEDBACK OFF
SET VERIFY OFF
WHENEVER SQLERROR EXIT FAILURE ROLLBACK
WHENEVER OSERROR EXIT FAILURE ROLLBACK

DECLARE

  l_patch_name   varchar2(400) := ('&1');
  l_node_name	 varchar2(31)  := ('&2');
  l_num_finished number;

  CURSOR csr_get_existing IS
  SELECT num_finished 
  FROM   xxas_com_applied_patches ap
  WHERE  ap.patch_name = l_patch_name
  AND node_name=l_node_name;

BEGIN

  --
  -- Get the number of successful installations 
  --
  OPEN  csr_get_existing;
  FETCH csr_get_existing INTO l_num_finished;
  CLOSE csr_get_existing;

  --
  -- Only update if the patch exists
  --
  IF l_num_finished IS NOT NULL THEN

    UPDATE xxas_com_applied_patches
    SET    current_status = 'C'
          ,num_finished = l_num_finished + 1
          ,last_update_date = sysdate
    WHERE  patch_name = l_patch_name
	AND current_status = 'S';

  END IF;

END;
/
COMMIT;
EXIT;
