#!/usr/bin/ksh
#whatobjects ()
#------------------------------------------------------------------------------#
#    Module Name:  whatdbdictionary                                            #
#                                                                              #
#    Purpose:      Report on the DataDictionary Objects (count) by Type        #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    10-Oct-2009   F.Dobrzenski  Module design/creation                        #
#                  M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        HNAME=$(uname -n)

        #----------------------------------------------------------------------#
        #  TEST:  Number ($#) of arguments passed to this function?            #
        #----------------------------------------------------------------------#
        if      [ $# = 0 ]
        then
            clear
            echo 
            echo  " #--------------------------------------------------------#"
            echo  " # whatobjects:             Oracle DataDictionary Objects #"
            echo  " #--------------------------------------------------------#"
            echo                                                               

            #------------------------------------------------------------------#
            #  Trap:  Set CNTL-C CNTL-D CNTL-\ Before Password Protection      #
            #------------------------------------------------------------------#
            trap        "stty echo; return"     2                              
            trap        "stty echo; return"     3
            stty -echo

            read PASSWD?" Please Enter the Oracle APPS Passwd:  "

            stty echo
            echo 
            #------------------------------------------------------------------#
            #  Trap:  Reset CNTL-C CNTL-D CNTL-\ After Password Protection     #
            #------------------------------------------------------------------#
            trap        2
            trap        3

            clear
        else
            PASSWD=$1
            clear
        fi

#------------------------------------------------------------------------------#
#  Initialize                                                                  #
#------------------------------------------------------------------------------#
        SPOOLNM=/tmp/whatdbdictionary_$$.txt

#------------------------------------------------------------------------------#
#  SQL*Plus ("Here-Document")                                                  #
#------------------------------------------------------------------------------#
sqlplus  -s  /nolog  <<-END_FILE

        CONNECT  APPS/$PASSWD

        SPOOL ${SPOOLNM}

        clear   BREAKS
        clear   BUFFER
        clear   COLUMNS
        clear   COMPUTES
        clear   SCREEN
        clear   SQL
        clear   TIMING

        set     feedback        off
        set     flush           on
        set     heading         on
        set     pause           off
        set     space           1
        set     termout         on
        set     verify          on
        set     linesize        120
        set     pagesize        999

        prompt #---------------------------------------------------------------#
        prompt #- What DataDictionary DBDictionary (whatdbdictionary)         -#
        prompt #---------------------------------------------------------------#

        COLUMN  datevalue       NOPRINT NEW_VALUE       DATEVAR
        COLUMN  timevalue       NOPRINT NEW_VALUE       TIMEVAR

        TTITLE  CENTER  '${ORASID} (${HNAME}) Apps DataDictionary'          -
                LEFT    DATEVAR                                     skip 1  -
                CENTER  'eBusiness 12 DataDictionary Schema Count)'  -
                LEFT    TIMEVAR                                     skip 2

        alter session set NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

	COLUMN owner 			FORMAT a14 heading 'OWNER'
	COLUMN total_count 		FORMAT 999999 heading 'TOTAL'
	COLUMN cluster_count 	FORMAT 999 heading 'CLU'
	COLUMN table_count 		FORMAT 99999 heading 'TABLE'
	COLUMN table_part 		FORMAT 99999 heading 'TABLE|PART'
	COLUMN index_count 		FORMAT 99999 heading 'INDEX'
	COLUMN index_part 		FORMAT 99999 heading 'INDEX|PART'
	COLUMN view_count 		FORMAT 99999 heading 'VIEW'
	COLUMN synonym_count 		FORMAT 999999 heading 'SYN'
	COLUMN sequence_count 		FORMAT 99999 heading 'SEQ'
	COLUMN dblink_count 		FORMAT 999 heading 'DB|LNK'
	COLUMN trigger_count 		FORMAT 999999 heading 'TRIG'
	COLUMN procedure_count 		FORMAT 9999 heading 'FUNC|PROC'
	COLUMN package_count 		FORMAT 99999 heading 'PACK'
	COLUMN package_body_count 	FORMAT 99999 heading 'PACK|BODY'
	COLUMN JAVA_CLASS_count 	FORMAT 99999 heading 'JAVA|CLASS'

	break on report
	compute sum -
	     of total_count cluster_count table_count table_part -
	        index_count index_part view_count -
	        synonym_count sequence_count dblink_count trigger_count -
	        procedure_count package_body_count package_count JAVA_CLASS_count -
	     on report

	select	owner,
		count(*) total_count,
		sum(decode( object_type, 'CLUSTER', 1 )) cluster_count,
		sum(decode( object_type, 'TABLE', 1 )) table_count,
		sum(decode( object_type, 'TABLE PARTITION', 1 )) table_part,
		sum(decode( object_type, 'INDEX', 1 )) index_count,
		sum(decode( object_type, 'INDEX PARTITION', 1 )) index_part,
		sum(decode( object_type, 'VIEW', 1 )) view_count,
		sum(decode( object_type, 'SYNONYM', 1 )) synonym_count,
		sum(decode( object_type, 'SEQUENCE', 1 )) sequence_count,
		sum(decode( object_type, 'DATABASE LINK', 1 )) dblink_count,
		sum(decode( object_type, 'TRIGGER', 1 )) trigger_count,
		sum(decode( object_type, 'FUNCTION', 1, 'PROCEDURE', 1 )) procedure_count,
		sum(decode( object_type, 'PACKAGE', 1 )) package_count,
		sum(decode( object_type, 'PACKAGE BODY', 1 )) package_body_count,
		sum(decode( object_type, 'JAVA CLASS', 1 )) JAVA_CLASS_count
	  FROM	sys.dba_objects
	WHERE	owner LIKE upper('%')
	GROUP BY  owner
	ORDER BY  owner;

END_FILE

print
print  "Please see  /tmp/whatdbdictionary_$$.txt"
print
}
