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

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

DECLARE

  l_APPLAUD  CONSTANT varchar2(4)  := 'XXAS';
  l_custom_obj_prefix varchar2(30) := upper(trim('&1'));
  
  --
  -- Count the number of invalid objects
  --
  CURSOR csr_invalid
    (p_object_prefix IN varchar2)
  IS
  SELECT count(*)
  FROM   user_objects uo
  WHERE  uo.object_name like p_object_prefix || '%'
  AND    uo.status = 'INVALID'
  AND    uo.object_type IN ('PACKAGE', 'VIEW', 'PACKAGE BODY');

  l_xxas_count   number := 0;
  l_custom_count number := 0;

BEGIN

  --
  -- Count all invalid XXAS objects
  --
  OPEN  csr_invalid(l_APPLAUD);
  FETCH csr_invalid INTO l_xxas_count;
  CLOSE csr_invalid;
  
  IF l_custom_obj_prefix IS NOT NULL AND
     l_custom_obj_prefix <> l_APPLAUD THEN
    --
    -- Count all invalid custom objects
    --
    OPEN  csr_invalid(l_custom_obj_prefix);
    FETCH csr_invalid INTO l_custom_count;
    CLOSE csr_invalid;
  END IF;

  dbms_output.put_line(to_char(l_xxas_count + l_custom_count));

END;
/
COMMIT;
EXIT;
