Oracle July 2020 Critical Patch Advisory - PL/SQL detailed changes

This post is also available in: Português

Oracle July 2020 Critical Patch Advisory changed objects performed by each database patch.

For more details and the catalog, check the main post: Dissecting 200714 BP, PSU, RU and RUR

What exactly changed for each?
(click to see detailed line changes)

Changed Objects

P.S:
> = Added Lines
< = Removed Lines

11.2.0.4

SYS.DBMS_RCVMAN - PACKAGE BODY (PSU):
6265,6278d6264
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
6318c6304,6316
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
6464c6462,6474
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
SYS.DBMS_RCVMAN - PACKAGE BODY (BP):
6265,6278d6264
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
6318c6304,6316
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
6464c6462,6474
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC

12.1.0.2

SYS.DBMS_RCVMAN - PACKAGE (PSU):
1173a1174,1175
> PROCEDURE setGuid(guid IN varchar2 DEFAULT NULL);
> 
1981a1984,1988
> PROCEDURE translateProxyCopyGuid(
>    guid         IN varchar2
>   ,device_type  IN varchar2
>   ,statusMask   IN binary_integer);
> 
2067a2075,2078
> 
> PROCEDURE translateBackupPieceGuid(
>    guid         IN varchar2
>   ,statusMask   IN binary_integer);
SYS.DBMS_STATS - PACKAGE (BP):
2567,2568c2567,2569
< --              ownname or statid in the stattab; (2) statistics are locked; (3)
< --              objects in the stattab no longer exist in the current database
---
> --              ownname or statid in the stattab; (2) statistics are locked;
> --              (3) objects in the stattab no longer exist in the current
> --              database
2800,2803c2801,2804
< --         from partition level statistics. It will aggregate all statistics except number of
< --         distinct values for columns and number of distinct keys of indexes.
< --         The existing histograms of the columns at the table level
< --         are also aggregated.The global statistics are  gathered
---
> --         from partition level statistics. It will aggregate all statistics
> --         except number of distinct values for columns and number of distinct
> --         keys of indexes.  The existing histograms of the columns at the
> --         table level are also aggregated.  The global statistics are gathered
2810,2814c2811,2816
< --         This option is useful when you collect statistics for a new partition added
< --         into a range partitioned table (for example, a table  partitioned by month).
< --         The new data in the partition makes the global statistics stale (especially
< --         the min/max values of the partitioning column). This stale global statistics
< --         may cause suboptimal plans.  In this scenario, users can collect statistics
---
> --         This option is useful when you collect statistics for a new
> --         partition added into a range partitioned table (for example, a table
> --         partitioned by month).  The new data in the partition makes the
> --         global statistics stale (especially the min/max values of the
> --         partitioning column). This stale global statistics may cause
> --         suboptimal plans.  In this scenario, users can collect statistics
2816,2823c2818,2826
< --         option so that the global statistics will reflect the newly added range.
< --         This option will take less time than 'GLOBAL AND PARTITION' option since the
< --         global statistics are aggregated from underlying partition level statistics.
< --         Note that, if you are using APPROX_GLOBAL AND PARTITION,
< --         you still  need to collect global statistics (with granularity = 'GLOBAL' option)
< --         when there is substantial amount of change at the table level.
< --         For example you added 10% more data to the table.  This is needed to get the
< --         correct number of distinct values/keys statistic at table level.
---
> --         option so that the global statistics will reflect the newly added
> --         range.  This option will take less time than 'GLOBAL AND PARTITION'
> --         option since the global statistics are aggregated from underlying
> --         partition level statistics.  Note that, if you are using
> --         APPROX_GLOBAL AND PARTITION, you still  need to collect global
> --         statistics (with granularity = 'GLOBAL' option) when there is
> --         substantial amount of change at the table level.  For example you
> --         added 10% more data to the table.  This is needed to get the correct
> --         number of distinct values/keys statistic at table level.
3018,3021c3021,3024
< --   obj_filter_list - a list of object filters. When provided, gather_schema_stats
< --     will only gather statistics on the objects which satisfy at least one
< --     object filter in the list as needed. Please refer to obj_filter_list
< --     in  gather_database_stats.
---
> --   obj_filter_list - a list of object filters. When provided,
> --     gather_schema_stats will only gather statistics on the objects which
> --     satisfy at least one object filter in the list as needed. Please refer
> --     to obj_filter_list in gather_database_stats.
3188,3201c3191,3204
< --   obj_filter_list - a list of object filters. When provided, gather_database_
< --     stats will only gather statistics on the objects which satisfy at least
< --     one of the object filters as needed.
< --
< --     In one single object filter, we can specify the constraints on the object
< --     attributes. The attribute values specified in the object filter are case-
< --     insensitive unless double-quoted. Wildcard is allowed in the attribute values.
< --     Suppose non-null values s1, s2, ... are specified for attributes a1, a2, ... in
< --     one object filter. An object o is said to satisfy this object filter if
< --     (o.a1 like s1) and (o.a2 like s2) and ... is true.
< --     The following example specifies that any table with a "SALES" prefix in the
< --     SH schema and any table in the SYS schema, if stale, will be gathered.
< --     Note that the statistics for the partitions of the tables also will be
< --     gathered if they are stale.
---
> --   obj_filter_list - a list of object filters. When provided,
> --     gather_database_stats will only gather statistics on the objects which
> --     satisfy at least one of the object filters as needed.
> --
> --     In one single object filter, we can specify the constraints on the
> --     object attributes. The attribute values specified in the object filter
> --     are case-insensitive unless double-quoted. Wildcard is allowed in the
> --     attribute values.  Suppose non-null values s1, s2, ... are specified for
> --     attributes a1, a2, ... in one object filter. An object o is said to
> --     satisfy this object filter if (o.a1 like s1) and (o.a2 like s2) and ...
> --     is true.  The following example specifies that any table with a "SALES"
> --     prefix in the SH schema and any table in the SYS schema, if stale, will
> --     be gathered.  Note that the statistics for the partitions of the tables
> --     also will be gathered if they are stale.
3770,3773c3773,3776
< --   obj_filter_list - a list of object filters. When provided, gather_dictionary_
< --     stats will only gather statistics on the objects which satisfy at least
< --     one of the object filters as needed. Please refer to obj_filter_list in
< --     gather_database_stats
---
> --   obj_filter_list - a list of object filters. When provided,
> --     gather_dictionary_stats will only gather statistics on the objects which
> --     satisfy at least one of the object filters as needed. Please refer to
> --     obj_filter_list in gather_database_stats
4443,4448c4446,4452
< -- This function creates a column stats entry in the system for a user specified
< -- column group or an expression in a table. Statistics for this extension will
< -- be gathered when user or auto statistics gathering job gathers statistics for
< -- the table. We call statistics for such an extension, "extended statistics".
< -- This function returns the name of this newly created entry for the extension.
< -- If the extension already exists then this function  throws an error.
---
> -- This function creates a column stats entry in the system for a user
> -- specified column group or an expression in a table. Statistics for this
> -- extension will be gathered when user or auto statistics gathering job
> -- gathers statistics for the table. We call statistics for such an extension,
> -- "extended statistics".  This function returns the name of this newly created
> -- entry for the extension.  If the extension already exists then this function
> -- throws an error.
4641,4648c4645,4652
< -- This procedure deletes the recorded column (group) usage information
< -- from dictionary. Column (group) usage information is used by gather
< -- procedures to automatically determine the columns that require histograms.
< -- Also this information is used by create_extended_stats to create extensions
< -- for the group of columns seen in the workload. So resetting column usage
< -- will affect these functionalities. This procedure should be used only in very
< -- rare cases where you need to start from scratch and need to seed
< -- column usage all over again.
---
> -- This procedure deletes the recorded column (group) usage information from
> -- dictionary. Column (group) usage information is used by gather procedures to
> -- automatically determine the columns that require histograms.  Also this
> -- information is used by create_extended_stats to create extensions for the
> -- group of columns seen in the workload. So resetting column usage will affect
> -- these functionalities. This procedure should be used only in very rare cases
> -- where you need to start from scratch and need to seed column usage all over
> -- again.
4665,4668c4669,4672
< --     ownname         - owner name. If null it reports column usage information
< --                       for tables in all schemas in the database.
< --     tabname         - table name. If null, it reports column usage information
< --                       for all tables of ownname.
---
> --     ownname         - owner name. If null it reports column usage
> --                       information for tables in all schemas in the database.
> --     tabname         - table name. If null, it reports column usage
> --                       information for all tables of ownname.
4691c4695
< --...............................................................................
---
> --.............................................................................
4693c4697
< --###############################################################################
---
> --#############################################################################
4704c4708
< --###############################################################################
---
> --#############################################################################
5009a5014,5025
> 
>   -- For internal use
>   --
>   -- Quickly estimate number of rows in the table for auto sampling
>   --
>   function get_row_count_estimate(
>         ownname varchar2,                 -- table owner to select from
>         tabname varchar2,                 -- table name to select from
>         partname varchar2,                -- table partition name
>         nblks integer,
>         degree integer
>         ) return number;
SYS.DBMS_STATS - PACKAGE (PSU):
2559,2560c2559,2561
< --              ownname or statid in the stattab; (2) statistics are locked; (3)
< --              objects in the stattab no longer exist in the current database
---
> --              ownname or statid in the stattab; (2) statistics are locked;
> --              (3) objects in the stattab no longer exist in the current
> --              database
2792,2795c2793,2796
< --         from partition level statistics. It will aggregate all statistics except number of
< --         distinct values for columns and number of distinct keys of indexes.
< --         The existing histograms of the columns at the table level
< --         are also aggregated.The global statistics are  gathered
---
> --         from partition level statistics. It will aggregate all statistics
> --         except number of distinct values for columns and number of distinct
> --         keys of indexes.  The existing histograms of the columns at the
> --         table level are also aggregated.  The global statistics are gathered
2802,2806c2803,2808
< --         This option is useful when you collect statistics for a new partition added
< --         into a range partitioned table (for example, a table  partitioned by month).
< --         The new data in the partition makes the global statistics stale (especially
< --         the min/max values of the partitioning column). This stale global statistics
< --         may cause suboptimal plans.  In this scenario, users can collect statistics
---
> --         This option is useful when you collect statistics for a new
> --         partition added into a range partitioned table (for example, a table
> --         partitioned by month).  The new data in the partition makes the
> --         global statistics stale (especially the min/max values of the
> --         partitioning column). This stale global statistics may cause
> --         suboptimal plans.  In this scenario, users can collect statistics
2808,2815c2810,2818
< --         option so that the global statistics will reflect the newly added range.
< --         This option will take less time than 'GLOBAL AND PARTITION' option since the
< --         global statistics are aggregated from underlying partition level statistics.
< --         Note that, if you are using APPROX_GLOBAL AND PARTITION,
< --         you still  need to collect global statistics (with granularity = 'GLOBAL' option)
< --         when there is substantial amount of change at the table level.
< --         For example you added 10% more data to the table.  This is needed to get the
< --         correct number of distinct values/keys statistic at table level.
---
> --         option so that the global statistics will reflect the newly added
> --         range.  This option will take less time than 'GLOBAL AND PARTITION'
> --         option since the global statistics are aggregated from underlying
> --         partition level statistics.  Note that, if you are using
> --         APPROX_GLOBAL AND PARTITION, you still  need to collect global
> --         statistics (with granularity = 'GLOBAL' option) when there is
> --         substantial amount of change at the table level.  For example you
> --         added 10% more data to the table.  This is needed to get the correct
> --         number of distinct values/keys statistic at table level.
3010,3013c3013,3016
< --   obj_filter_list - a list of object filters. When provided, gather_schema_stats
< --     will only gather statistics on the objects which satisfy at least one
< --     object filter in the list as needed. Please refer to obj_filter_list
< --     in  gather_database_stats.
---
> --   obj_filter_list - a list of object filters. When provided,
> --     gather_schema_stats will only gather statistics on the objects which
> --     satisfy at least one object filter in the list as needed. Please refer
> --     to obj_filter_list in gather_database_stats.
3180,3193c3183,3196
< --   obj_filter_list - a list of object filters. When provided, gather_database_
< --     stats will only gather statistics on the objects which satisfy at least
< --     one of the object filters as needed.
< --
< --     In one single object filter, we can specify the constraints on the object
< --     attributes. The attribute values specified in the object filter are case-
< --     insensitive unless double-quoted. Wildcard is allowed in the attribute values.
< --     Suppose non-null values s1, s2, ... are specified for attributes a1, a2, ... in
< --     one object filter. An object o is said to satisfy this object filter if
< --     (o.a1 like s1) and (o.a2 like s2) and ... is true.
< --     The following example specifies that any table with a "SALES" prefix in the
< --     SH schema and any table in the SYS schema, if stale, will be gathered.
< --     Note that the statistics for the partitions of the tables also will be
< --     gathered if they are stale.
---
> --   obj_filter_list - a list of object filters. When provided,
> --     gather_database_stats will only gather statistics on the objects which
> --     satisfy at least one of the object filters as needed.
> --
> --     In one single object filter, we can specify the constraints on the
> --     object attributes. The attribute values specified in the object filter
> --     are case-insensitive unless double-quoted. Wildcard is allowed in the
> --     attribute values.  Suppose non-null values s1, s2, ... are specified for
> --     attributes a1, a2, ... in one object filter. An object o is said to
> --     satisfy this object filter if (o.a1 like s1) and (o.a2 like s2) and ...
> --     is true.  The following example specifies that any table with a "SALES"
> --     prefix in the SH schema and any table in the SYS schema, if stale, will
> --     be gathered.  Note that the statistics for the partitions of the tables
> --     also will be gathered if they are stale.
3762,3765c3765,3768
< --   obj_filter_list - a list of object filters. When provided, gather_dictionary_
< --     stats will only gather statistics on the objects which satisfy at least
< --     one of the object filters as needed. Please refer to obj_filter_list in
< --     gather_database_stats
---
> --   obj_filter_list - a list of object filters. When provided,
> --     gather_dictionary_stats will only gather statistics on the objects which
> --     satisfy at least one of the object filters as needed. Please refer to
> --     obj_filter_list in gather_database_stats
4435,4440c4438,4444
< -- This function creates a column stats entry in the system for a user specified
< -- column group or an expression in a table. Statistics for this extension will
< -- be gathered when user or auto statistics gathering job gathers statistics for
< -- the table. We call statistics for such an extension, "extended statistics".
< -- This function returns the name of this newly created entry for the extension.
< -- If the extension already exists then this function  throws an error.
---
> -- This function creates a column stats entry in the system for a user
> -- specified column group or an expression in a table. Statistics for this
> -- extension will be gathered when user or auto statistics gathering job
> -- gathers statistics for the table. We call statistics for such an extension,
> -- "extended statistics".  This function returns the name of this newly created
> -- entry for the extension.  If the extension already exists then this function
> -- throws an error.
4633,4640c4637,4644
< -- This procedure deletes the recorded column (group) usage information
< -- from dictionary. Column (group) usage information is used by gather
< -- procedures to automatically determine the columns that require histograms.
< -- Also this information is used by create_extended_stats to create extensions
< -- for the group of columns seen in the workload. So resetting column usage
< -- will affect these functionalities. This procedure should be used only in very
< -- rare cases where you need to start from scratch and need to seed
< -- column usage all over again.
---
> -- This procedure deletes the recorded column (group) usage information from
> -- dictionary. Column (group) usage information is used by gather procedures to
> -- automatically determine the columns that require histograms.  Also this
> -- information is used by create_extended_stats to create extensions for the
> -- group of columns seen in the workload. So resetting column usage will affect
> -- these functionalities. This procedure should be used only in very rare cases
> -- where you need to start from scratch and need to seed column usage all over
> -- again.
4657,4660c4661,4664
< --     ownname         - owner name. If null it reports column usage information
< --                       for tables in all schemas in the database.
< --     tabname         - table name. If null, it reports column usage information
< --                       for all tables of ownname.
---
> --     ownname         - owner name. If null it reports column usage
> --                       information for tables in all schemas in the database.
> --     tabname         - table name. If null, it reports column usage
> --                       information for all tables of ownname.
4683c4687
< --...............................................................................
---
> --.............................................................................
4685c4689
< --###############################################################################
---
> --#############################################################################
4696c4700
< --###############################################################################
---
> --#############################################################################
5001a5006,5017
> 
>   -- For internal use
>   --
>   -- Quickly estimate number of rows in the table for auto sampling
>   --
>   function get_row_count_estimate(
>         ownname varchar2,                 -- table owner to select from
>         tabname varchar2,                 -- table name to select from
>         partname varchar2,                -- table partition name
>         nblks integer,
>         degree integer
>         ) return number;
SYS.CDBVIEW - PACKAGE BODY (BP):
119a120
>     ownerId      number;
125,129c126,132
<     execute immediate 'SELECT COUNT(*) FROM USER$ WHERE NAME = :1'
<              into cCheck using upper(owner);
<     if (cCheck = 0) then
<       RETURN FALSE;
<     end if;
---
>     -- USER$ contains both users and roles, exclude roles from the check
>     begin
>       execute immediate 'SELECT USER# FROM USER$ WHERE TYPE# = 1 AND NAME = :1'
>                into ownerId using upper(owner);
>     exception
>       when no_data_found then return false;
>     end;
131,137c134,146
<     -- Check if oldview already exist
<     execute immediate 'SELECT COUNT(*) FROM OBJ$ WHERE NAME = :1' ||
<                       ' AND (TYPE# = 4 OR TYPE# = 2)'
<              into cCheck using upper(oldview);
<     if (cCheck = 0) then
<       RETURN FALSE;
<     end if;
---
>     -- Check if oldview already exist, qualify with owner# to avoid ORA-1422
>     -- error,if two dictionary view with the same name exists across different
>     -- schemas like DBA_DV_STATUS which exists in both SYS and DVSYS schemas.
>     -- Bug 29339155: Check for remoteowner being null to avoid ORA-1422 error
>     -- if there were remote PL/SQL objects depending on oldview.
>     begin
>       execute immediate 'SELECT 1 FROM OBJ$ WHERE NAME = :1' ||
>                         ' AND TYPE# in (2, 4) and owner# = :2' ||
>                         ' AND REMOTEOWNER is null'
>                into cCheck using upper(oldview), ownerId;
>     exception
>       when no_data_found then return false;
>     end;
SYS.DBMS_RCVMAN - PACKAGE BODY (BP):
7446,7459d7445
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7499c7485,7497
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
7654c7652,7664
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
SYS.DBMS_RCVMAN - PACKAGE BODY (PSU):
422a423,424
> GUIDQUALIFIER VARCHAR2(32);
> 
1204a1207
>      AND (GUIDQUALIFIER IS NULL OR GUID = GUIDQUALIFIER)
1312a1316
>      AND (GUIDQUALIFIER IS NULL OR GUID = GUIDQUALIFIER)
1420a1425
>      AND (GUIDQUALIFIER IS NULL OR BS.GUID = GUIDQUALIFIER)
1532a1538
>       AND (GUIDQUALIFIER IS NULL OR BS.GUID = GUIDQUALIFIER)
1643a1650
>       AND (GUIDQUALIFIER IS NULL OR BS.GUID = GUIDQUALIFIER)
2029a2037
>      AND (GUIDQUALIFIER IS NULL OR DC.GUID = GUIDQUALIFIER)
2166a2175
>      AND (GUIDQUALIFIER IS NULL OR GUID = GUIDQUALIFIER)
2294a2304
>      AND (GUIDQUALIFIER IS NULL OR BS.GUID = GUIDQUALIFIER)
2574c2584,2586
<   ,STATUSMASK           IN     BINARY_INTEGER)
---
>   ,STATUSMASK           IN     BINARY_INTEGER
>   ,PDBKEY               IN     NUMBER         DEFAULT NULL
>   ,GUID                 IN     VARCHAR2       DEFAULT NULL)
2668a2681,2682
>       AND (FINDPROXYCOPY.GUID IS NULL OR
>            FINDPROXYCOPY.GUID = GUID)
2757a2772
>       AND (FINDPROXYCOPY.GUID IS NULL)
3773c3788,3790
<   ,STATUSMASK   IN     BINARY_INTEGER)
---
>   ,STATUSMASK   IN     BINARY_INTEGER
>   ,PDBKEY       IN     NUMBER   DEFAULT NULL
>   ,GUID         IN     VARCHAR2 DEFAULT NULL)
3812a3830,3831
>       AND (FINDBACKUPPIECE_C.GUID IS NULL OR
>            FINDBACKUPPIECE_C.GUID = BS.GUID)
4804c4823,4825
<      FROM X$KCCDC DC, V$CONTAINERS PDB
---
>      FROM X$KCCDC DC
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON DC.CON_ID = PDB.CON_ID
4807d4827
<       AND DC.CON_ID = PDB.CON_ID
4847c4867,4869
<      FROM X$KCCBF BF, V$CONTAINERS PDB
---
>      FROM X$KCCBF BF
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON BF.CON_ID = PDB.CON_ID
4850d4871
<       AND BF.CON_ID = PDB.CON_ID
4890c4911,4913
<      FROM X$KCCPD PD, V$CONTAINERS PDB
---
>      FROM X$KCCPD PD
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON PD.CON_ID = PDB.CON_ID
4893d4915
<       AND PD.CON_ID = PDB.CON_ID
5011c5033,5035
<      FROM X$KCCDC DC, V$CONTAINERS PDB
---
>      FROM X$KCCDC DC
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON DC.CON_ID = PDB.CON_ID
5014,5015c5038
<       AND DC.CON_ID  = PDB.CON_ID
<       AND PDB.CON_ID = TRANSLATEALLDFOFPDBID_C.PDBID
---
>       AND DC.CON_ID = TRANSLATEALLDFOFPDBID_C.PDBID
5055c5078,5080
<      FROM X$KCCBF BF, V$CONTAINERS PDB
---
>      FROM X$KCCBF BF
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON BF.CON_ID = PDB.CON_ID
5058,5059c5083
<       AND BF.CON_ID  = PDB.CON_ID
<       AND PDB.CON_ID = TRANSLATEALLDFOFPDBID_C.PDBID
---
>       AND BF.CON_ID = TRANSLATEALLDFOFPDBID_C.PDBID
5099c5123,5125
<      FROM X$KCCPD PD, V$CONTAINERS PDB
---
>      FROM X$KCCPD PD
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON PD.CON_ID = PDB.CON_ID
5102,5103c5128
<       AND PD.CON_ID  = PDB.CON_ID
<       AND PDB.CON_ID = TRANSLATEALLDFOFPDBID_C.PDBID
---
>       AND PD.CON_ID = TRANSLATEALLDFOFPDBID_C.PDBID
5220c5245,5247
<      FROM X$KCCDC DC, V$CONTAINERS PDB
---
>      FROM X$KCCDC DC
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON DC.CON_ID = PDB.CON_ID
5223,5224c5250
<       AND DC.CON_ID = PDB.CON_ID
<       AND ISTRANSLATEDPDBID(PDB.CON_ID) = TRUE#
---
>       AND ISTRANSLATEDPDBID(DC.CON_ID) = TRUE#
5264c5290,5292
<      FROM X$KCCBF BF, V$CONTAINERS PDB
---
>      FROM X$KCCBF BF
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON BF.CON_ID = PDB.CON_ID
5267,5268c5295
<       AND BF.CON_ID = PDB.CON_ID
<       AND ISTRANSLATEDPDBID(PDB.CON_ID) = TRUE#
---
>       AND ISTRANSLATEDPDBID(BF.CON_ID) = TRUE#
5308c5335,5337
<      FROM X$KCCPD PD, V$CONTAINERS PDB
---
>      FROM X$KCCPD PD
>      LEFT OUTER JOIN V$CONTAINERS PDB
>        ON PD.CON_ID = PDB.CON_ID
5311,5312c5340
<       AND PD.CON_ID = PDB.CON_ID
<       AND ISTRANSLATEDPDBID(PDB.CON_ID) = TRUE#
---
>       AND ISTRANSLATEDPDBID(PD.CON_ID) = TRUE#
7368,7381d7395
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7421c7435,7447
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
7576c7602,7614
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
13409c13447,13449
<   ,STARTBSKEY   IN     NUMBER          DEFAULT NULL)
---
>   ,STARTBSKEY   IN     NUMBER          DEFAULT NULL
>   ,PDBKEY       IN     NUMBER          DEFAULT NULL
>   ,GUID         IN     VARCHAR2        DEFAULT NULL)
13445c13485,13487
<                                 STATUSMASK  => STATUSMASK);
---
>                                 STATUSMASK  => STATUSMASK,
>                                 PDBKEY      => PDBKEY,
>                                 GUID        => GUID);
15531a15574
>    SETGUID(NULL);
21842a21886,21909
> PROCEDURE TRANSLATEPROXYCOPYGUID(
>    GUID        IN VARCHAR2
>   ,DEVICE_TYPE IN VARCHAR2
>   ,STATUSMASK  IN BINARY_INTEGER)
> IS
>    PDBKEY NUMBER := NULL;
> BEGIN
>    DEB(DEB_ENTER, 'translateProxyCopyGuid');
>    VALIDATESTATE(GETPROXYCOPYCURSOR);
>    DEB(DEB_OPEN, 'findProxyCopy');
> 
> 
>    OPEN FINDPROXYCOPY(PDBKEY         => PDBKEY,
>                       GUID           => GUID,
>                       DEVICETYPE     => DEVICE_TYPE,
>                       STATUSMASK     => NVL(STATUSMASK, 0));
>    GETPROXYCOPYCURSOR       := 'findProxyCopy';
>    GETPROXYCOPYNOROWS.ERROR := -20310;
>    GETPROXYCOPYNOROWS.MSG   := 'no matching proxy copy found';
>    GETPROXYCOPYBYHANDLE     := FALSE;
>    DEB(DEB_EXIT);
> END TRANSLATEPROXYCOPYGUID;
> 
> 
22209a22277,22293
> 
> PROCEDURE TRANSLATEBACKUPPIECEGUID(
>    GUID        IN VARCHAR2
>   ,STATUSMASK  IN BINARY_INTEGER)
> IS
>    PDBKEY  NUMBER := NULL;
> BEGIN
>    DEB(DEB_ENTER, 'translateBackupPieceGuid');
> 
> 
>    FINDBACKUPPIECE(PDBKEY      => PDBKEY,
>                    GUID        => GUID,
>                    STATUSMASK  => NVL(STATUSMASK, 0));
>    DEB(DEB_EXIT);
> END TRANSLATEBACKUPPIECEGUID;
> 
> 
22941a23026,23034
>    
>    IF (GUIDQUALIFIER IS NOT NULL) THEN
>       IF (FINDARCHIVEDLOGCOPY%ISOPEN) THEN
>          CLOSE FINDARCHIVEDLOGCOPY;
>       END IF;
>       DEB(DEB_EXIT, 'guid not valid for archivelog');
>       RAISE NO_DATA_FOUND;
>    END IF;
> 
23345a23439,23448
> 
>    
>    IF (GUIDQUALIFIER IS NOT NULL) THEN
>       IF (FINDARCLOGBACKUP%ISOPEN) THEN
>          CLOSE FINDARCLOGBACKUP;
>       END IF;
>       DEB(DEB_EXIT, 'guid not valid for archivelog');
>       RAISE NO_DATA_FOUND;
>    END IF;
> 
23731a23835,23843
>    
>    IF (GUIDQUALIFIER IS NOT NULL) THEN
>       IF (FINDARCLOGBACKUP%ISOPEN) THEN
>          CLOSE FINDARCLOGBACKUP;
>       END IF;
>       DEB(DEB_EXIT, 'guid not valid for archivelog');
>       RAISE NO_DATA_FOUND;
>    END IF;
> 
28605a28718,28725
> 
> 
> PROCEDURE SETGUID(
>    GUID IN VARCHAR2 DEFAULT NULL)
> IS
> BEGIN
>    GUIDQUALIFIER := GUID;
> END SETGUID;
SYS.DBMS_STATS - PACKAGE BODY (BP):
1222,1232c1222,1232
<     SUCCEEDED   INTEGER := 0,          
<     FAILED      INTEGER := 0,          
<     STOPPED     INTEGER := 0,          
<     STARTED     INTEGER := 0,          
<     SCHEDULED   INTEGER := 0,          
<                                        
<                                        
<     LASTJOB   VARCHAR(30),             
<     LASTEVENT SCHEDULER$_EVENT_INFO,   
<     SOFAR_PART  INTEGER := 0,          
<     SOFAR_SUBPART INTEGER := 0         
---
>     SUCCEEDED   INTEGER := 0,         
>     FAILED      INTEGER := 0,         
>     STOPPED     INTEGER := 0,         
>     STARTED     INTEGER := 0,         
>     SCHEDULED   INTEGER := 0,         
>                                       
>                                       
>     LASTJOB   VARCHAR(30),            
>     LASTEVENT SCHEDULER$_EVENT_INFO,  
>     SOFAR_PART  INTEGER := 0,         
>     SOFAR_SUBPART INTEGER := 0        
1235a1236
>   
1259c1260,1261
<     TOP_LEVEL BOOLEAN, 
---
>     TOP_LEVEL BOOLEAN,                          
>                                                 
1789a1792
>   
2249c2252,2254
<   FUNCTION CHECK_GRANULARITY(GRANULARITY VARCHAR2, GRANCHK VARCHAR2) RETURN BOOLEAN;
---
>   FUNCTION CHECK_GRANULARITY(GRANULARITY VARCHAR2, 
>                              GRANCHK VARCHAR2) RETURN BOOLEAN;
>   
2253a2259
> 
2255,2258c2261,2266
<                           JSTATS IN OUT NOCOPY JOBSTATSREC, 
<                           JOBSTAB IN OUT NOCOPY VARCHARTAB, ANAME VARCHAR2, LOPSTR VARCHAR2,
<                           EXCEPTIONPOLICY BINARY_INTEGER DEFAULT DSC_ABSORB,
<                           RETURNPOLICY BINARY_INTEGER DEFAULT DSC_WAIT_FOR_ALL);
---
>                                          JSTATS IN OUT NOCOPY JOBSTATSREC, 
>                                          JOBSTAB IN OUT NOCOPY VARCHARTAB,
>                                          ANAME VARCHAR2, LOPSTR VARCHAR2,
>                              EXCEPTIONPOLICY BINARY_INTEGER DEFAULT DSC_ABSORB,
>                                          RETURNPOLICY BINARY_INTEGER 
>                                             DEFAULT DSC_WAIT_FOR_ALL);
3304c3312,3314
<           TSTATS(I).TAB  || ' . ' || TSTATS(I).PART || ' . ' || TSTATS(I).SPART);
---
>                                        TSTATS(I).TAB  || ' . ' || 
>                                        TSTATS(I).PART || ' . ' || 
>                                        TSTATS(I).SPART);
3315c3325,3327
<           ISTATS(I).IND  || ' . ' || ISTATS(I).PART || ' . ' || ISTATS(I).SPART);
---
>                                        ISTATS(I).IND  || ' . ' || 
>                                        ISTATS(I).PART || ' . ' || 
>                                        ISTATS(I).SPART);
3929c3941,3942
<       RAISE_APPLICATION_ERROR(-20001, 'DBMS_STATS: str2bool: invalid boolean value.');
---
>       RAISE_APPLICATION_ERROR(-20001, 
>                               'DBMS_STATS: str2bool: invalid boolean value.');
4281c4294,4295
<     IF(TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes')) < 4) THEN      
---
>     IF(TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes'))
>        < 4) THEN      
5433c5447,5448
<          JOB_CLASS_NAME           => DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX,       
---
>          JOB_CLASS_NAME           => DSC_STATS_COLLECTION_JOB_CLASS || '_' || 
>                                      SUFFIX,       
5577c5592,5593
<       TRACE_ERROR('exception in monitoring_man_drop_agent: ' || ': ' || SQLERRM );
---
>       TRACE_ERROR('exception in monitoring_man_drop_agent: ' || ': ' ||
>                   SQLERRM );
5602a5619
>     
5625,5627c5642,5645
<         TRACE_ERROR('exception in monitoring_man_subscribe_agent: ' || SQLERRM);
<         RAISE_APPLICATION_ERROR(-20001, 'monitoring_man_subscribe_agent: ' || ANAME || 
<                                           ': ' || SQLERRM );       
---
>         TRACE_ERROR('exception in monitoring_man_subscribe_agent: ' || 
>                     SQLERRM);
>         RAISE_APPLICATION_ERROR(-20001, 'monitoring_man_subscribe_agent: ' || 
>                                         ANAME || ': ' || SQLERRM );       
5653c5671,5672
<   PROCEDURE JOB_MAN_PERFORM_CLEANUPS(FORCE BOOLEAN, DROP_JOB BOOLEAN, SUFFIX VARCHAR2, 
---
>   PROCEDURE JOB_MAN_PERFORM_CLEANUPS(FORCE BOOLEAN, DROP_JOB BOOLEAN, 
>                                      SUFFIX VARCHAR2, 
5662,5663c5681,5683
<     TRACE_TABLE('Perform Cleanups... ' ||  DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX
<                 || ' force: ' || BOOL2STR(FORCE) || ' drop_job: ' || BOOL2STR(DROP_JOB));  
---
>     TRACE_TABLE('Perform Cleanups... ' ||  DSC_STATS_COLLECTION_JOB_CLASS || 
>                 '_' || SUFFIX || ' force: ' || BOOL2STR(FORCE) || 
>                 ' drop_job: ' || BOOL2STR(DROP_JOB));  
5679c5699,5700
<             JOB_NAME         => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX,
---
>             JOB_NAME         => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || 
>                                 '_' || SUFFIX,
5699c5720,5721
<                JOB_CLASS_NAME   => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX);
---
>                JOB_CLASS_NAME   => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || 
>                                    '_' || SUFFIX);
5702a5725
>                                                     
5763c5786,5787
<       TRACE_ERROR('exception in monitoring_man_process_event: ' || ': ' || SQLERRM);
---
>       TRACE_ERROR('exception in monitoring_man_process_event: ' || ': ' || 
>                   SQLERRM);
5780c5804,5805
<   PROCEDURE GET_JOB_STATS(JOBSTAB IN OUT NOCOPY VARCHARTAB, JSTATS IN OUT NOCOPY JOBSTATSREC) 
---
>   PROCEDURE GET_JOB_STATS(JOBSTAB IN OUT NOCOPY VARCHARTAB, 
>                           JSTATS IN OUT NOCOPY JOBSTATSREC) 
5815a5841
>   
5873a5900,5904
>   
>   
>   
>   
>   
5876c5907,5908
<                           JOBSTAB IN OUT NOCOPY VARCHARTAB, ANAME VARCHAR2, LOPSTR VARCHAR2,
---
>                           JOBSTAB IN OUT NOCOPY VARCHARTAB, ANAME VARCHAR2, 
>                           LOPSTR VARCHAR2,
5878c5910
<                           RETURNPOLICY BINARY_INTEGER DEFAULT DSC_WAIT_FOR_ALL) 
---
>                           RETURNPOLICY BINARY_INTEGER DEFAULT DSC_WAIT_FOR_ALL)
5898,5899c5930,5932
<     TRACE_TABLE(ANAME || ': waiting for jobs in wait_for_jobs...* ' 
<                 || TO_CHAR(JOBSTAB.COUNT - (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED)));      
---
>     TRACE_TABLE(ANAME || ': waiting for jobs in wait_for_jobs...* ' || 
>                 TO_CHAR(JOBSTAB.COUNT - 
>                         (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED)));
5910c5943,5944
<       DEQUEUE_OPTIONS.DEQ_CONDITION := 'tab.user_data.object_name like ''' || JOB_NAME_PREFIX || '%'''; 
---
>       DEQUEUE_OPTIONS.DEQ_CONDITION := 'tab.user_data.object_name like ''' || 
>                                        JOB_NAME_PREFIX || '%'''; 
5913c5947,5948
<     WHILE (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED) < JOBSTAB.COUNT LOOP
---
>     WHILE (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED) < 
>           JOBSTAB.COUNT LOOP
5921a5957
>       
5922a5959
>         
5928a5966
>         
5957c5995,5996
<       TRACE_TABLE('  >> process event: ' || MESSAGE.OBJECT_NAME || ' > ' || MESSAGE.EVENT_TYPE || 
---
>       TRACE_TABLE('  >> process event: ' || MESSAGE.OBJECT_NAME || ' > ' || 
>                   MESSAGE.EVENT_TYPE || 
5966c6005,6006
<         TRACE_TABLE(' *** Failure Event: ' || MESSAGE.ERROR_CODE || ': ' || MESSAGE.ERROR_MSG);
---
>         TRACE_TABLE(' *** Failure Event: ' || MESSAGE.ERROR_CODE || ': ' || 
>                     MESSAGE.ERROR_MSG);
5969c6009,6010
<           RAISE_APPLICATION_ERROR(-20000, 'insufficient privileges to analyze an object.');
---
>           RAISE_APPLICATION_ERROR(-20000, 
>                               'insufficient privileges to analyze an object.');
6004c6045,6046
<         DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS(PROGRESSREC.RINDEX, PROGRESSREC.SLNO,
---
>         DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS(PROGRESSREC.RINDEX, 
>                                                   PROGRESSREC.SLNO,
6026c6068,6070
<       TRACE_ERROR(JOB_NAME_PREFIX ||': exception in monitoring_man_wait_for_jobs: ' || ': ' || SQLERRM );      
---
>       TRACE_ERROR(JOB_NAME_PREFIX ||
>                   ': exception in monitoring_man_wait_for_jobs: ' || ': ' || 
>                   SQLERRM );      
6398a6443,6462
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
6488,6493c6552,6559
<        TRACE_ERROR('Exception while creating job ' || JOBNAME || ' for table(s) ' ||
<                    COMMENTS || ' at ' || SYSTIMESTAMP ||                    
<                    ' jobsTab.count: ' || TO_CHAR(JOBSTAB.COUNT) || ': ' || SQLERRM );  
<        RAISE_APPLICATION_ERROR(-20001, 'Exception while creating job ' || JOBNAME || ' for table(s) ' ||
<                    COMMENTS || ' at ' || SYSTIMESTAMP ||                    
<                    ' jobsTab.count: ' || TO_CHAR(JOBSTAB.COUNT) || ': ' || SQLERRM);
---
>        TRACE_ERROR('Exception while creating job ' || JOBNAME || 
>                    ' for table(s) ' || COMMENTS || ' at ' || SYSTIMESTAMP ||
>                    ' jobsTab.count: ' || TO_CHAR(JOBSTAB.COUNT) || ': ' || 
>                    SQLERRM );  
>        RAISE_APPLICATION_ERROR(-20001, 'Exception while creating job ' || 
>                                JOBNAME || ' for table(s) ' || COMMENTS || 
>                                ' at ' || SYSTIMESTAMP || ' jobsTab.count: ' ||
>                                TO_CHAR(JOBSTAB.COUNT) || ': ' || SQLERRM);
6513a6580,6581
>   
>   
7671c7739,7743
<   PROCEDURE URGENT_CLEANUP(JOBSTAB IN OUT NOCOPY VARCHARTAB, JOB_CLASS_SUFFIX VARCHAR2,
---
>   
>   
>   
>   PROCEDURE URGENT_CLEANUP(JOBSTAB IN OUT NOCOPY VARCHARTAB, 
>                            JOB_CLASS_SUFFIX VARCHAR2,
7678c7750,7751
<     CLASS_SUFFIX DBMS_QUOTED_ID := DBMS_ASSERT_SIMPLE_SQL_NAME(JOB_CLASS_SUFFIX);
---
>     CLASS_SUFFIX DBMS_QUOTED_ID := 
>                                  DBMS_ASSERT_SIMPLE_SQL_NAME(JOB_CLASS_SUFFIX);
7696c7769,7770
<                        select owner ||'.' || job_name name from dba_scheduler_jobs  
---
>                        select owner ||'.' || job_name name 
>                        from dba_scheduler_jobs  
7699c7773,7774
<                        select job_class_name name from dba_scheduler_job_classes  
---
>                        select job_class_name name 
>                        from dba_scheduler_job_classes  
7722c7797,7798
<                        dbms_scheduler.stop_job(job_name=>rec.name, force=>true);
---
>                        dbms_scheduler.stop_job(job_name=>rec.name, 
>                                                force=>true);
7739c7815,7816
<                        dbms_scheduler.drop_job(job_name=>rec.name, force=>true);
---
>                        dbms_scheduler.drop_job(job_name=>rec.name, 
>                                                force=>true);
7749c7826,7827
<                      dbms_scheduler.drop_job_class(job_class_name=>rec.name, force=>true);
---
>                      dbms_scheduler.drop_job_class(job_class_name=>rec.name, 
>                                                    force=>true);
7758,7760c7836,7841
<                      subscriber := sys.aq$_agent (rec.name, 'sys.scheduler$_event_queue', null);
<                      dbms_aqadm.remove_subscriber('sys.scheduler$_event_queue', subscriber);   
<                      dbms_aqadm.drop_aq_agent (rec.name);                          
---
>                      subscriber := sys.aq$_agent (rec.name, 
>                                                   'sys.scheduler$_event_queue',
>                                                   null);
>                      dbms_aqadm.remove_subscriber('sys.scheduler$_event_queue',
>                                                   subscriber);   
>                      dbms_aqadm.drop_aq_agent (rec.name);
7786c7867,7868
<    TRACE_TABLE('Created Cleanup Job ' || LOC_JOB_NAME ||  ' at ' || SYSTIMESTAMP);  
---
>    TRACE_TABLE('Created Cleanup Job ' || LOC_JOB_NAME ||  ' at ' || 
>                SYSTIMESTAMP);  
7848a7931
>     
7850c7933
<       RES := MONITORING_MAN_SUBSCRIBE_AGENT(JOB_NAME_PREFIX, USERNAMEU);                
---
>       RES := MONITORING_MAN_SUBSCRIBE_AGENT(JOB_NAME_PREFIX, USERNAMEU);
7856c7939,7940
<         TRACE_ERROR('Silent exception in init_conc: agent subscription has failed');
---
>         TRACE_ERROR(
>                'Silent exception in init_conc: agent subscription has failed');
7910a7995,7997
>   
>   
>   
7953c8040
<         PROP := DBMS_STATS_INTERNAL.GET_TAB_PROPERTY(OWNER, TABNAME);                     
---
>         PROP := DBMS_STATS_INTERNAL.GET_TAB_PROPERTY(OWNER, TABNAME);
7962c8049,8050
<            NOT (BITAND(PROP, 4194304) = 4194304 OR BITAND(PROP, 8388608) = 8388608)           
---
>            NOT (BITAND(PROP, 4194304) = 4194304 OR BITAND(PROP, 8388608) = 
>                 8388608)           
7992c8080,8081
<             LOC_JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(DSC_JOB_PREF || 'T');
---
>             LOC_JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(
>                                                           DSC_JOB_PREF || 'T');
7998c8087
<             IF(IS_NULL(BATCHING_JOB_PREFIX) AND IS_NULL(JOB_NAME_PREFIX)) THEN              
---
>             IF(IS_NULL(BATCHING_JOB_PREFIX) AND IS_NULL(JOB_NAME_PREFIX)) THEN
8001c8090,8091
<                 TRACE_TABLE('Disabling concurrency as initializations have failed');
---
>                 TRACE_TABLE(
>                        'Disabling concurrency as initializations have failed');
8009,8010c8099,8101
<               JOB_MAN_PERFORM_CLEANUPS(TRUE, FALSE, BATCHING_JOB_PREFIX, CONCTX.JOBSTAB, 
<                                        TRUE, TRUE);  
---
>               
>               JOB_MAN_PERFORM_CLEANUPS(TRUE, FALSE, BATCHING_JOB_PREFIX, 
>                                        CONCTX.JOBSTAB, TRUE, TRUE);  
8132c8223,8224
<       (OWNER VARCHAR2, OBJNAMEU IN OUT NOCOPY VARCHAR2, OBJTYPE BINARY_INTEGER) IS
---
>      (OWNER VARCHAR2, OBJNAMEU IN OUT NOCOPY VARCHAR2, OBJTYPE BINARY_INTEGER)
>   IS
8774c8866
<       DBMS_STATS_INTERNAL.PART_TYPES(OWNNAME, OBJNAME, OBJTYPE, PTYPE, SPTYPE);   
---
>       DBMS_STATS_INTERNAL.PART_TYPES(OWNNAME, OBJNAME, OBJTYPE, PTYPE, SPTYPE);
8823a8916,8917
>   
>   
9149c9243,9244
<         STATS_CHECK_PRIVILEGES(OWNER, TREC.OBJ_NAME, DSC_KGLNTABL, FALSE, NULL);
---
>         STATS_CHECK_PRIVILEGES(OWNER, TREC.OBJ_NAME, DSC_KGLNTABL, FALSE, 
>                                NULL);
9316c9411
<                   DBMS_ASSERT.SIMPLE_SQL_NAME(DBMS_STATS_INTERNAL.DQ(COL.PCNAME));
---
>                DBMS_ASSERT.SIMPLE_SQL_NAME(DBMS_STATS_INTERNAL.DQ(COL.PCNAME));
9579,9580c9674,9675
<     CONVERT_FROM_RAW_ICD(DSC_DTYIBFLOAT, RAWVAL, CVAL, DVAL, NVAL, NCVAL, RWVAL,
<                          RESVAL, BDVAL);
---
>     CONVERT_FROM_RAW_ICD(DSC_DTYIBFLOAT, RAWVAL, CVAL, DVAL, NVAL, NCVAL, 
>                          RWVAL, RESVAL, BDVAL);
9595,9596c9690,9691
<     CONVERT_FROM_RAW_ICD(DSC_DTYIBDOUBLE, RAWVAL, CVAL, DVAL, NVAL, NCVAL, RWVAL,
<                          BFVAL, RESVAL);
---
>     CONVERT_FROM_RAW_ICD(DSC_DTYIBDOUBLE, RAWVAL, CVAL, DVAL, NVAL, NCVAL, 
>                          RWVAL, BFVAL, RESVAL);
9830,9831c9925,9926
<       RAISE_APPLICATION_ERROR(-20000, 'Unsupported data type ' || TYP_CODE || ' ' ||
<                                TBL_NAME || ' ' || COL_NAME);
---
>       RAISE_APPLICATION_ERROR(-20000, 'Unsupported data type ' || TYP_CODE || 
>                                       ' ' || TBL_NAME || ' ' || COL_NAME);
10320c10415,10416
<       FOR REC IN DBMS_STATS_INTERNAL.PART_NAME_QRY(TBL_OWNER,TBL_NAME,PART_NAME)
---
>       FOR REC IN DBMS_STATS_INTERNAL.PART_NAME_QRY(TBL_OWNER,TBL_NAME,
>                                                    PART_NAME)
10577c10673,10674
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot store user statistics in external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot store user statistics in external statistics table');
10679c10776,10777
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot get user statistics from external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot get user statistics from external statistics table');
10804c10902,10903
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot store user statistics in external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot store user statistics in external statistics table');
10872c10971,10972
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot get user statistics from external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot get user statistics from external statistics table');
11457,11458c11557,11558
<               RAISE_APPLICATION_ERROR(-20000, 'Could not find anything wrong '||
<                 'with statistics table ' || STATOWNU || '.' || STATTABU ||
---
>               RAISE_APPLICATION_ERROR(-20000, 'Could not find anything '||
>                'wrong with statistics table ' || STATOWNU || '.' || STATTABU ||
13335c13435,13436
<         INT_ASSERT(FALSE,'show_extended_stats_name_aux', 'invalid extn_type', FALSE, 0);
---
>         INT_ASSERT(FALSE,'show_extended_stats_name_aux', 'invalid extn_type', 
>                    FALSE, 0);
13361c13462,13463
<         RAISE_APPLICATION_ERROR(-20001, 'Error when processing extension - ' || 
---
>         RAISE_APPLICATION_ERROR(-20001, 
>                                 'Error when processing extension - ' || 
13392c13494
<             BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
---
>            BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
13404c13506,13507
<       DBMS_STATS_INTERNAL.DUMP_TRACE('Trying to create extension ' || SAFE_EXTN);
---
>       DBMS_STATS_INTERNAL.DUMP_TRACE('Trying to create extension ' || 
>                                      SAFE_EXTN);
13552c13655
<                                  'not supported for an index organized table ');
---
>                                 'not supported for an index organized table ');
13567c13670,13671
<           RAISE_APPLICATION_ERROR(-20001, 'Error when processing extension - ' || 
---
>           RAISE_APPLICATION_ERROR(-20001, 
>                                   'Error when processing extension - ' || 
13628c13732
<             BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
---
>            BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
13673a13778
>       
13710a13816
>   
13872c13978,13979
<                       LASTTABNAME,LASTCOLNAME,LASTPARTNAME,LASTSUBPARTNAME,OWNER;
---
>                       LASTTABNAME,LASTCOLNAME,LASTPARTNAME,LASTSUBPARTNAME,
>                       OWNER;
14162c14269,14270
<         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, PARTNAMEU);
---
>         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, 
>                                                     PARTNAMEU);
14275c14383
<              'Invalid or inconsistent input values in the histogram endpoints');
---
>             'Invalid or inconsistent input values in the histogram endpoints');
14558c14666,14667
<           IF ((ISTATS(I).ALBLK IS NULL) AND (ISTATS(I).NLBLKS IS NOT NULL)) THEN
---
>           IF ((ISTATS(I).ALBLK IS NULL) AND 
>               (ISTATS(I).NLBLKS IS NOT NULL)) THEN
14713c14822,14823
<         OPEN SYS.DBMS_STATS_INTERNAL.GET_IPART_NAME(OWNER, INDNAMEU, PARTNAMEU);
---
>         OPEN SYS.DBMS_STATS_INTERNAL.GET_IPART_NAME(OWNER, INDNAMEU, 
>                                                     PARTNAMEU);
15477c15587,15588
<         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, PARTNAMEU);
---
>         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, 
>                                                     PARTNAMEU);
16127c16238,16239
<         OBJ_TRANSFERRED IN OUT BOOLEAN, 
---
>         OBJ_TRANSFERRED IN OUT BOOLEAN,               
>                                                       
16320c16432,16433
<         OBJ_TRANSFERRED IN OUT BOOLEAN, 
---
>         OBJ_TRANSFERRED IN OUT BOOLEAN,               
>                                                       
16473c16586,16587
<       IF ((DELETEST = FALSE) AND (FROMTABU IS NULL) AND TOTABU IS NOT NULL) THEN
---
>       IF ((DELETEST = FALSE) AND (FROMTABU IS NULL) AND 
>           TOTABU IS NOT NULL) THEN
16573c16687,16688
<             TOBJN := DBMS_STATS_INTERNAL.GET_OBJNUM(TSTATS(I).OWN, TSTATS(I).TAB, 
---
>             TOBJN := DBMS_STATS_INTERNAL.GET_OBJNUM(TSTATS(I).OWN, 
>                                                     TSTATS(I).TAB, 
17003,17004c17118,17119
<         STATOWN, 'Schema', NO_INVALIDATE, FALSE, STATTYPE, FORCE, OBJ_TRANSFERRED,
<         FALSE, STAT_CATEGORY);
---
>         STATOWN, 'Schema', NO_INVALIDATE, FALSE, STATTYPE, FORCE, 
>         OBJ_TRANSFERRED, FALSE, STAT_CATEGORY);
17018,17019c17133,17134
<       STATOWN, 'Database', NO_INVALIDATE, FALSE, STATTYPE, FORCE, OBJ_TRANSFERRED,
<       TRUE, STAT_CATEGORY);
---
>       STATOWN, 'Database', NO_INVALIDATE, FALSE, STATTYPE, FORCE, 
>       OBJ_TRANSFERRED, TRUE, STAT_CATEGORY);
17295c17410,17411
<         RAISE_APPLICATION_ERROR (-20001, 'Invalid or inconsistent input values');
---
>         RAISE_APPLICATION_ERROR (-20001, 
>                                  'Invalid or inconsistent input values');
17971,17972c18087,18088
<       TXT := 'select statid,type,version,flags,c1,c2,c3,c4,n1,n2,n3,n4,n5,n6,' ||
<           'n7,n8,n9,d1,r1,r2 from ' || DBMS_STATS_INTERNAL.DQ(OWNER) ||
---
>       TXT := 'select statid,type,version,flags,c1,c2,c3,c4,n1,n2,n3,n4,n5,' ||
>           'n6,n7,n8,n9,d1,r1,r2 from ' || DBMS_STATS_INTERNAL.DQ(OWNER) ||
19138a19255
>                                      
19140c19257,19258
<     LOCAL_BKTNUM INTEGER;     
---
>                                      
>     LOCAL_BKTNUM INTEGER; 
19551a19670
>                 
19553c19672,19673
<                     BITAND(CLIST(CIND).HGATH, DSC_CREC_EP+DSC_CREC_RP) = 0) THEN
---
>                     BITAND(CLIST(CIND).HGATH, DSC_CREC_EP+DSC_CREC_RP) = 
>                     0) THEN
19759,19760c19879,19880
<          'invalid column name or duplicate columns/column groups/expressions' ||
<          ' in method_opt');
---
>         'invalid column name or duplicate columns/column groups/expressions' ||
>         ' in method_opt');
19859c19979
<             BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
---
>            BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
20632a20753
>   
22361a22483,22566
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>   FUNCTION GET_ROW_COUNT_ESTIMATE (
>         OWNNAME VARCHAR2,                 
>         TABNAME VARCHAR2,                 
>         PARTNAME VARCHAR2,                
>         NBLKS INTEGER,
>         DEGREE INTEGER
>         ) RETURN NUMBER IS
>     ROW_COUNT    NUMBER;
>     OWNER        VARCHAR2(30);
>     TABNAMEU     VARCHAR2(30);
>     PARTNAMEU    VARCHAR2(30);
>     FOBJN        NUMBER;
>     PNAME        VARCHAR2(30);
>     SPNAME       VARCHAR2(30);
>     SEED         INTEGER;
>     NO_ITERATION BOOLEAN;
>     PARTTYPE     NUMBER;
>   BEGIN
>     FILL_IN_SCHEMA(OWNNAME, OWNER);
>     UPCASE(TABNAME, TABNAMEU);
>     UPCASE(PARTNAME, PARTNAMEU);
>     STATS_CHECK_PRIVILEGES(OWNER, TABNAMEU, DSC_KGLNTABL, FALSE, NULL);
> 
>     IF (PARTNAMEU IS NOT NULL) THEN
>       
>       VALIDATE_PART(OWNER, TABNAMEU, PARTNAMEU, DSC_KGLTTABL, NULL);
> 
>       
>       FOBJN := DBMS_STATS_INTERNAL.GET_OBJNUM(OWNER, TABNAMEU, PARTNAMEU, NULL,
>                                               'TABLE');
> 
>       
>       IF (PARTTYPE = 5 ) THEN
>         SPNAME := PARTNAMEU;
>       ELSE
>         PNAME := PARTNAMEU;
>       END IF;
>     END IF;
> 
>     GET_EVENT_LEVEL(DSC_SAMPLE_SEED_EVENT, SEED);
> 
>     IF (DBMS_STATS_INTERNAL.GET_FXT_TYP(OWNER, TABNAME) = DSC_NON_FXT) THEN
>       NO_ITERATION := FALSE;
>     ELSE
>       NO_ITERATION := TRUE;
>     END IF;    
> 
>     QUICK_ESTIMATE_ROWCNT(OWNER,
>                           TABNAMEU,
>                           PNAME,
>                           SPNAME,
>                           FOBJN,
>                           ROW_COUNT,
>                           SEED,
>                           NBLKS,
>                           DEGREE,
>                           NO_ITERATION);
>     RETURN ROW_COUNT;
>   END GET_ROW_COUNT_ESTIMATE;
> 
> 
22457c22662
<         CLIST IN OUT NOCOPY CTAB,                     
---
>         CLIST IN OUT NOCOPY CTAB,       
22627c22832
<         CLIST IN OUT NOCOPY CTAB,              
---
>         CLIST IN OUT NOCOPY CTAB,       
23640a23846
>             
23930a24137
>                                         
24435,24437c24642,24644
<                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || PART.PNAME
<                     || ' set to ' || CSTATS(1).DIST || ' (ndv of ' || COLUMN_NAME
<                     || ')');
---
>                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || 
>                               PART.PNAME || ' set to ' || CSTATS(1).DIST ||
>                               ' (ndv of ' || COLUMN_NAME || ')');
24439,24441c24646,24648
<                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || SPART.SPNAME
<                     || ' set to ' || CSTATS(1).DIST || ' (ndv of ' || COLUMN_NAME
<                     || ')');
---
>                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || 
>                               SPART.SPNAME || ' set to ' || CSTATS(1).DIST ||
>                               ' (ndv of ' || COLUMN_NAME || ')');
24460c24667,24668
<       IF (COLLECT_NDK AND TSTATS_UPTODATE AND SAMPLE_PCT < DSC_SAMPLE_MAXPCT AND
---
>       IF (COLLECT_NDK AND TSTATS_UPTODATE AND 
>           SAMPLE_PCT < DSC_SAMPLE_MAXPCT AND
25464c25672,25673
<             RESTORE_INDEX_STATS_AUX(DBMS_STATS_INTERNAL.DQ(LOPINFO(SOFAR).NAME2),
---
>             RESTORE_INDEX_STATS_AUX(DBMS_STATS_INTERNAL.DQ(
>                                                          LOPINFO(SOFAR).NAME2),
25593c25802,25803
<       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, NULL, NULL, IDX.TOBJN);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, NULL, NULL, 
>                                     IDX.TOBJN);
25598c25808,25809
<       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, NULL, NULL, IDX.TOBJN);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, NULL, 
>                                     NULL, IDX.TOBJN);
25602c25813,25814
<       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDXGRAN, NULL, NULL, IDX.TOBJN);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDXGRAN, NULL, NULL, 
>                                     IDX.TOBJN);
25794c26006,26007
<                       (BITAND(DBMS_SQLDIAG.GET_FIX_CONTROL(8917507), 2) = 2) AND
---
>                       (BITAND(DBMS_SQLDIAG.GET_FIX_CONTROL(8917507), 2) = 
>                        2) AND
25819,25820c26032,26035
<           TRACE_INDEX('last: ' || TO_CHAR(SPART.LAST_ANALYZED, 'MM-DD-YYYY HH24:MI:SS') || 
<                       ' start_time: ' || TO_CHAR(START_TIME, 'MM-DD-YYYY HH24:MI:SS'));
---
>           TRACE_INDEX('last: ' || TO_CHAR(SPART.LAST_ANALYZED, 
>                                           'MM-DD-YYYY HH24:MI:SS') || 
>                       ' start_time: ' || TO_CHAR(START_TIME, 
>                                                  'MM-DD-YYYY HH24:MI:SS'));
26522c26737,26738
<         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = DSC_CREC_MINMAX) AND
---
>         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = 
>              DSC_CREC_MINMAX) AND
26594c26810,26811
<         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = DSC_CREC_MINMAX) AND
---
>         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = 
>              DSC_CREC_MINMAX) AND
27245c27462,27463
<         TRACE_SCALING('  Caught an unusable-index error.  giving up combo-ndv scaling');
---
>         TRACE_SCALING(
>              '  Caught an unusable-index error.  giving up combo-ndv scaling');
27333,27334c27551,27553
<         TRACE_HIST('Switching to frequency histogram, ssize = ' || SSIZE || ', popcnt = ' 
<                   || POPCNT || ', ssizesq = ' || SSIZESQ || ', popcntsq = ' || POPCNTSQ);
---
>         TRACE_HIST('Switching to frequency histogram, ssize = ' || SSIZE || 
>                    ', popcnt = ' || POPCNT || ', ssizesq = ' || SSIZESQ || 
>                    ', popcntsq = ' || POPCNTSQ);
27570,27571c27789,27791
<     EVALUATE_HEIGHT_HIST(CSR, CHT, DONE_HIST, PCT, POPCNT, POPCNTSQ, SSIZE, SSIZESQ,
<                          MIN_SSIZE, APPR_NDV, TRUE, INCREMENTAL);   
---
>     
>     EVALUATE_HEIGHT_HIST(CSR, CHT, DONE_HIST, PCT, POPCNT, POPCNTSQ, SSIZE, 
>                          SSIZESQ, MIN_SSIZE, APPR_NDV, TRUE, INCREMENTAL);   
27601c27821,27822
<                           POPCNT, POPCNTSQ, PCT, DONE_HIST, CSR.SLSV, APPR_NDV);
---
>                                                 POPCNT, POPCNTSQ, PCT,
>                                                 DONE_HIST, CSR.SLSV, APPR_NDV);
27851,27852c28072,28074
<             CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, LOC_PPREDTXT,
<                                        PRETXT, POSTTXT, MATERIALIZE);
---
>             CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, 
>                                        LOC_PPREDTXT, PRETXT, POSTTXT, 
>                                        MATERIALIZE);
27871,27872c28093,28095
<               CONSTRUCT_SELECT_HEIGHT(CLIST(LOOPVAR), MNB, LOC_HINTTXT, LOC_PPREDTXT,
<                                     PRETXT, POSTTXT, MATERIALIZE);
---
>               CONSTRUCT_SELECT_HEIGHT(CLIST(LOOPVAR), MNB, LOC_HINTTXT, 
>                                       LOC_PPREDTXT, PRETXT, POSTTXT, 
>                                       MATERIALIZE);
27889,27890c28112,28114
<               CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, LOC_PPREDTXT,
<                                          PRETXT, POSTTXT, MATERIALIZE);
---
>               CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, 
>                                          LOC_PPREDTXT, PRETXT, POSTTXT,
>                                          MATERIALIZE);
28227c28451
<           IF (BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_AVG) = DSC_CREC_AVG) THEN            
---
>           IF (BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_AVG) = DSC_CREC_AVG) THEN
28341,28344c28565,28568
<               TRACE_SCALING(' Need larger sample: sndv = ' || CLIST(LOOPVAR).SNDV
<                             || ', snnvdv = ' || CLIST(LOOPVAR).SNNVDV
<                             || ', nnv = ' || NNV
<                             || ', ndv = ' || CLIST(LOOPVAR).NDV);
---
>               TRACE_SCALING(' Need larger sample: sndv = ' || 
>                             CLIST(LOOPVAR).SNDV || ', snnvdv = ' || 
>                             CLIST(LOOPVAR).SNNVDV || ', nnv = ' || NNV || 
>                             ', ndv = ' || CLIST(LOOPVAR).NDV);
28509c28733,28734
<               IF DBMS_STATS_INTERNAL.COLHASHISTOGRAM(TOBJN, CLIST(LOOPVAR).ICOL) THEN
---
>               IF DBMS_STATS_INTERNAL.COLHASHISTOGRAM(TOBJN, 
>                                                      CLIST(LOOPVAR).ICOL) THEN
28511c28736,28737
<                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, DSC_CREC_HIST);
---
>                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, 
>                                               DSC_CREC_HIST);
28517c28743,28744
<                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, DSC_CREC_HIST);
---
>                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, 
>                                               DSC_CREC_HIST);
29900c30127
<         IF (BITAND(SEL.GATHFLG, DSC_SELREC_RES) = DSC_SELREC_RES) THEN             
---
>         IF (BITAND(SEL.GATHFLG, DSC_SELREC_RES) = DSC_SELREC_RES) THEN
30846c31073
<                 'Unable to incrementally maintain, tablespace SYSAUX is offline');
---
>              'Unable to incrementally maintain, tablespace SYSAUX is offline');
30959a31187
>   
31324c31552
<     NEW_HIST_PCT BOOLEAN := FALSE;   
---
>     NEW_HIST_PCT BOOLEAN := FALSE;  
31469,31474c31697,31704
<                  OWNER, TABNAME, PNAME, SPNAME,  PCT, CTX.CONC_CTX.BLOCK_SAMPLE, 
<                  CTX.CONC_CTX.METHOD_OPT, DEGREE, LOC_GRANULARITY, CTX.CONC_CTX.GIDXGRAN, 
<                  CTX.CONC_CTX.CASCADE, NULL, NULL, NULL, CTX.CONC_CTX.NO_INVALIDATE,
<                  CTX.CONC_CTX.FLUSH_COLU, FXT_TYP, CTX.CONC_CTX.STATTYPE, CTX.CONC_CTX.START_TIME, 
<                  CTX.CONC_CTX.GATHERING_GROUP_STATS, CTX.CONC_CTX.CMS_ONLY, CTX.CONC_CTX.FORCE, 
<                  DSC_EXECUTE, CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB,
---
>                  OWNER, TABNAME, PNAME, SPNAME,  PCT, 
>                  CTX.CONC_CTX.BLOCK_SAMPLE, CTX.CONC_CTX.METHOD_OPT, DEGREE, 
>                  LOC_GRANULARITY, CTX.CONC_CTX.GIDXGRAN, CTX.CONC_CTX.CASCADE, 
>                  NULL, NULL, NULL, CTX.CONC_CTX.NO_INVALIDATE, 
>                  CTX.CONC_CTX.FLUSH_COLU, FXT_TYP, CTX.CONC_CTX.STATTYPE, 
>                  CTX.CONC_CTX.START_TIME, CTX.CONC_CTX.GATHERING_GROUP_STATS, 
>                  CTX.CONC_CTX.CMS_ONLY, CTX.CONC_CTX.FORCE, DSC_EXECUTE, 
>                  CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB,
31477,31480c31707,31711
<                  CTX.REPORTING_CTX.PRIORITY, CTX.REPORTING_CTX.FLAGS, TARGET_SIZE, 
<                  BATCHING_COEFF, 
<                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.REPORTING_CTX.TARGET_TYPE,
<                  DSC_STOP_ON_FIRST, REPORTING_MODE);
---
>                  CTX.REPORTING_CTX.PRIORITY, CTX.REPORTING_CTX.FLAGS, 
>                  TARGET_SIZE, BATCHING_COEFF, 
>                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX, 
>                  CTX.REPORTING_CTX.TARGET_TYPE, DSC_STOP_ON_FIRST, 
>                  REPORTING_MODE);
31918c32149,32150
<             NEW_PCT := GET_NEW_PCT_FOR_APPR_NDV(CURR_PCT, CLIST, ISTART, ISTOP);
---
>             NEW_PCT := GET_NEW_PCT_FOR_APPR_NDV(CURR_PCT, CLIST, ISTART, 
>                                                 ISTOP);
32155c32387,32388
<             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTABP, NULL);
---
>             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTABP, 
>                                                         NULL);
32158c32391,32392
<             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTASP, NULL);
---
>             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTASP, 
>                                                         NULL);
32363c32597,32598
<       FOR RECP IN SYS.DBMS_STATS_INTERNAL.TSPART_CUR_ORDERED(OWNER,TABNAME,PNAME) 
---
>       FOR RECP IN SYS.DBMS_STATS_INTERNAL.TSPART_CUR_ORDERED(OWNER,TABNAME,
>                                                              PNAME) 
32506c32741
<                                DSC_ACTION_GATHER, NULL, SCSFLAGS);                  
---
>                                DSC_ACTION_GATHER, NULL, SCSFLAGS);
32520c32755,32756
<            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) = DSC_PREPARE)) THEN 
---
>            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) = 
>            DSC_PREPARE)) THEN 
32526c32762,32763
<       TRACE_ERROR('gather_subpart [executeStatJobs: '|| BOOL2STR(CTX.CONC_CTX.EXECUTESTATJOBS) || ']');      
---
>       TRACE_ERROR('gather_subpart [executeStatJobs: '|| 
>                   BOOL2STR(CTX.CONC_CTX.EXECUTESTATJOBS) || ']');      
32902c33139
<           JOBPROGRESSMON(CTX.CONC_CTX.LAST_JOB_NAME) := LOPINFO(SOFAR);                   
---
>           JOBPROGRESSMON(CTX.CONC_CTX.LAST_JOB_NAME) := LOPINFO(SOFAR);
33086a33324
>                                     
33110,33111c33348,33351
<     CTX.CONC_CTX.EXECUTESTATJOBS := BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE 
<                               OR BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_SEQ) = DSC_SEQ;
---
>     CTX.CONC_CTX.EXECUTESTATJOBS := BITAND(CTX.CONC_CTX.EXECUTIONPHASE, 
>                                            DSC_EXECUTE) = DSC_EXECUTE OR
>                                     BITAND(CTX.CONC_CTX.EXECUTIONPHASE, 
>                                            DSC_SEQ) = DSC_SEQ;
33116c33356,33357
<                           || ' global_requested: ' || BOOL2STR(CTX.CONC_CTX.GLOBAL_REQUESTED)
---
>                           || ' global_requested: ' 
>                           || BOOL2STR(CTX.CONC_CTX.GLOBAL_REQUESTED)
33311,33312c33552,33555
<            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) =  DSC_PREPARE AND  
<            DBMS_STATS_INTERNAL.IS_PARTITIONED_TAB(OWNER, TABNAME) = TRUE AND 
---
>            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) =  
>            DSC_PREPARE AND  
>            DBMS_STATS_INTERNAL.IS_PARTITIONED_TAB(OWNER, TABNAME) = TRUE AND
>              
33315,33316c33558,33560
<           TRACE_TABLE('IM or approx global case: submitting the current batch content: ' ||
<                        CTX.CONC_CTX.JOBSTAB.COUNT);
---
>           TRACE_TABLE(
>              'IM or approx global case: submitting the current batch content: '
>                       || CTX.CONC_CTX.JOBSTAB.COUNT);
33320,33324c33564,33571
<             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, CTX.CONC_CTX.AGENT, 
<                                  CTX.REPORTING_CTX.OP_ID, CTX.REPORTING_CTX.JOB_NAME,
<                                  DSC_STOP_ON_FIRST,
<                                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX,
<                                  FALSE, TRUE, REPORTING_MODE);
---
>             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, 
>                                      CTX.CONC_CTX.AGENT, 
>                                      CTX.REPORTING_CTX.OP_ID, 
>                                      CTX.REPORTING_CTX.JOB_NAME, 
>                                      DSC_STOP_ON_FIRST,
>                                      CTX.CONC_CTX.AGENT <> 
>                                        CTX.CONC_CTX.JOB_NAME_PREFIX,
>                                      FALSE, TRUE, REPORTING_MODE);
33327,33336c33574,33589
<             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, CTX.CONC_CTX.AGENT, 
<                                  CTX.REPORTING_CTX.OP_ID, CTX.REPORTING_CTX.JOB_NAME,
<                                  DSC_STOP_ON_FIRST,
<                                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX,
<                                  FALSE, FALSE, REPORTING_MODE);
<           END IF;
<           TRACE_TABLE('waiting for jobs in construct analyze sql (IM or approx global): ' || 
<                        CTX.CONC_CTX.JOBSTAB.COUNT);
<           MONITORING_MAN_WAIT_FOR_JOBS(CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.CONC_CTX.JSTATS, 
<                                        CTX.CONC_CTX.JOBSTAB, CTX.CONC_CTX.AGENT, NULL,
---
>             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, 
>                                      CTX.CONC_CTX.AGENT, 
>                                      CTX.REPORTING_CTX.OP_ID, 
>                                      CTX.REPORTING_CTX.JOB_NAME,
>                                      DSC_STOP_ON_FIRST,
>                                      CTX.CONC_CTX.AGENT <> 
>                                        CTX.CONC_CTX.JOB_NAME_PREFIX,
>                                      FALSE, FALSE, REPORTING_MODE);
>           END IF;
>           TRACE_TABLE(
>             'waiting for jobs in construct analyze sql (IM or approx global): '
>                       || CTX.CONC_CTX.JOBSTAB.COUNT);
>           MONITORING_MAN_WAIT_FOR_JOBS(CTX.CONC_CTX.JOB_NAME_PREFIX, 
>                                        CTX.CONC_CTX.JSTATS, 
>                                        CTX.CONC_CTX.JOBSTAB, 
>                                        CTX.CONC_CTX.AGENT, NULL,
33338,33340c33591,33596
<           IF(CTX.CONC_CTX.JSTATS.FAILED > 0 OR CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
<             IF CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_CODE IN (-1403, -942, -1031) THEN
<               RAISE_APPLICATION_ERROR(-20009, CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);        
---
>           IF(CTX.CONC_CTX.JSTATS.FAILED > 0 OR 
>              CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
>             IF CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_CODE IN (-1403, -942, -1031)
>               THEN
>               RAISE_APPLICATION_ERROR(-20009, 
>                                       CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);
33342c33598,33599
<               RAISE_APPLICATION_ERROR(-20001, CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);
---
>               RAISE_APPLICATION_ERROR(-20001, 
>                                       CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);
33384,33388c33641,33650
<                          CLIST, ISTART, ISTOP, CSTATS, TSTATS,
<                          SAMPLE = AUTO_SAMPLE_SIZE, INCREMENTAL_PARTLVL) = FALSE)) THEN
<           
<           IF((CTX.CONC_CTX.JOBSTAB.COUNT > 0 OR CTX.BATCHING_CTX.CURRENTBATCHSIZE > 0) 
<              AND (REP_TARGET_TYPE = DSC_TABLE OR REP_TARGET_TYPE = DSC_TABLE_COORD)) THEN
---
>                                               CLIST, ISTART, ISTOP, CSTATS, 
>                                               TSTATS, 
>                                               SAMPLE = AUTO_SAMPLE_SIZE,
>                                               INCREMENTAL_PARTLVL) = 
>                    FALSE)) THEN
>           
>           IF((CTX.CONC_CTX.JOBSTAB.COUNT > 0 OR 
>               CTX.BATCHING_CTX.CURRENTBATCHSIZE > 0) 
>              AND (REP_TARGET_TYPE = DSC_TABLE OR 
>                   REP_TARGET_TYPE = DSC_TABLE_COORD)) THEN
33453c33715,33716
<       IF ((CTX.CONC_CTX.GLOBAL_REQUESTED AND BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE) 
---
>       IF ((CTX.CONC_CTX.GLOBAL_REQUESTED AND 
>            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE) 
33805c34068,34069
<     EXECUTIONPHASE BINARY_INTEGER := CTX.CONC_CTX.EXECUTIONPHASE; 
---
>     EXECUTIONPHASE BINARY_INTEGER := 
>                         CTX.CONC_CTX.EXECUTIONPHASE; 
33852,33854c34116,34119
<     TRACE_TABLE('Started table ' || OWNER || '.' || TABNAMEU || '.' || PARTNAMEU || ' at ' 
<                 || SYSTIMESTAMP ||'. Execution phase: ' || EXEC_PHASE_TO_STR(EXECUTIONPHASE) || 
<                    ' stattype: ' || STATTYPE || ' Reporting Mode: ' || BOOL2STR(REPORTING_MODE));  
---
>     TRACE_TABLE('Started table ' || OWNER || '.' || TABNAMEU || '.' || 
>                 PARTNAMEU || ' at ' || SYSTIMESTAMP ||'. Execution phase: ' || 
>                 EXEC_PHASE_TO_STR(EXECUTIONPHASE) || ' stattype: ' || 
>                 STATTYPE || ' Reporting Mode: ' || BOOL2STR(REPORTING_MODE));  
33877c34142,34143
<       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, OWNER, TABNAMEU);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, OWNER, 
>                                     TABNAMEU);
33881c34147,34148
<       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, OWNER, TABNAMEU);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, OWNER, 
>                                     TABNAMEU);
33886c34153,34154
<       DBMS_STATS_INTERNAL.GET_PREFS('METHOD_OPT', LOC_METHOD_OPT, OWNER, TABNAMEU);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('METHOD_OPT', LOC_METHOD_OPT, OWNER, 
>                                     TABNAMEU);
34032a34301
>       
34130c34399
<     EXECUTESTATJOBS := BITAND(EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE;                         
---
>     EXECUTESTATJOBS := BITAND(EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE;
34209,34211c34478,34481
<             NULL, NULL, STATTAB, STATID, TRANSFER_PART_STATS, TRUE, LOC_CASCADE, FALSE,
<             STATOWN, IOT_TOP_NAME, FALSE, NO_INVALIDATE, FXT_TYP, 'ALL', FALSE,
<             FALSE, OBJ_TRANSFERRED, DEFAULT_STAT_CATEGORY);
---
>                              NULL, NULL, STATTAB, STATID, TRANSFER_PART_STATS, 
>                              TRUE, LOC_CASCADE, FALSE, STATOWN, IOT_TOP_NAME,
>                              FALSE, NO_INVALIDATE, FXT_TYP, 'ALL', FALSE, 
>                              FALSE, OBJ_TRANSFERRED, DEFAULT_STAT_CATEGORY);
34268c34538,34539
<         IF(CTX.CONC_CTX.GLOBAL_REQUESTED IS NULL AND GATHERING_GROUP_STATS) THEN
---
>         IF (CTX.CONC_CTX.GLOBAL_REQUESTED IS NULL AND 
>             GATHERING_GROUP_STATS) THEN
34270c34541,34542
<             DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDX_GRANULARITY, OWNER, TABNAMEU);
---
>             DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDX_GRANULARITY, 
>                                           OWNER, TABNAMEU);
34274c34546,34547
<           CTX.CONC_CTX.GLOBAL_REQUESTED := CHECK_GRANULARITY(INDEXGRAN, 'GLOBAL');         
---
>           CTX.CONC_CTX.GLOBAL_REQUESTED := CHECK_GRANULARITY(INDEXGRAN,
>                                                              'GLOBAL');
34358c34631
<             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = LOC_IND_NAME)) THEN           
---
>             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = LOC_IND_NAME)) THEN
34385c34658
<             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = RECI.IND_NAME)) THEN            
---
>             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = RECI.IND_NAME)) THEN
34447c34720,34721
<       TRACE_TABLE('waiting for all jobs to finish in gather_table_stats_aux: ' || CTX.CONC_CTX.JOBSTAB.COUNT);
---
>       TRACE_TABLE('waiting for all jobs to finish in gather_table_stats_aux: ' 
>                   || CTX.CONC_CTX.JOBSTAB.COUNT);
34452c34726,34727
<       IF(CTX.CONC_CTX.JSTATS.FAILED > 0 OR CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
---
>       IF (CTX.CONC_CTX.JSTATS.FAILED > 0 OR 
>           CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
34460c34735,34738
<         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, LOC_JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
---
>                                                         
>                                                         
>         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, LOC_JOB_NAME_PREFIX, 
>                                  CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
34492c34770,34771
<                 OWNER || '.' || TABNAMEU || '.' || PARTNAMEU || ' at ' || SYSTIMESTAMP);     
---
>                 OWNER || '.' || TABNAMEU || '.' || PARTNAMEU || ' at ' || 
>                 SYSTIMESTAMP);     
34501c34780
<                               DSC_AUTO_STATS_COMPLETED,                          
---
>                               DSC_AUTO_STATS_COMPLETED,
34520a34800
>                                
34525,34526c34805,34807
<       TRACE_ERROR('Exception in gather table stats aux... cleaned: ' || BOOL2STR(CLEANED)
<                    || ' isTopLevel: ' || BOOL2STR(ISTOPLEVEL));           
---
>       TRACE_ERROR('Exception in gather table stats aux... cleaned: ' || 
>                   BOOL2STR(CLEANED) || ' isTopLevel: ' || 
>                   BOOL2STR(ISTOPLEVEL));
34532c34813
<                       CTX.CONC_CTX.JSTATS.STOPPED || ' jobs were stopped.');         
---
>                       CTX.CONC_CTX.JSTATS.STOPPED || ' jobs were stopped.');
34535c34816,34818
<           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
---
>                                
>           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, 
>                                    CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
34537c34820,34821
<           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB, FALSE, FALSE);
---
>           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, 
>                                    CTX.CONC_CTX.JOBSTAB, FALSE, FALSE);
34560,34561c34844,34846
<           ' VIEW "' || OWNER || '"."' || USERSPECDTABNAME || '"' || PARTNAMEU ||
<           ', insufficient privileges or invalid');
---
>                                   ' VIEW "' || OWNER || '"."' || 
>                                   USERSPECDTABNAME || '"' || PARTNAMEU ||
>                                   ', insufficient privileges or invalid');
34682a34968,34980
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
34824c35122,35123
<         TRACE_TABLE('Starting a batch of ' || TASK_COUNT || ' tasks... op id: ' || CTX.REPORTING_CTX.OP_ID);
---
>         TRACE_TABLE('Starting a batch of ' || TASK_COUNT || 
>                     ' tasks... op id: ' || CTX.REPORTING_CTX.OP_ID);
34826c35125,35126
<         TRACE_TABLE('Starting a single task batch... op id: ' || CTX.REPORTING_CTX.OP_ID);
---
>         TRACE_TABLE('Starting a single task batch... op id: ' || 
>                     CTX.REPORTING_CTX.OP_ID);
34856c35156,35157
<         TRACE_TABLE('Processing task ' || ITER || ' of ' || TASK_COUNT || '...');
---
>         TRACE_TABLE('Processing task ' || ITER || ' of ' || TASK_COUNT || 
>                     '...');
34862c35163
<           LOC_START_TIME := TO_DATE(PARAMS(20), 'MM-DD-YYYY HH24:MI:SS');        
---
>           LOC_START_TIME := TO_DATE(PARAMS(20), 'MM-DD-YYYY HH24:MI:SS');
34873,34875c35174,35177
<         TRACE_TABLE(' |-->  ' || PARAMS(2) || '.' || PARAMS(3) || '.' || PARAMS(4) || 
<                     ' > Estimated Cost: ' || CTX.REPORTING_CTX.EST_COST ||
<                     ' Batching Coefficient: ' || CTX.REPORTING_CTX.BATCHING_COEFF);       
---
>         TRACE_TABLE(' |-->  ' || PARAMS(2) || '.' || PARAMS(3) || '.' || 
>                     PARAMS(4) || ' > Estimated Cost: ' || 
>                     CTX.REPORTING_CTX.EST_COST || ' Batching Coefficient: ' || 
>                     CTX.REPORTING_CTX.BATCHING_COEFF);       
34888c35190,35191
<          TRACE_ERROR('Exception while processing task ' || ITER || ': ' || SQLERRM);
---
>          TRACE_ERROR('Exception while processing task ' || ITER || ': ' || 
>                      SQLERRM);
34890c35193,35194
<              (SQLCODE = -20000 AND SQLERRM LIKE '%insufficient privileges%')) THEN
---
>              (SQLCODE = -20000 AND 
>               SQLERRM LIKE '%insufficient privileges%')) THEN
35085c35389,35390
<     TRACE_TABLE('Start gather group stats...*' || OBJLIST.COUNT || ' stattab: ' || STATTAB);  
---
>     TRACE_TABLE('Start gather group stats...*' || OBJLIST.COUNT || 
>                 ' stattab: ' || STATTAB);  
35225,35226c35530,35533
<               TRACE_TABLE('Submit table job: objnameQ: '|| OBJNAMEQ || ' subname: ' || SUB_NAME || 
<                            ' multi-job table: ' || BOOL2STR(BITAND(EXECUTIONPHASE, DSC_PREPARE) = DSC_PREPARE));
---
>               TRACE_TABLE('Submit table job: objnameQ: '|| OBJNAMEQ || 
>                           ' subname: ' || SUB_NAME || ' multi-job table: ' || 
>                           BOOL2STR(BITAND(EXECUTIONPHASE, DSC_PREPARE) = 
>                                    DSC_PREPARE));
35235,35240c35542,35547
<                             FALSE,FXT_TYP, STATTYPE, START_TIME, TRUE, CMS_ONLY,
<                             FORCE, EXECUTIONPHASE, JOB_NAME_PREFIX, JOBSTAB, NULL, FALSE,
<                             JOB_NAME_PREFIX, STAT_CTX.REPORTING_CTX.OP_ID, 
<                             CURRELEM.PRIORITY, CURRELEM.FLAGS, TARGET_SIZE, 
<                             BATCHING_COEFF, FALSE, DSC_TABLE, DSC_ABSORB,
<                             REPORTING_MODE);
---
>                             FALSE,FXT_TYP, STATTYPE, START_TIME, TRUE, 
>                             CMS_ONLY, FORCE, EXECUTIONPHASE, JOB_NAME_PREFIX, 
>                             JOBSTAB, NULL, FALSE, JOB_NAME_PREFIX, 
>                             STAT_CTX.REPORTING_CTX.OP_ID, CURRELEM.PRIORITY, 
>                             CURRELEM.FLAGS, TARGET_SIZE, BATCHING_COEFF, FALSE,
>                             DSC_TABLE, DSC_ABSORB, REPORTING_MODE);
35242c35549,35550
<               JOBPROGRESSMON(STAT_CTX.BATCHING_CTX.BATCHJOBNAME) := PROGRESSREC;
---
>               JOBPROGRESSMON(STAT_CTX.BATCHING_CTX.BATCHJOBNAME) := 
>                                                                    PROGRESSREC;
35246a35555
>                   
35460c35769
<  
---
>   
35656c35965,35966
<       DBMS_STATS_INTERNAL.OPEN_ALL_STALE_OBJS_CUR(OWNNAME,GSYS,GFXT,IGNORE_FLAGS, 
---
>       DBMS_STATS_INTERNAL.OPEN_ALL_STALE_OBJS_CUR(OWNNAME, GSYS, GFXT,
>                                                   IGNORE_FLAGS, 
35666c35976,35977
<         IF (AUTO AND GATHER_FIXED AND IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
---
>         IF (AUTO AND GATHER_FIXED AND 
>             IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
35668,35674c35979,35989
<            'TABLE', RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
<         ELSIF (AUTO AND IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, 'TABLE')) THEN
<           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME,
<            'TABLE', RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
<         ELSE
<           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME,
<            'TABLE', RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
---
>                           'TABLE', RECT.OBJNAME, RECT.PARTNAME, 
>                           RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
>         ELSIF (AUTO AND IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, 
>                                             'TABLE')) THEN
>           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME, 'TABLE', RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_STALE_STATS);
>         ELSE
>           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME, 'TABLE', RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_STALE_STATS);
35692,35693c36007,36009
<       DBMS_STATS_INTERNAL.OPEN_ALL_EMPTY_OBJS_CUR(OWNNAME,GSYS,GTEMP,GFXT,
<                                                   IGNORE_FLAGS,LOC_GRANULARITY,GIND,CUR);
---
>       DBMS_STATS_INTERNAL.OPEN_ALL_EMPTY_OBJS_CUR(OWNNAME, GSYS, GTEMP, GFXT,
>                                                   IGNORE_FLAGS, 
>                                                   LOC_GRANULARITY, GIND, CUR);
35702,35704c36018,36022
<         IF (AUTO AND GATHER_FIXED AND IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
<           ADD_OBJECT_ELEM(OBJLIST_START, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
---
>         IF (AUTO AND GATHER_FIXED AND 
>             IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
>           ADD_OBJECT_ELEM(OBJLIST_START, RECT.OWNNAME, RECT.OBJTYPE, 
>                           RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
35706,35708c36024,36028
<                IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, RECT.OBJTYPE)) THEN
<           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
---
>                IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, 
>                                    RECT.OBJTYPE)) THEN
>           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME, RECT.OBJTYPE, 
>                           RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
35710,35714c36030,36036
<           ADD_OBJECT_ELEM(OBJLIST2, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
<         ELSE
<           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
---
>           ADD_OBJECT_ELEM(OBJLIST2, RECT.OWNNAME, RECT.OBJTYPE, RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
>         ELSE
>           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME, RECT.OBJTYPE, RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
35782c36104,36105
<     TRACE_TABLE('Start gather schema/db stats... owner: ' || OWNER || ' stattab: ' || STATTAB);       
---
>     TRACE_TABLE('Start gather schema/db stats... owner: ' || OWNER || 
>                 ' stattab: ' || STATTAB);
35794c36117,36118
<       JOB_QUEUE_PROCESSES := TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes')); 
---
>       JOB_QUEUE_PROCESSES := 
>        TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes'));
35799c36123,36124
<           JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(DSC_JOB_PREF || 'SD');          
---
>           JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(DSC_JOB_PREF || 
>                                                               'SD');          
36001c36326,36327
<                           GRANULARITY, CASCADE, FORCE, 'DATA', LOC_OBJ_FILTER_LIST);      
---
>                           GRANULARITY, CASCADE, FORCE, 'DATA', 
>                           LOC_OBJ_FILTER_LIST);      
36027c36353,36354
<       TRACE_TABLE('waiting for jobs in gather_schema_or_db_stats_aux: ' || JOBSTAB.COUNT);
---
>       TRACE_TABLE('waiting for jobs in gather_schema_or_db_stats_aux: ' || 
>                   JOBSTAB.COUNT);
36034c36361,36362
<         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || ' jobs were stopped.');
---
>         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || 
>                     ' jobs were stopped.');
36039c36367,36368
<         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, JOBSTAB, TRUE, TRUE);
---
>         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, 
>                                  JOBSTAB, TRUE, TRUE);
36084a36414
>    
36437a36768
>                                  
36522,36529c36853,36859
<     GATHER_SCHEMA_OR_DB_STATS(
<       'Database',
<       NULL,ESTIMATE_PERCENT,BLOCK_SAMPLE,METHOD_OPT,
<       DEGREE,GRANULARITY,CASCADE,STATTAB,STATID,
<       OPTIONSU,TLIST,STATOWN,
<       GATHER_SYS,NO_INVALIDATE,GATHER_TEMP,GATHER_FIXED, STATTYPEU,
<       SYSTIMESTAMP, FALSE, OBJ_FILTER_LIST, COLLECTED_SOFAR, JOBSTAB, TRUE, NULL, 
<       CONCURRENT, OP_ID, REPORTING_MODE);    
---
>     GATHER_SCHEMA_OR_DB_STATS('Database', NULL, ESTIMATE_PERCENT, BLOCK_SAMPLE,
>                               METHOD_OPT, DEGREE, GRANULARITY, CASCADE, 
>                               STATTAB, STATID, OPTIONSU, TLIST, STATOWN,
>                               GATHER_SYS, NO_INVALIDATE, GATHER_TEMP, 
>                               GATHER_FIXED, STATTYPEU, SYSTIMESTAMP, FALSE, 
>                               OBJ_FILTER_LIST, COLLECTED_SOFAR, JOBSTAB, TRUE, 
>                               NULL, CONCURRENT, OP_ID, REPORTING_MODE);    
37091a37422
>                                  
39557a39889
>       
40127,40129c40459,40462
<       TRACE_TABLE('waiting for jobs in gather_dictionary_stats_aux: ' || JOBSTAB.COUNT);
<       MONITORING_MAN_WAIT_FOR_JOBS(JOB_NAME_PREFIX, JSTATS, 
<                                    JOBSTAB, JOB_NAME_PREFIX, 'Dictionary Schema');
---
>       TRACE_TABLE('waiting for jobs in gather_dictionary_stats_aux: ' || 
>                   JOBSTAB.COUNT);
>       MONITORING_MAN_WAIT_FOR_JOBS(JOB_NAME_PREFIX, JSTATS, JOBSTAB, 
>                                    JOB_NAME_PREFIX, 'Dictionary Schema');
40134c40467,40468
<         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || ' jobs were stopped.');
---
>         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || 
>                     ' jobs were stopped.');
40137c40471,40472
<       JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, JOBSTAB, TRUE, TRUE);
---
>       JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, 
>                                JOBSTAB, TRUE, TRUE);
41449a41785
>   
41710c42046,42047
<     DBMS_STATS_INTERNAL.PART_TYPES(OWNER, TABNAMEU, DSC_KGLNTABL, PTYPE, SPTYPE);  
---
>     DBMS_STATS_INTERNAL.PART_TYPES(OWNER, TABNAMEU, DSC_KGLNTABL, PTYPE, 
>                                    SPTYPE);  
43229c43566
<     FOR RECI IN SYS.DBMS_STATS_INTERNAL.ALL_INDEXES(OWNNAME,TABNAME,                                                               NULL,NULL)
---
>     FOR RECI IN SYS.DBMS_STATS_INTERNAL.ALL_INDEXES(OWNNAME,TABNAME,NULL,NULL)
43811c44148
<                                          
---
>                                       
44379,44381c44716,44718
<       DBMS_STATS_INTERNAL.UPDATE_TARGET_LIST(SESID, SESSER, DEFAULT_GRANULARITY, 
<                          NULL, 
<                          TO_STALE_PERCENT_TYPE(GET_PREFS('STALE_PERCENT')));
---
>       DBMS_STATS_INTERNAL.UPDATE_TARGET_LIST(SESID, SESSER, 
>                                              DEFAULT_GRANULARITY, NULL, 
>                             TO_STALE_PERCENT_TYPE(GET_PREFS('STALE_PERCENT')));
44964,44965c45301,45302
<       RAISE_APPLICATION_ERROR (-20001,
<         'Invalid input value: valid values between 1 and 255 or DBMS_STATS.AUTO_TABLE_CACHED_BLOCKS');
---
>       RAISE_APPLICATION_ERROR (-20001, 'Invalid input value: valid values ' ||
>                    'between 1 and 255 or DBMS_STATS.AUTO_TABLE_CACHED_BLOCKS');
45842c46179,46180
<      || '          and SYS_OP_MAP_NONNULL(s.statid) = SYS_OP_MAP_NONNULL(:statidU)';
---
>      || '          and SYS_OP_MAP_NONNULL(s.statid) = '
>      || '              SYS_OP_MAP_NONNULL(:statidU)';
45921a46260
>       
46004a46344
>       
46081a46422
>       
46155a46497
>       
46605a46948
>       
46738a47082
>       
46879a47224
>       
47949,47950c48294,48295
<     LINE_LOC := PAD_CHR(LINE_LOC || END_STR, DSC_EXTN_LEN) || DSC_HEADER_DELIM ||
<                 USAGE || DSC_NEW_LINE;
---
>     LINE_LOC := PAD_CHR(LINE_LOC || END_STR, DSC_EXTN_LEN) || 
>                         DSC_HEADER_DELIM ||USAGE || DSC_NEW_LINE;
48134c48479,48480
<         USED_CNT := REPORT_TAB_COL_USAGE(TREC.USER_NAME, TREC.OBJ_NAME, REPORT);
---
>         USED_CNT := REPORT_TAB_COL_USAGE(TREC.USER_NAME, TREC.OBJ_NAME, 
>                                          REPORT);
48649,48650c48995,48997
<   COMMON_HINTS VARCHAR2(32767)
<   := 'dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring xmlindex_sel_idx_tbl ';
---
>   COMMON_HINTS VARCHAR2(32767) := 'dbms_stats cursor_sharing_exact ' || 
>                                   'use_weak_name_resl dynamic_sampling(0) ' ||
>                                   'no_monitoring xmlindex_sel_idx_tbl ';
SYS.DBMS_STATS - PACKAGE BODY (PSU):
1206,1216c1206,1216
<     SUCCEEDED   INTEGER := 0,          
<     FAILED      INTEGER := 0,          
<     STOPPED     INTEGER := 0,          
<     STARTED     INTEGER := 0,          
<     SCHEDULED   INTEGER := 0,          
<                                        
<                                        
<     LASTJOB   VARCHAR(30),             
<     LASTEVENT SCHEDULER$_EVENT_INFO,   
<     SOFAR_PART  INTEGER := 0,          
<     SOFAR_SUBPART INTEGER := 0         
---
>     SUCCEEDED   INTEGER := 0,         
>     FAILED      INTEGER := 0,         
>     STOPPED     INTEGER := 0,         
>     STARTED     INTEGER := 0,         
>     SCHEDULED   INTEGER := 0,         
>                                       
>                                       
>     LASTJOB   VARCHAR(30),            
>     LASTEVENT SCHEDULER$_EVENT_INFO,  
>     SOFAR_PART  INTEGER := 0,         
>     SOFAR_SUBPART INTEGER := 0        
1219a1220
>   
1243c1244,1245
<     TOP_LEVEL BOOLEAN, 
---
>     TOP_LEVEL BOOLEAN,                          
>                                                 
1773a1776
>   
2233c2236,2238
<   FUNCTION CHECK_GRANULARITY(GRANULARITY VARCHAR2, GRANCHK VARCHAR2) RETURN BOOLEAN;
---
>   FUNCTION CHECK_GRANULARITY(GRANULARITY VARCHAR2, 
>                              GRANCHK VARCHAR2) RETURN BOOLEAN;
>   
2237a2243
> 
2239,2242c2245,2250
<                           JSTATS IN OUT NOCOPY JOBSTATSREC, 
<                           JOBSTAB IN OUT NOCOPY VARCHARTAB, ANAME VARCHAR2, LOPSTR VARCHAR2,
<                           EXCEPTIONPOLICY BINARY_INTEGER DEFAULT DSC_ABSORB,
<                           RETURNPOLICY BINARY_INTEGER DEFAULT DSC_WAIT_FOR_ALL);
---
>                                          JSTATS IN OUT NOCOPY JOBSTATSREC, 
>                                          JOBSTAB IN OUT NOCOPY VARCHARTAB,
>                                          ANAME VARCHAR2, LOPSTR VARCHAR2,
>                              EXCEPTIONPOLICY BINARY_INTEGER DEFAULT DSC_ABSORB,
>                                          RETURNPOLICY BINARY_INTEGER 
>                                             DEFAULT DSC_WAIT_FOR_ALL);
3111c3119,3121
<           TSTATS(I).TAB  || ' . ' || TSTATS(I).PART || ' . ' || TSTATS(I).SPART);
---
>                                        TSTATS(I).TAB  || ' . ' || 
>                                        TSTATS(I).PART || ' . ' || 
>                                        TSTATS(I).SPART);
3122c3132,3134
<           ISTATS(I).IND  || ' . ' || ISTATS(I).PART || ' . ' || ISTATS(I).SPART);
---
>                                        ISTATS(I).IND  || ' . ' || 
>                                        ISTATS(I).PART || ' . ' || 
>                                        ISTATS(I).SPART);
3736c3748,3749
<       RAISE_APPLICATION_ERROR(-20001, 'DBMS_STATS: str2bool: invalid boolean value.');
---
>       RAISE_APPLICATION_ERROR(-20001, 
>                               'DBMS_STATS: str2bool: invalid boolean value.');
4078c4091,4092
<     IF(TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes')) < 4) THEN      
---
>     IF(TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes'))
>        < 4) THEN      
5229c5243,5244
<          JOB_CLASS_NAME           => DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX,       
---
>          JOB_CLASS_NAME           => DSC_STATS_COLLECTION_JOB_CLASS || '_' || 
>                                      SUFFIX,       
5373c5388,5389
<       TRACE_ERROR('exception in monitoring_man_drop_agent: ' || ': ' || SQLERRM );
---
>       TRACE_ERROR('exception in monitoring_man_drop_agent: ' || ': ' ||
>                   SQLERRM );
5398a5415
>     
5421,5423c5438,5441
<         TRACE_ERROR('exception in monitoring_man_subscribe_agent: ' || SQLERRM);
<         RAISE_APPLICATION_ERROR(-20001, 'monitoring_man_subscribe_agent: ' || ANAME || 
<                                           ': ' || SQLERRM );       
---
>         TRACE_ERROR('exception in monitoring_man_subscribe_agent: ' || 
>                     SQLERRM);
>         RAISE_APPLICATION_ERROR(-20001, 'monitoring_man_subscribe_agent: ' || 
>                                         ANAME || ': ' || SQLERRM );       
5449c5467,5468
<   PROCEDURE JOB_MAN_PERFORM_CLEANUPS(FORCE BOOLEAN, DROP_JOB BOOLEAN, SUFFIX VARCHAR2, 
---
>   PROCEDURE JOB_MAN_PERFORM_CLEANUPS(FORCE BOOLEAN, DROP_JOB BOOLEAN, 
>                                      SUFFIX VARCHAR2, 
5458,5459c5477,5479
<     TRACE_TABLE('Perform Cleanups... ' ||  DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX
<                 || ' force: ' || BOOL2STR(FORCE) || ' drop_job: ' || BOOL2STR(DROP_JOB));  
---
>     TRACE_TABLE('Perform Cleanups... ' ||  DSC_STATS_COLLECTION_JOB_CLASS || 
>                 '_' || SUFFIX || ' force: ' || BOOL2STR(FORCE) || 
>                 ' drop_job: ' || BOOL2STR(DROP_JOB));  
5475c5495,5496
<             JOB_NAME         => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX,
---
>             JOB_NAME         => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || 
>                                 '_' || SUFFIX,
5495c5516,5517
<                JOB_CLASS_NAME   => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || '_' || SUFFIX);
---
>                JOB_CLASS_NAME   => 'SYS.' || DSC_STATS_COLLECTION_JOB_CLASS || 
>                                    '_' || SUFFIX);
5498a5521
>                                                     
5559c5582,5583
<       TRACE_ERROR('exception in monitoring_man_process_event: ' || ': ' || SQLERRM);
---
>       TRACE_ERROR('exception in monitoring_man_process_event: ' || ': ' || 
>                   SQLERRM);
5576c5600,5601
<   PROCEDURE GET_JOB_STATS(JOBSTAB IN OUT NOCOPY VARCHARTAB, JSTATS IN OUT NOCOPY JOBSTATSREC) 
---
>   PROCEDURE GET_JOB_STATS(JOBSTAB IN OUT NOCOPY VARCHARTAB, 
>                           JSTATS IN OUT NOCOPY JOBSTATSREC) 
5611a5637
>   
5669a5696,5700
>   
>   
>   
>   
>   
5672c5703,5704
<                           JOBSTAB IN OUT NOCOPY VARCHARTAB, ANAME VARCHAR2, LOPSTR VARCHAR2,
---
>                           JOBSTAB IN OUT NOCOPY VARCHARTAB, ANAME VARCHAR2, 
>                           LOPSTR VARCHAR2,
5674c5706
<                           RETURNPOLICY BINARY_INTEGER DEFAULT DSC_WAIT_FOR_ALL) 
---
>                           RETURNPOLICY BINARY_INTEGER DEFAULT DSC_WAIT_FOR_ALL)
5694,5695c5726,5728
<     TRACE_TABLE(ANAME || ': waiting for jobs in wait_for_jobs...* ' 
<                 || TO_CHAR(JOBSTAB.COUNT - (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED)));      
---
>     TRACE_TABLE(ANAME || ': waiting for jobs in wait_for_jobs...* ' || 
>                 TO_CHAR(JOBSTAB.COUNT - 
>                         (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED)));
5706c5739,5740
<       DEQUEUE_OPTIONS.DEQ_CONDITION := 'tab.user_data.object_name like ''' || JOB_NAME_PREFIX || '%'''; 
---
>       DEQUEUE_OPTIONS.DEQ_CONDITION := 'tab.user_data.object_name like ''' || 
>                                        JOB_NAME_PREFIX || '%'''; 
5709c5743,5744
<     WHILE (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED) < JOBSTAB.COUNT LOOP
---
>     WHILE (JSTATS.SUCCEEDED + JSTATS.FAILED + JSTATS.STOPPED) < 
>           JOBSTAB.COUNT LOOP
5717a5753
>       
5718a5755
>         
5724a5762
>         
5753c5791,5792
<       TRACE_TABLE('  >> process event: ' || MESSAGE.OBJECT_NAME || ' > ' || MESSAGE.EVENT_TYPE || 
---
>       TRACE_TABLE('  >> process event: ' || MESSAGE.OBJECT_NAME || ' > ' || 
>                   MESSAGE.EVENT_TYPE || 
5762c5801,5802
<         TRACE_TABLE(' *** Failure Event: ' || MESSAGE.ERROR_CODE || ': ' || MESSAGE.ERROR_MSG);
---
>         TRACE_TABLE(' *** Failure Event: ' || MESSAGE.ERROR_CODE || ': ' || 
>                     MESSAGE.ERROR_MSG);
5765c5805,5806
<           RAISE_APPLICATION_ERROR(-20000, 'insufficient privileges to analyze an object.');
---
>           RAISE_APPLICATION_ERROR(-20000, 
>                               'insufficient privileges to analyze an object.');
5800c5841,5842
<         DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS(PROGRESSREC.RINDEX, PROGRESSREC.SLNO,
---
>         DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS(PROGRESSREC.RINDEX, 
>                                                   PROGRESSREC.SLNO,
5822c5864,5866
<       TRACE_ERROR(JOB_NAME_PREFIX ||': exception in monitoring_man_wait_for_jobs: ' || ': ' || SQLERRM );      
---
>       TRACE_ERROR(JOB_NAME_PREFIX ||
>                   ': exception in monitoring_man_wait_for_jobs: ' || ': ' || 
>                   SQLERRM );      
6194a6239,6258
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
6284,6289c6348,6355
<        TRACE_ERROR('Exception while creating job ' || JOBNAME || ' for table(s) ' ||
<                    COMMENTS || ' at ' || SYSTIMESTAMP ||                    
<                    ' jobsTab.count: ' || TO_CHAR(JOBSTAB.COUNT) || ': ' || SQLERRM );  
<        RAISE_APPLICATION_ERROR(-20001, 'Exception while creating job ' || JOBNAME || ' for table(s) ' ||
<                    COMMENTS || ' at ' || SYSTIMESTAMP ||                    
<                    ' jobsTab.count: ' || TO_CHAR(JOBSTAB.COUNT) || ': ' || SQLERRM);
---
>        TRACE_ERROR('Exception while creating job ' || JOBNAME || 
>                    ' for table(s) ' || COMMENTS || ' at ' || SYSTIMESTAMP ||
>                    ' jobsTab.count: ' || TO_CHAR(JOBSTAB.COUNT) || ': ' || 
>                    SQLERRM );  
>        RAISE_APPLICATION_ERROR(-20001, 'Exception while creating job ' || 
>                                JOBNAME || ' for table(s) ' || COMMENTS || 
>                                ' at ' || SYSTIMESTAMP || ' jobsTab.count: ' ||
>                                TO_CHAR(JOBSTAB.COUNT) || ': ' || SQLERRM);
6309a6376,6377
>   
>   
7467c7535,7539
<   PROCEDURE URGENT_CLEANUP(JOBSTAB IN OUT NOCOPY VARCHARTAB, JOB_CLASS_SUFFIX VARCHAR2,
---
>   
>   
>   
>   PROCEDURE URGENT_CLEANUP(JOBSTAB IN OUT NOCOPY VARCHARTAB, 
>                            JOB_CLASS_SUFFIX VARCHAR2,
7474c7546,7547
<     CLASS_SUFFIX DBMS_QUOTED_ID := DBMS_ASSERT_SIMPLE_SQL_NAME(JOB_CLASS_SUFFIX);
---
>     CLASS_SUFFIX DBMS_QUOTED_ID := 
>                                  DBMS_ASSERT_SIMPLE_SQL_NAME(JOB_CLASS_SUFFIX);
7492c7565,7566
<                        select owner ||'.' || job_name name from dba_scheduler_jobs  
---
>                        select owner ||'.' || job_name name 
>                        from dba_scheduler_jobs  
7495c7569,7570
<                        select job_class_name name from dba_scheduler_job_classes  
---
>                        select job_class_name name 
>                        from dba_scheduler_job_classes  
7518c7593,7594
<                        dbms_scheduler.stop_job(job_name=>rec.name, force=>true);
---
>                        dbms_scheduler.stop_job(job_name=>rec.name, 
>                                                force=>true);
7535c7611,7612
<                        dbms_scheduler.drop_job(job_name=>rec.name, force=>true);
---
>                        dbms_scheduler.drop_job(job_name=>rec.name, 
>                                                force=>true);
7545c7622,7623
<                      dbms_scheduler.drop_job_class(job_class_name=>rec.name, force=>true);
---
>                      dbms_scheduler.drop_job_class(job_class_name=>rec.name, 
>                                                    force=>true);
7554,7556c7632,7637
<                      subscriber := sys.aq$_agent (rec.name, 'sys.scheduler$_event_queue', null);
<                      dbms_aqadm.remove_subscriber('sys.scheduler$_event_queue', subscriber);   
<                      dbms_aqadm.drop_aq_agent (rec.name);                          
---
>                      subscriber := sys.aq$_agent (rec.name, 
>                                                   'sys.scheduler$_event_queue',
>                                                   null);
>                      dbms_aqadm.remove_subscriber('sys.scheduler$_event_queue',
>                                                   subscriber);   
>                      dbms_aqadm.drop_aq_agent (rec.name);
7582c7663,7664
<    TRACE_TABLE('Created Cleanup Job ' || LOC_JOB_NAME ||  ' at ' || SYSTIMESTAMP);  
---
>    TRACE_TABLE('Created Cleanup Job ' || LOC_JOB_NAME ||  ' at ' || 
>                SYSTIMESTAMP);  
7644a7727
>     
7646c7729
<       RES := MONITORING_MAN_SUBSCRIBE_AGENT(JOB_NAME_PREFIX, USERNAMEU);                
---
>       RES := MONITORING_MAN_SUBSCRIBE_AGENT(JOB_NAME_PREFIX, USERNAMEU);
7652c7735,7736
<         TRACE_ERROR('Silent exception in init_conc: agent subscription has failed');
---
>         TRACE_ERROR(
>                'Silent exception in init_conc: agent subscription has failed');
7706a7791,7793
>   
>   
>   
7749c7836
<         PROP := DBMS_STATS_INTERNAL.GET_TAB_PROPERTY(OWNER, TABNAME);                     
---
>         PROP := DBMS_STATS_INTERNAL.GET_TAB_PROPERTY(OWNER, TABNAME);
7758c7845,7846
<            NOT (BITAND(PROP, 4194304) = 4194304 OR BITAND(PROP, 8388608) = 8388608)           
---
>            NOT (BITAND(PROP, 4194304) = 4194304 OR BITAND(PROP, 8388608) = 
>                 8388608)           
7788c7876,7877
<             LOC_JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(DSC_JOB_PREF || 'T');
---
>             LOC_JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(
>                                                           DSC_JOB_PREF || 'T');
7794c7883
<             IF(IS_NULL(BATCHING_JOB_PREFIX) AND IS_NULL(JOB_NAME_PREFIX)) THEN              
---
>             IF(IS_NULL(BATCHING_JOB_PREFIX) AND IS_NULL(JOB_NAME_PREFIX)) THEN
7797c7886,7887
<                 TRACE_TABLE('Disabling concurrency as initializations have failed');
---
>                 TRACE_TABLE(
>                        'Disabling concurrency as initializations have failed');
7805,7806c7895,7897
<               JOB_MAN_PERFORM_CLEANUPS(TRUE, FALSE, BATCHING_JOB_PREFIX, CONCTX.JOBSTAB, 
<                                        TRUE, TRUE);  
---
>               
>               JOB_MAN_PERFORM_CLEANUPS(TRUE, FALSE, BATCHING_JOB_PREFIX, 
>                                        CONCTX.JOBSTAB, TRUE, TRUE);  
7928c8019,8020
<       (OWNER VARCHAR2, OBJNAMEU IN OUT NOCOPY VARCHAR2, OBJTYPE BINARY_INTEGER) IS
---
>      (OWNER VARCHAR2, OBJNAMEU IN OUT NOCOPY VARCHAR2, OBJTYPE BINARY_INTEGER)
>   IS
8570c8662
<       DBMS_STATS_INTERNAL.PART_TYPES(OWNNAME, OBJNAME, OBJTYPE, PTYPE, SPTYPE);   
---
>       DBMS_STATS_INTERNAL.PART_TYPES(OWNNAME, OBJNAME, OBJTYPE, PTYPE, SPTYPE);
8619a8712,8713
>   
>   
8945c9039,9040
<         STATS_CHECK_PRIVILEGES(OWNER, TREC.OBJ_NAME, DSC_KGLNTABL, FALSE, NULL);
---
>         STATS_CHECK_PRIVILEGES(OWNER, TREC.OBJ_NAME, DSC_KGLNTABL, FALSE, 
>                                NULL);
9112c9207
<                   DBMS_ASSERT.SIMPLE_SQL_NAME(DBMS_STATS_INTERNAL.DQ(COL.PCNAME));
---
>                DBMS_ASSERT.SIMPLE_SQL_NAME(DBMS_STATS_INTERNAL.DQ(COL.PCNAME));
9370,9371c9465,9466
<     CONVERT_FROM_RAW_ICD(DSC_DTYIBFLOAT, RAWVAL, CVAL, DVAL, NVAL, NCVAL, RWVAL,
<                          RESVAL, BDVAL);
---
>     CONVERT_FROM_RAW_ICD(DSC_DTYIBFLOAT, RAWVAL, CVAL, DVAL, NVAL, NCVAL, 
>                          RWVAL, RESVAL, BDVAL);
9386,9387c9481,9482
<     CONVERT_FROM_RAW_ICD(DSC_DTYIBDOUBLE, RAWVAL, CVAL, DVAL, NVAL, NCVAL, RWVAL,
<                          BFVAL, RESVAL);
---
>     CONVERT_FROM_RAW_ICD(DSC_DTYIBDOUBLE, RAWVAL, CVAL, DVAL, NVAL, NCVAL, 
>                          RWVAL, BFVAL, RESVAL);
9621,9622c9716,9717
<       RAISE_APPLICATION_ERROR(-20000, 'Unsupported data type ' || TYP_CODE || ' ' ||
<                                TBL_NAME || ' ' || COL_NAME);
---
>       RAISE_APPLICATION_ERROR(-20000, 'Unsupported data type ' || TYP_CODE || 
>                                       ' ' || TBL_NAME || ' ' || COL_NAME);
10111c10206,10207
<       FOR REC IN DBMS_STATS_INTERNAL.PART_NAME_QRY(TBL_OWNER,TBL_NAME,PART_NAME)
---
>       FOR REC IN DBMS_STATS_INTERNAL.PART_NAME_QRY(TBL_OWNER,TBL_NAME,
>                                                    PART_NAME)
10368c10464,10465
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot store user statistics in external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot store user statistics in external statistics table');
10470c10567,10568
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot get user statistics from external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot get user statistics from external statistics table');
10595c10693,10694
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot store user statistics in external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot store user statistics in external statistics table');
10663c10762,10763
<       RAISE_APPLICATION_ERROR(-20000, 'Cannot get user statistics from external statistics table');
---
>       RAISE_APPLICATION_ERROR(-20000, 
>                   'Cannot get user statistics from external statistics table');
11248,11249c11348,11349
<               RAISE_APPLICATION_ERROR(-20000, 'Could not find anything wrong '||
<                 'with statistics table ' || STATOWNU || '.' || STATTABU ||
---
>               RAISE_APPLICATION_ERROR(-20000, 'Could not find anything '||
>                'wrong with statistics table ' || STATOWNU || '.' || STATTABU ||
13117c13217,13218
<         INT_ASSERT(FALSE,'show_extended_stats_name_aux', 'invalid extn_type', FALSE, 0);
---
>         INT_ASSERT(FALSE,'show_extended_stats_name_aux', 'invalid extn_type', 
>                    FALSE, 0);
13143c13244,13245
<         RAISE_APPLICATION_ERROR(-20001, 'Error when processing extension - ' || 
---
>         RAISE_APPLICATION_ERROR(-20001, 
>                                 'Error when processing extension - ' || 
13174c13276
<             BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
---
>            BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
13186c13288,13289
<       DBMS_STATS_INTERNAL.DUMP_TRACE('Trying to create extension ' || SAFE_EXTN);
---
>       DBMS_STATS_INTERNAL.DUMP_TRACE('Trying to create extension ' || 
>                                      SAFE_EXTN);
13334c13437
<                                  'not supported for an index organized table ');
---
>                                 'not supported for an index organized table ');
13349c13452,13453
<           RAISE_APPLICATION_ERROR(-20001, 'Error when processing extension - ' || 
---
>           RAISE_APPLICATION_ERROR(-20001, 
>                                   'Error when processing extension - ' || 
13410c13514
<             BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
---
>            BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
13455a13560
>       
13492a13598
>   
13649c13755,13756
<                       LASTTABNAME,LASTCOLNAME,LASTPARTNAME,LASTSUBPARTNAME,OWNER;
---
>                       LASTTABNAME,LASTCOLNAME,LASTPARTNAME,LASTSUBPARTNAME,
>                       OWNER;
13939c14046,14047
<         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, PARTNAMEU);
---
>         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, 
>                                                     PARTNAMEU);
14052c14160
<              'Invalid or inconsistent input values in the histogram endpoints');
---
>             'Invalid or inconsistent input values in the histogram endpoints');
14330c14438,14439
<           IF ((ISTATS(I).ALBLK IS NULL) AND (ISTATS(I).NLBLKS IS NOT NULL)) THEN
---
>           IF ((ISTATS(I).ALBLK IS NULL) AND 
>               (ISTATS(I).NLBLKS IS NOT NULL)) THEN
14485c14594,14595
<         OPEN SYS.DBMS_STATS_INTERNAL.GET_IPART_NAME(OWNER, INDNAMEU, PARTNAMEU);
---
>         OPEN SYS.DBMS_STATS_INTERNAL.GET_IPART_NAME(OWNER, INDNAMEU, 
>                                                     PARTNAMEU);
15244c15354,15355
<         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, PARTNAMEU);
---
>         OPEN SYS.DBMS_STATS_INTERNAL.GET_TPART_NAME(OWNER, TABNAMEU, 
>                                                     PARTNAMEU);
15891c16002,16003
<         OBJ_TRANSFERRED IN OUT BOOLEAN, 
---
>         OBJ_TRANSFERRED IN OUT BOOLEAN,               
>                                                       
16084c16196,16197
<         OBJ_TRANSFERRED IN OUT BOOLEAN, 
---
>         OBJ_TRANSFERRED IN OUT BOOLEAN,               
>                                                       
16237c16350,16351
<       IF ((DELETEST = FALSE) AND (FROMTABU IS NULL) AND TOTABU IS NOT NULL) THEN
---
>       IF ((DELETEST = FALSE) AND (FROMTABU IS NULL) AND 
>           TOTABU IS NOT NULL) THEN
16337c16451,16452
<             TOBJN := DBMS_STATS_INTERNAL.GET_OBJNUM(TSTATS(I).OWN, TSTATS(I).TAB, 
---
>             TOBJN := DBMS_STATS_INTERNAL.GET_OBJNUM(TSTATS(I).OWN, 
>                                                     TSTATS(I).TAB, 
16767,16768c16882,16883
<         STATOWN, 'Schema', NO_INVALIDATE, FALSE, STATTYPE, FORCE, OBJ_TRANSFERRED,
<         FALSE, STAT_CATEGORY);
---
>         STATOWN, 'Schema', NO_INVALIDATE, FALSE, STATTYPE, FORCE, 
>         OBJ_TRANSFERRED, FALSE, STAT_CATEGORY);
16782,16783c16897,16898
<       STATOWN, 'Database', NO_INVALIDATE, FALSE, STATTYPE, FORCE, OBJ_TRANSFERRED,
<       TRUE, STAT_CATEGORY);
---
>       STATOWN, 'Database', NO_INVALIDATE, FALSE, STATTYPE, FORCE, 
>       OBJ_TRANSFERRED, TRUE, STAT_CATEGORY);
17059c17174,17175
<         RAISE_APPLICATION_ERROR (-20001, 'Invalid or inconsistent input values');
---
>         RAISE_APPLICATION_ERROR (-20001, 
>                                  'Invalid or inconsistent input values');
17734,17735c17850,17851
<       TXT := 'select statid,type,version,flags,c1,c2,c3,c4,n1,n2,n3,n4,n5,n6,' ||
<           'n7,n8,n9,d1,r1,r2 from ' || DBMS_STATS_INTERNAL.DQ(OWNER) ||
---
>       TXT := 'select statid,type,version,flags,c1,c2,c3,c4,n1,n2,n3,n4,n5,' ||
>           'n6,n7,n8,n9,d1,r1,r2 from ' || DBMS_STATS_INTERNAL.DQ(OWNER) ||
18901a19018
>                                      
18903c19020,19021
<     LOCAL_BKTNUM INTEGER;     
---
>                                      
>     LOCAL_BKTNUM INTEGER; 
19314a19433
>                 
19316c19435,19436
<                     BITAND(CLIST(CIND).HGATH, DSC_CREC_EP+DSC_CREC_RP) = 0) THEN
---
>                     BITAND(CLIST(CIND).HGATH, DSC_CREC_EP+DSC_CREC_RP) = 
>                     0) THEN
19522,19523c19642,19643
<          'invalid column name or duplicate columns/column groups/expressions' ||
<          ' in method_opt');
---
>         'invalid column name or duplicate columns/column groups/expressions' ||
>         ' in method_opt');
19622c19742
<             BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
---
>            BITAND (DBMS_STATS_INTERNAL.TRACE_LEVEL, DSC_COL_TRC) = DSC_COL_TRC;
20395a20516
>   
22123a22245,22328
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>   FUNCTION GET_ROW_COUNT_ESTIMATE (
>         OWNNAME VARCHAR2,                 
>         TABNAME VARCHAR2,                 
>         PARTNAME VARCHAR2,                
>         NBLKS INTEGER,
>         DEGREE INTEGER
>         ) RETURN NUMBER IS
>     ROW_COUNT    NUMBER;
>     OWNER        VARCHAR2(30);
>     TABNAMEU     VARCHAR2(30);
>     PARTNAMEU    VARCHAR2(30);
>     FOBJN        NUMBER;
>     PNAME        VARCHAR2(30);
>     SPNAME       VARCHAR2(30);
>     SEED         INTEGER;
>     NO_ITERATION BOOLEAN;
>     PARTTYPE     NUMBER;
>   BEGIN
>     FILL_IN_SCHEMA(OWNNAME, OWNER);
>     UPCASE(TABNAME, TABNAMEU);
>     UPCASE(PARTNAME, PARTNAMEU);
>     STATS_CHECK_PRIVILEGES(OWNER, TABNAMEU, DSC_KGLNTABL, FALSE, NULL);
> 
>     IF (PARTNAMEU IS NOT NULL) THEN
>       
>       VALIDATE_PART(OWNER, TABNAMEU, PARTNAMEU, DSC_KGLTTABL, NULL);
> 
>       
>       FOBJN := DBMS_STATS_INTERNAL.GET_OBJNUM(OWNER, TABNAMEU, PARTNAMEU, NULL,
>                                               'TABLE');
> 
>       
>       IF (PARTTYPE = 5 ) THEN
>         SPNAME := PARTNAMEU;
>       ELSE
>         PNAME := PARTNAMEU;
>       END IF;
>     END IF;
> 
>     GET_EVENT_LEVEL(DSC_SAMPLE_SEED_EVENT, SEED);
> 
>     IF (DBMS_STATS_INTERNAL.GET_FXT_TYP(OWNER, TABNAME) = DSC_NON_FXT) THEN
>       NO_ITERATION := FALSE;
>     ELSE
>       NO_ITERATION := TRUE;
>     END IF;    
> 
>     QUICK_ESTIMATE_ROWCNT(OWNER,
>                           TABNAMEU,
>                           PNAME,
>                           SPNAME,
>                           FOBJN,
>                           ROW_COUNT,
>                           SEED,
>                           NBLKS,
>                           DEGREE,
>                           NO_ITERATION);
>     RETURN ROW_COUNT;
>   END GET_ROW_COUNT_ESTIMATE;
> 
> 
22219c22424
<         CLIST IN OUT NOCOPY CTAB,                     
---
>         CLIST IN OUT NOCOPY CTAB,       
22389c22594
<         CLIST IN OUT NOCOPY CTAB,              
---
>         CLIST IN OUT NOCOPY CTAB,       
23402a23608
>             
23692a23899
>                                         
24197,24199c24404,24406
<                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || PART.PNAME
<                     || ' set to ' || CSTATS(1).DIST || ' (ndv of ' || COLUMN_NAME
<                     || ')');
---
>                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || 
>                               PART.PNAME || ' set to ' || CSTATS(1).DIST ||
>                               ' (ndv of ' || COLUMN_NAME || ')');
24201,24203c24408,24410
<                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || SPART.SPNAME
<                     || ' set to ' || CSTATS(1).DIST || ' (ndv of ' || COLUMN_NAME
<                     || ')');
---
>                   TRACE_INDEX('ndk of index ' || INDNAME || ' on ' || 
>                               SPART.SPNAME || ' set to ' || CSTATS(1).DIST ||
>                               ' (ndv of ' || COLUMN_NAME || ')');
24222c24429,24430
<       IF (COLLECT_NDK AND TSTATS_UPTODATE AND SAMPLE_PCT < DSC_SAMPLE_MAXPCT AND
---
>       IF (COLLECT_NDK AND TSTATS_UPTODATE AND 
>           SAMPLE_PCT < DSC_SAMPLE_MAXPCT AND
25226c25434,25435
<             RESTORE_INDEX_STATS_AUX(DBMS_STATS_INTERNAL.DQ(LOPINFO(SOFAR).NAME2),
---
>             RESTORE_INDEX_STATS_AUX(DBMS_STATS_INTERNAL.DQ(
>                                                          LOPINFO(SOFAR).NAME2),
25355c25564,25565
<       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, NULL, NULL, IDX.TOBJN);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, NULL, NULL, 
>                                     IDX.TOBJN);
25360c25570,25571
<       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, NULL, NULL, IDX.TOBJN);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, NULL, 
>                                     NULL, IDX.TOBJN);
25364c25575,25576
<       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDXGRAN, NULL, NULL, IDX.TOBJN);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDXGRAN, NULL, NULL, 
>                                     IDX.TOBJN);
25556c25768,25769
<                       (BITAND(DBMS_SQLDIAG.GET_FIX_CONTROL(8917507), 2) = 2) AND
---
>                       (BITAND(DBMS_SQLDIAG.GET_FIX_CONTROL(8917507), 2) = 
>                        2) AND
25581,25582c25794,25797
<           TRACE_INDEX('last: ' || TO_CHAR(SPART.LAST_ANALYZED, 'MM-DD-YYYY HH24:MI:SS') || 
<                       ' start_time: ' || TO_CHAR(START_TIME, 'MM-DD-YYYY HH24:MI:SS'));
---
>           TRACE_INDEX('last: ' || TO_CHAR(SPART.LAST_ANALYZED, 
>                                           'MM-DD-YYYY HH24:MI:SS') || 
>                       ' start_time: ' || TO_CHAR(START_TIME, 
>                                                  'MM-DD-YYYY HH24:MI:SS'));
26284c26499,26500
<         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = DSC_CREC_MINMAX) AND
---
>         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = 
>              DSC_CREC_MINMAX) AND
26356c26572,26573
<         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = DSC_CREC_MINMAX) AND
---
>         IF ((BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_MINMAX) = 
>              DSC_CREC_MINMAX) AND
27007c27224,27225
<         TRACE_SCALING('  Caught an unusable-index error.  giving up combo-ndv scaling');
---
>         TRACE_SCALING(
>              '  Caught an unusable-index error.  giving up combo-ndv scaling');
27095,27096c27313,27315
<         TRACE_HIST('Switching to frequency histogram, ssize = ' || SSIZE || ', popcnt = ' 
<                   || POPCNT || ', ssizesq = ' || SSIZESQ || ', popcntsq = ' || POPCNTSQ);
---
>         TRACE_HIST('Switching to frequency histogram, ssize = ' || SSIZE || 
>                    ', popcnt = ' || POPCNT || ', ssizesq = ' || SSIZESQ || 
>                    ', popcntsq = ' || POPCNTSQ);
27332,27333c27551,27553
<     EVALUATE_HEIGHT_HIST(CSR, CHT, DONE_HIST, PCT, POPCNT, POPCNTSQ, SSIZE, SSIZESQ,
<                          MIN_SSIZE, APPR_NDV, TRUE, INCREMENTAL);   
---
>     
>     EVALUATE_HEIGHT_HIST(CSR, CHT, DONE_HIST, PCT, POPCNT, POPCNTSQ, SSIZE, 
>                          SSIZESQ, MIN_SSIZE, APPR_NDV, TRUE, INCREMENTAL);   
27363c27583,27584
<                           POPCNT, POPCNTSQ, PCT, DONE_HIST, CSR.SLSV, APPR_NDV);
---
>                                                 POPCNT, POPCNTSQ, PCT,
>                                                 DONE_HIST, CSR.SLSV, APPR_NDV);
27613,27614c27834,27836
<             CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, LOC_PPREDTXT,
<                                        PRETXT, POSTTXT, MATERIALIZE);
---
>             CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, 
>                                        LOC_PPREDTXT, PRETXT, POSTTXT, 
>                                        MATERIALIZE);
27633,27634c27855,27857
<               CONSTRUCT_SELECT_HEIGHT(CLIST(LOOPVAR), MNB, LOC_HINTTXT, LOC_PPREDTXT,
<                                     PRETXT, POSTTXT, MATERIALIZE);
---
>               CONSTRUCT_SELECT_HEIGHT(CLIST(LOOPVAR), MNB, LOC_HINTTXT, 
>                                       LOC_PPREDTXT, PRETXT, POSTTXT, 
>                                       MATERIALIZE);
27651,27652c27874,27876
<               CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, LOC_PPREDTXT,
<                                          PRETXT, POSTTXT, MATERIALIZE);
---
>               CONSTRUCT_SELECT_FREQUENCY(CLIST(LOOPVAR), LOC_HINTTXT, 
>                                          LOC_PPREDTXT, PRETXT, POSTTXT,
>                                          MATERIALIZE);
27989c28213
<           IF (BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_AVG) = DSC_CREC_AVG) THEN            
---
>           IF (BITAND(CLIST(LOOPVAR).GATHER,DSC_CREC_AVG) = DSC_CREC_AVG) THEN
28103,28106c28327,28330
<               TRACE_SCALING(' Need larger sample: sndv = ' || CLIST(LOOPVAR).SNDV
<                             || ', snnvdv = ' || CLIST(LOOPVAR).SNNVDV
<                             || ', nnv = ' || NNV
<                             || ', ndv = ' || CLIST(LOOPVAR).NDV);
---
>               TRACE_SCALING(' Need larger sample: sndv = ' || 
>                             CLIST(LOOPVAR).SNDV || ', snnvdv = ' || 
>                             CLIST(LOOPVAR).SNNVDV || ', nnv = ' || NNV || 
>                             ', ndv = ' || CLIST(LOOPVAR).NDV);
28271c28495,28496
<               IF DBMS_STATS_INTERNAL.COLHASHISTOGRAM(TOBJN, CLIST(LOOPVAR).ICOL) THEN
---
>               IF DBMS_STATS_INTERNAL.COLHASHISTOGRAM(TOBJN, 
>                                                      CLIST(LOOPVAR).ICOL) THEN
28273c28498,28499
<                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, DSC_CREC_HIST);
---
>                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, 
>                                               DSC_CREC_HIST);
28279c28505,28506
<                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, DSC_CREC_HIST);
---
>                 CLIST(LOOPVAR).HGATH := BITOR(CLIST(LOOPVAR).HGATH, 
>                                               DSC_CREC_HIST);
29657c29884
<         IF (BITAND(SEL.GATHFLG, DSC_SELREC_RES) = DSC_SELREC_RES) THEN             
---
>         IF (BITAND(SEL.GATHFLG, DSC_SELREC_RES) = DSC_SELREC_RES) THEN
30603c30830
<                 'Unable to incrementally maintain, tablespace SYSAUX is offline');
---
>              'Unable to incrementally maintain, tablespace SYSAUX is offline');
30716a30944
>   
31081c31309
<     NEW_HIST_PCT BOOLEAN := FALSE;   
---
>     NEW_HIST_PCT BOOLEAN := FALSE;  
31226,31231c31454,31461
<                  OWNER, TABNAME, PNAME, SPNAME,  PCT, CTX.CONC_CTX.BLOCK_SAMPLE, 
<                  CTX.CONC_CTX.METHOD_OPT, DEGREE, LOC_GRANULARITY, CTX.CONC_CTX.GIDXGRAN, 
<                  CTX.CONC_CTX.CASCADE, NULL, NULL, NULL, CTX.CONC_CTX.NO_INVALIDATE,
<                  CTX.CONC_CTX.FLUSH_COLU, FXT_TYP, CTX.CONC_CTX.STATTYPE, CTX.CONC_CTX.START_TIME, 
<                  CTX.CONC_CTX.GATHERING_GROUP_STATS, CTX.CONC_CTX.CMS_ONLY, CTX.CONC_CTX.FORCE, 
<                  DSC_EXECUTE, CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB,
---
>                  OWNER, TABNAME, PNAME, SPNAME,  PCT, 
>                  CTX.CONC_CTX.BLOCK_SAMPLE, CTX.CONC_CTX.METHOD_OPT, DEGREE, 
>                  LOC_GRANULARITY, CTX.CONC_CTX.GIDXGRAN, CTX.CONC_CTX.CASCADE, 
>                  NULL, NULL, NULL, CTX.CONC_CTX.NO_INVALIDATE, 
>                  CTX.CONC_CTX.FLUSH_COLU, FXT_TYP, CTX.CONC_CTX.STATTYPE, 
>                  CTX.CONC_CTX.START_TIME, CTX.CONC_CTX.GATHERING_GROUP_STATS, 
>                  CTX.CONC_CTX.CMS_ONLY, CTX.CONC_CTX.FORCE, DSC_EXECUTE, 
>                  CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB,
31234,31237c31464,31468
<                  CTX.REPORTING_CTX.PRIORITY, CTX.REPORTING_CTX.FLAGS, TARGET_SIZE, 
<                  BATCHING_COEFF, 
<                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.REPORTING_CTX.TARGET_TYPE,
<                  DSC_STOP_ON_FIRST, REPORTING_MODE);
---
>                  CTX.REPORTING_CTX.PRIORITY, CTX.REPORTING_CTX.FLAGS, 
>                  TARGET_SIZE, BATCHING_COEFF, 
>                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX, 
>                  CTX.REPORTING_CTX.TARGET_TYPE, DSC_STOP_ON_FIRST, 
>                  REPORTING_MODE);
31675c31906,31907
<             NEW_PCT := GET_NEW_PCT_FOR_APPR_NDV(CURR_PCT, CLIST, ISTART, ISTOP);
---
>             NEW_PCT := GET_NEW_PCT_FOR_APPR_NDV(CURR_PCT, CLIST, ISTART, 
>                                                 ISTOP);
31908c32140,32141
<             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTABP, NULL);
---
>             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTABP, 
>                                                         NULL);
31911c32144,32145
<             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTASP, NULL);
---
>             SYS.DBMS_STATS_INTERNAL.GET_PARTN_LOCK_FLAG(FOBJN, DSC_KGLTTASP, 
>                                                         NULL);
32116c32350,32351
<       FOR RECP IN SYS.DBMS_STATS_INTERNAL.TSPART_CUR_ORDERED(OWNER,TABNAME,PNAME) 
---
>       FOR RECP IN SYS.DBMS_STATS_INTERNAL.TSPART_CUR_ORDERED(OWNER,TABNAME,
>                                                              PNAME) 
32259c32494
<                                DSC_ACTION_GATHER, NULL, SCSFLAGS);                  
---
>                                DSC_ACTION_GATHER, NULL, SCSFLAGS);
32269c32504,32505
<            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) = DSC_PREPARE)) THEN 
---
>            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) = 
>            DSC_PREPARE)) THEN 
32275c32511,32512
<       TRACE_ERROR('gather_subpart [executeStatJobs: '|| BOOL2STR(CTX.CONC_CTX.EXECUTESTATJOBS) || ']');      
---
>       TRACE_ERROR('gather_subpart [executeStatJobs: '|| 
>                   BOOL2STR(CTX.CONC_CTX.EXECUTESTATJOBS) || ']');      
32651c32888
<           JOBPROGRESSMON(CTX.CONC_CTX.LAST_JOB_NAME) := LOPINFO(SOFAR);                   
---
>           JOBPROGRESSMON(CTX.CONC_CTX.LAST_JOB_NAME) := LOPINFO(SOFAR);
32835a33073
>                                     
32858,32859c33096,33099
<     CTX.CONC_CTX.EXECUTESTATJOBS := BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE 
<                               OR BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_SEQ) = DSC_SEQ;
---
>     CTX.CONC_CTX.EXECUTESTATJOBS := BITAND(CTX.CONC_CTX.EXECUTIONPHASE, 
>                                            DSC_EXECUTE) = DSC_EXECUTE OR
>                                     BITAND(CTX.CONC_CTX.EXECUTIONPHASE, 
>                                            DSC_SEQ) = DSC_SEQ;
32864c33104,33105
<                           || ' global_requested: ' || BOOL2STR(CTX.CONC_CTX.GLOBAL_REQUESTED)
---
>                           || ' global_requested: ' 
>                           || BOOL2STR(CTX.CONC_CTX.GLOBAL_REQUESTED)
33044,33045c33285,33288
<            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) =  DSC_PREPARE AND  
<            DBMS_STATS_INTERNAL.IS_PARTITIONED_TAB(OWNER, TABNAME) = TRUE AND 
---
>            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_PREPARE) =  
>            DSC_PREPARE AND  
>            DBMS_STATS_INTERNAL.IS_PARTITIONED_TAB(OWNER, TABNAME) = TRUE AND
>              
33048,33049c33291,33293
<           TRACE_TABLE('IM or approx global case: submitting the current batch content: ' ||
<                        CTX.CONC_CTX.JOBSTAB.COUNT);
---
>           TRACE_TABLE(
>              'IM or approx global case: submitting the current batch content: '
>                       || CTX.CONC_CTX.JOBSTAB.COUNT);
33053,33057c33297,33304
<             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, CTX.CONC_CTX.AGENT, 
<                                  CTX.REPORTING_CTX.OP_ID, CTX.REPORTING_CTX.JOB_NAME,
<                                  DSC_STOP_ON_FIRST,
<                                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX,
<                                  FALSE, TRUE, REPORTING_MODE);
---
>             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, 
>                                      CTX.CONC_CTX.AGENT, 
>                                      CTX.REPORTING_CTX.OP_ID, 
>                                      CTX.REPORTING_CTX.JOB_NAME, 
>                                      DSC_STOP_ON_FIRST,
>                                      CTX.CONC_CTX.AGENT <> 
>                                        CTX.CONC_CTX.JOB_NAME_PREFIX,
>                                      FALSE, TRUE, REPORTING_MODE);
33060,33069c33307,33322
<             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, CTX.CONC_CTX.AGENT, 
<                                  CTX.REPORTING_CTX.OP_ID, CTX.REPORTING_CTX.JOB_NAME,
<                                  DSC_STOP_ON_FIRST,
<                                  CTX.CONC_CTX.AGENT <> CTX.CONC_CTX.JOB_NAME_PREFIX,
<                                  FALSE, FALSE, REPORTING_MODE);
<           END IF;
<           TRACE_TABLE('waiting for jobs in construct analyze sql (IM or approx global): ' || 
<                        CTX.CONC_CTX.JOBSTAB.COUNT);
<           MONITORING_MAN_WAIT_FOR_JOBS(CTX.CONC_CTX.JOB_NAME_PREFIX, CTX.CONC_CTX.JSTATS, 
<                                        CTX.CONC_CTX.JOBSTAB, CTX.CONC_CTX.AGENT, NULL,
---
>             JOB_MAN_SUBMIT_JOB_BATCH(CTX.BATCHING_CTX, CTX.CONC_CTX.JOBSTAB, 
>                                      CTX.CONC_CTX.AGENT, 
>                                      CTX.REPORTING_CTX.OP_ID, 
>                                      CTX.REPORTING_CTX.JOB_NAME,
>                                      DSC_STOP_ON_FIRST,
>                                      CTX.CONC_CTX.AGENT <> 
>                                        CTX.CONC_CTX.JOB_NAME_PREFIX,
>                                      FALSE, FALSE, REPORTING_MODE);
>           END IF;
>           TRACE_TABLE(
>             'waiting for jobs in construct analyze sql (IM or approx global): '
>                       || CTX.CONC_CTX.JOBSTAB.COUNT);
>           MONITORING_MAN_WAIT_FOR_JOBS(CTX.CONC_CTX.JOB_NAME_PREFIX, 
>                                        CTX.CONC_CTX.JSTATS, 
>                                        CTX.CONC_CTX.JOBSTAB, 
>                                        CTX.CONC_CTX.AGENT, NULL,
33071,33073c33324,33329
<           IF(CTX.CONC_CTX.JSTATS.FAILED > 0 OR CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
<             IF CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_CODE IN (-1403, -942, -1031) THEN
<               RAISE_APPLICATION_ERROR(-20009, CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);        
---
>           IF(CTX.CONC_CTX.JSTATS.FAILED > 0 OR 
>              CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
>             IF CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_CODE IN (-1403, -942, -1031)
>               THEN
>               RAISE_APPLICATION_ERROR(-20009, 
>                                       CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);
33075c33331,33332
<               RAISE_APPLICATION_ERROR(-20001, CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);
---
>               RAISE_APPLICATION_ERROR(-20001, 
>                                       CTX.CONC_CTX.JSTATS.LASTEVENT.ERROR_MSG);
33117,33121c33374,33383
<                          CLIST, ISTART, ISTOP, CSTATS, TSTATS,
<                          SAMPLE = AUTO_SAMPLE_SIZE, INCREMENTAL_PARTLVL) = FALSE)) THEN
<           
<           IF((CTX.CONC_CTX.JOBSTAB.COUNT > 0 OR CTX.BATCHING_CTX.CURRENTBATCHSIZE > 0) 
<              AND (REP_TARGET_TYPE = DSC_TABLE OR REP_TARGET_TYPE = DSC_TABLE_COORD)) THEN
---
>                                               CLIST, ISTART, ISTOP, CSTATS, 
>                                               TSTATS, 
>                                               SAMPLE = AUTO_SAMPLE_SIZE,
>                                               INCREMENTAL_PARTLVL) = 
>                    FALSE)) THEN
>           
>           IF((CTX.CONC_CTX.JOBSTAB.COUNT > 0 OR 
>               CTX.BATCHING_CTX.CURRENTBATCHSIZE > 0) 
>              AND (REP_TARGET_TYPE = DSC_TABLE OR 
>                   REP_TARGET_TYPE = DSC_TABLE_COORD)) THEN
33186c33448,33449
<       IF ((CTX.CONC_CTX.GLOBAL_REQUESTED AND BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE) 
---
>       IF ((CTX.CONC_CTX.GLOBAL_REQUESTED AND 
>            BITAND(CTX.CONC_CTX.EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE) 
33538c33801,33802
<     EXECUTIONPHASE BINARY_INTEGER := CTX.CONC_CTX.EXECUTIONPHASE; 
---
>     EXECUTIONPHASE BINARY_INTEGER := 
>                         CTX.CONC_CTX.EXECUTIONPHASE; 
33582,33584c33846,33849
<     TRACE_TABLE('Started table ' || OWNER || '.' || TABNAMEU || '.' || PARTNAMEU || ' at ' 
<                 || SYSTIMESTAMP ||'. Execution phase: ' || EXEC_PHASE_TO_STR(EXECUTIONPHASE) || 
<                    ' stattype: ' || STATTYPE || ' Reporting Mode: ' || BOOL2STR(REPORTING_MODE));  
---
>     TRACE_TABLE('Started table ' || OWNER || '.' || TABNAMEU || '.' || 
>                 PARTNAMEU || ' at ' || SYSTIMESTAMP ||'. Execution phase: ' || 
>                 EXEC_PHASE_TO_STR(EXECUTIONPHASE) || ' stattype: ' || 
>                 STATTYPE || ' Reporting Mode: ' || BOOL2STR(REPORTING_MODE));  
33607c33872,33873
<       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, OWNER, TABNAMEU);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GRANULARITY, OWNER, 
>                                     TABNAMEU);
33611c33877,33878
<       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, OWNER, TABNAMEU);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('ESTIMATE_PERCENT', PVALU, OWNER, 
>                                     TABNAMEU);
33616c33883,33884
<       DBMS_STATS_INTERNAL.GET_PREFS('METHOD_OPT', LOC_METHOD_OPT, OWNER, TABNAMEU);
---
>       DBMS_STATS_INTERNAL.GET_PREFS('METHOD_OPT', LOC_METHOD_OPT, OWNER, 
>                                     TABNAMEU);
33762a34031
>       
33857c34126
<     EXECUTESTATJOBS := BITAND(EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE;                         
---
>     EXECUTESTATJOBS := BITAND(EXECUTIONPHASE, DSC_EXECUTE) = DSC_EXECUTE;
33936,33938c34205,34208
<             NULL, NULL, STATTAB, STATID, TRANSFER_PART_STATS, TRUE, LOC_CASCADE, FALSE,
<             STATOWN, IOT_TOP_NAME, FALSE, NO_INVALIDATE, FXT_TYP, 'ALL', FALSE,
<             FALSE, OBJ_TRANSFERRED, DEFAULT_STAT_CATEGORY);
---
>                              NULL, NULL, STATTAB, STATID, TRANSFER_PART_STATS, 
>                              TRUE, LOC_CASCADE, FALSE, STATOWN, IOT_TOP_NAME,
>                              FALSE, NO_INVALIDATE, FXT_TYP, 'ALL', FALSE, 
>                              FALSE, OBJ_TRANSFERRED, DEFAULT_STAT_CATEGORY);
33989c34259,34260
<         IF(CTX.CONC_CTX.GLOBAL_REQUESTED IS NULL AND GATHERING_GROUP_STATS) THEN
---
>         IF (CTX.CONC_CTX.GLOBAL_REQUESTED IS NULL AND 
>             GATHERING_GROUP_STATS) THEN
33991c34262,34263
<             DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDX_GRANULARITY, OWNER, TABNAMEU);
---
>             DBMS_STATS_INTERNAL.GET_PREFS('GRANULARITY', LOC_GIDX_GRANULARITY, 
>                                           OWNER, TABNAMEU);
33995c34267,34268
<           CTX.CONC_CTX.GLOBAL_REQUESTED := CHECK_GRANULARITY(INDEXGRAN, 'GLOBAL');         
---
>           CTX.CONC_CTX.GLOBAL_REQUESTED := CHECK_GRANULARITY(INDEXGRAN,
>                                                              'GLOBAL');
34079c34352
<             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = LOC_IND_NAME)) THEN           
---
>             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = LOC_IND_NAME)) THEN
34106c34379
<             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = RECI.IND_NAME)) THEN            
---
>             IF ((LOC_CASCADE = TRUE) OR (IOT_TOP_NAME = RECI.IND_NAME)) THEN
34168c34441,34442
<       TRACE_TABLE('waiting for all jobs to finish in gather_table_stats_aux: ' || CTX.CONC_CTX.JOBSTAB.COUNT);
---
>       TRACE_TABLE('waiting for all jobs to finish in gather_table_stats_aux: ' 
>                   || CTX.CONC_CTX.JOBSTAB.COUNT);
34173c34447,34448
<       IF(CTX.CONC_CTX.JSTATS.FAILED > 0 OR CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
---
>       IF (CTX.CONC_CTX.JSTATS.FAILED > 0 OR 
>           CTX.CONC_CTX.JSTATS.STOPPED > 0) THEN
34181c34456,34459
<         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, LOC_JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
---
>                                                         
>                                                         
>         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, LOC_JOB_NAME_PREFIX, 
>                                  CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
34205c34483,34484
<                 OWNER || '.' || TABNAMEU || '.' || PARTNAMEU || ' at ' || SYSTIMESTAMP);     
---
>                 OWNER || '.' || TABNAMEU || '.' || PARTNAMEU || ' at ' || 
>                 SYSTIMESTAMP);     
34214c34493
<                               DSC_AUTO_STATS_COMPLETED,                          
---
>                               DSC_AUTO_STATS_COMPLETED,
34233a34513
>                                
34238,34239c34518,34520
<       TRACE_ERROR('Exception in gather table stats aux... cleaned: ' || BOOL2STR(CLEANED)
<                    || ' isTopLevel: ' || BOOL2STR(ISTOPLEVEL));           
---
>       TRACE_ERROR('Exception in gather table stats aux... cleaned: ' || 
>                   BOOL2STR(CLEANED) || ' isTopLevel: ' || 
>                   BOOL2STR(ISTOPLEVEL));
34245c34526
<                       CTX.CONC_CTX.JSTATS.STOPPED || ' jobs were stopped.');         
---
>                       CTX.CONC_CTX.JSTATS.STOPPED || ' jobs were stopped.');
34248c34529,34531
<           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
---
>                                
>           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, 
>                                    CTX.CONC_CTX.JOBSTAB, TRUE, TRUE);
34250c34533,34534
<           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, CTX.CONC_CTX.JOBSTAB, FALSE, FALSE);
---
>           JOB_MAN_PERFORM_CLEANUPS(TRUE, TRUE, LOC_JOB_NAME_PREFIX, 
>                                    CTX.CONC_CTX.JOBSTAB, FALSE, FALSE);
34273,34274c34557,34559
<           ' VIEW "' || OWNER || '"."' || USERSPECDTABNAME || '"' || PARTNAMEU ||
<           ', insufficient privileges or invalid');
---
>                                   ' VIEW "' || OWNER || '"."' || 
>                                   USERSPECDTABNAME || '"' || PARTNAMEU ||
>                                   ', insufficient privileges or invalid');
34395a34681,34693
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
>    
34537c34835,34836
<         TRACE_TABLE('Starting a batch of ' || TASK_COUNT || ' tasks... op id: ' || CTX.REPORTING_CTX.OP_ID);
---
>         TRACE_TABLE('Starting a batch of ' || TASK_COUNT || 
>                     ' tasks... op id: ' || CTX.REPORTING_CTX.OP_ID);
34539c34838,34839
<         TRACE_TABLE('Starting a single task batch... op id: ' || CTX.REPORTING_CTX.OP_ID);
---
>         TRACE_TABLE('Starting a single task batch... op id: ' || 
>                     CTX.REPORTING_CTX.OP_ID);
34569c34869,34870
<         TRACE_TABLE('Processing task ' || ITER || ' of ' || TASK_COUNT || '...');
---
>         TRACE_TABLE('Processing task ' || ITER || ' of ' || TASK_COUNT || 
>                     '...');
34575c34876
<           LOC_START_TIME := TO_DATE(PARAMS(20), 'MM-DD-YYYY HH24:MI:SS');        
---
>           LOC_START_TIME := TO_DATE(PARAMS(20), 'MM-DD-YYYY HH24:MI:SS');
34586,34588c34887,34890
<         TRACE_TABLE(' |-->  ' || PARAMS(2) || '.' || PARAMS(3) || '.' || PARAMS(4) || 
<                     ' > Estimated Cost: ' || CTX.REPORTING_CTX.EST_COST ||
<                     ' Batching Coefficient: ' || CTX.REPORTING_CTX.BATCHING_COEFF);       
---
>         TRACE_TABLE(' |-->  ' || PARAMS(2) || '.' || PARAMS(3) || '.' || 
>                     PARAMS(4) || ' > Estimated Cost: ' || 
>                     CTX.REPORTING_CTX.EST_COST || ' Batching Coefficient: ' || 
>                     CTX.REPORTING_CTX.BATCHING_COEFF);       
34601c34903,34904
<          TRACE_ERROR('Exception while processing task ' || ITER || ': ' || SQLERRM);
---
>          TRACE_ERROR('Exception while processing task ' || ITER || ': ' || 
>                      SQLERRM);
34603c34906,34907
<              (SQLCODE = -20000 AND SQLERRM LIKE '%insufficient privileges%')) THEN
---
>              (SQLCODE = -20000 AND 
>               SQLERRM LIKE '%insufficient privileges%')) THEN
34798c35102,35103
<     TRACE_TABLE('Start gather group stats...*' || OBJLIST.COUNT || ' stattab: ' || STATTAB);  
---
>     TRACE_TABLE('Start gather group stats...*' || OBJLIST.COUNT || 
>                 ' stattab: ' || STATTAB);  
34938,34939c35243,35246
<               TRACE_TABLE('Submit table job: objnameQ: '|| OBJNAMEQ || ' subname: ' || SUB_NAME || 
<                            ' multi-job table: ' || BOOL2STR(BITAND(EXECUTIONPHASE, DSC_PREPARE) = DSC_PREPARE));
---
>               TRACE_TABLE('Submit table job: objnameQ: '|| OBJNAMEQ || 
>                           ' subname: ' || SUB_NAME || ' multi-job table: ' || 
>                           BOOL2STR(BITAND(EXECUTIONPHASE, DSC_PREPARE) = 
>                                    DSC_PREPARE));
34948,34953c35255,35260
<                             FALSE,FXT_TYP, STATTYPE, START_TIME, TRUE, CMS_ONLY,
<                             FORCE, EXECUTIONPHASE, JOB_NAME_PREFIX, JOBSTAB, NULL, FALSE,
<                             JOB_NAME_PREFIX, STAT_CTX.REPORTING_CTX.OP_ID, 
<                             CURRELEM.PRIORITY, CURRELEM.FLAGS, TARGET_SIZE, 
<                             BATCHING_COEFF, FALSE, DSC_TABLE, DSC_ABSORB,
<                             REPORTING_MODE);
---
>                             FALSE,FXT_TYP, STATTYPE, START_TIME, TRUE, 
>                             CMS_ONLY, FORCE, EXECUTIONPHASE, JOB_NAME_PREFIX, 
>                             JOBSTAB, NULL, FALSE, JOB_NAME_PREFIX, 
>                             STAT_CTX.REPORTING_CTX.OP_ID, CURRELEM.PRIORITY, 
>                             CURRELEM.FLAGS, TARGET_SIZE, BATCHING_COEFF, FALSE,
>                             DSC_TABLE, DSC_ABSORB, REPORTING_MODE);
34955c35262,35263
<               JOBPROGRESSMON(STAT_CTX.BATCHING_CTX.BATCHJOBNAME) := PROGRESSREC;
---
>               JOBPROGRESSMON(STAT_CTX.BATCHING_CTX.BATCHJOBNAME) := 
>                                                                    PROGRESSREC;
34959a35268
>                   
35168c35477
<  
---
>   
35364c35673,35674
<       DBMS_STATS_INTERNAL.OPEN_ALL_STALE_OBJS_CUR(OWNNAME,GSYS,GFXT,IGNORE_FLAGS, 
---
>       DBMS_STATS_INTERNAL.OPEN_ALL_STALE_OBJS_CUR(OWNNAME, GSYS, GFXT,
>                                                   IGNORE_FLAGS, 
35374c35684,35685
<         IF (AUTO AND GATHER_FIXED AND IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
---
>         IF (AUTO AND GATHER_FIXED AND 
>             IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
35376,35382c35687,35697
<            'TABLE', RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
<         ELSIF (AUTO AND IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, 'TABLE')) THEN
<           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME,
<            'TABLE', RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
<         ELSE
<           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME,
<            'TABLE', RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
---
>                           'TABLE', RECT.OBJNAME, RECT.PARTNAME, 
>                           RECT.SUBPARTNAME, DSC_AUTO_FLAGS_STALE_STATS);
>         ELSIF (AUTO AND IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, 
>                                             'TABLE')) THEN
>           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME, 'TABLE', RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_STALE_STATS);
>         ELSE
>           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME, 'TABLE', RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_STALE_STATS);
35400,35401c35715,35717
<       DBMS_STATS_INTERNAL.OPEN_ALL_EMPTY_OBJS_CUR(OWNNAME,GSYS,GTEMP,GFXT,
<                                                   IGNORE_FLAGS,LOC_GRANULARITY,GIND,CUR);
---
>       DBMS_STATS_INTERNAL.OPEN_ALL_EMPTY_OBJS_CUR(OWNNAME, GSYS, GTEMP, GFXT,
>                                                   IGNORE_FLAGS, 
>                                                   LOC_GRANULARITY, GIND, CUR);
35410,35412c35726,35730
<         IF (AUTO AND GATHER_FIXED AND IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
<           ADD_OBJECT_ELEM(OBJLIST_START, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
---
>         IF (AUTO AND GATHER_FIXED AND 
>             IS_CURSOR_FXT(RECT.OWNNAME, RECT.OBJNAME)) THEN
>           ADD_OBJECT_ELEM(OBJLIST_START, RECT.OWNNAME, RECT.OBJTYPE, 
>                           RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
35414,35416c35732,35736
<                IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, RECT.OBJTYPE)) THEN
<           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
---
>                IS_DICOBJ_FOR_STATS(RECT.OWNNAME, RECT.OBJNAME, 
>                                    RECT.OBJTYPE)) THEN
>           ADD_OBJECT_ELEM(OBJLIST_END, RECT.OWNNAME, RECT.OBJTYPE, 
>                           RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
35418,35422c35738,35744
<           ADD_OBJECT_ELEM(OBJLIST2, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
<         ELSE
<           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME,
<             RECT.OBJTYPE, RECT.OBJNAME, RECT.PARTNAME, RECT.SUBPARTNAME, DSC_AUTO_FLAGS_NO_STATS);
---
>           ADD_OBJECT_ELEM(OBJLIST2, RECT.OWNNAME, RECT.OBJTYPE, RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
>         ELSE
>           ADD_OBJECT_ELEM(OBJLIST, RECT.OWNNAME, RECT.OBJTYPE, RECT.OBJNAME, 
>                           RECT.PARTNAME, RECT.SUBPARTNAME, 
>                           DSC_AUTO_FLAGS_NO_STATS);
35490c35812,35813
<     TRACE_TABLE('Start gather schema/db stats... owner: ' || OWNER || ' stattab: ' || STATTAB);       
---
>     TRACE_TABLE('Start gather schema/db stats... owner: ' || OWNER || 
>                 ' stattab: ' || STATTAB);
35502c35825,35826
<       JOB_QUEUE_PROCESSES := TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes')); 
---
>       JOB_QUEUE_PROCESSES := 
>        TO_NUMBER(DBMS_STATS_INTERNAL.GET_PARAMETER_VAL('job_queue_processes'));
35507c35831,35832
<           JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(DSC_JOB_PREF || 'SD');          
---
>           JOB_NAME_PREFIX := DBMS_SCHEDULER.GENERATE_JOB_NAME(DSC_JOB_PREF || 
>                                                               'SD');          
35709c36034,36035
<                           GRANULARITY, CASCADE, FORCE, 'DATA', LOC_OBJ_FILTER_LIST);      
---
>                           GRANULARITY, CASCADE, FORCE, 'DATA', 
>                           LOC_OBJ_FILTER_LIST);      
35735c36061,36062
<       TRACE_TABLE('waiting for jobs in gather_schema_or_db_stats_aux: ' || JOBSTAB.COUNT);
---
>       TRACE_TABLE('waiting for jobs in gather_schema_or_db_stats_aux: ' || 
>                   JOBSTAB.COUNT);
35742c36069,36070
<         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || ' jobs were stopped.');
---
>         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || 
>                     ' jobs were stopped.');
35747c36075,36076
<         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, JOBSTAB, TRUE, TRUE);
---
>         JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, 
>                                  JOBSTAB, TRUE, TRUE);
35792a36122
>    
36145a36476
>                                  
36230,36237c36561,36567
<     GATHER_SCHEMA_OR_DB_STATS(
<       'Database',
<       NULL,ESTIMATE_PERCENT,BLOCK_SAMPLE,METHOD_OPT,
<       DEGREE,GRANULARITY,CASCADE,STATTAB,STATID,
<       OPTIONSU,TLIST,STATOWN,
<       GATHER_SYS,NO_INVALIDATE,GATHER_TEMP,GATHER_FIXED, STATTYPEU,
<       SYSTIMESTAMP, FALSE, OBJ_FILTER_LIST, COLLECTED_SOFAR, JOBSTAB, TRUE, NULL, 
<       CONCURRENT, OP_ID, REPORTING_MODE);    
---
>     GATHER_SCHEMA_OR_DB_STATS('Database', NULL, ESTIMATE_PERCENT, BLOCK_SAMPLE,
>                               METHOD_OPT, DEGREE, GRANULARITY, CASCADE, 
>                               STATTAB, STATID, OPTIONSU, TLIST, STATOWN,
>                               GATHER_SYS, NO_INVALIDATE, GATHER_TEMP, 
>                               GATHER_FIXED, STATTYPEU, SYSTIMESTAMP, FALSE, 
>                               OBJ_FILTER_LIST, COLLECTED_SOFAR, JOBSTAB, TRUE, 
>                               NULL, CONCURRENT, OP_ID, REPORTING_MODE);    
36799a37130
>                                  
39255a39587
>       
39825,39827c40157,40160
<       TRACE_TABLE('waiting for jobs in gather_dictionary_stats_aux: ' || JOBSTAB.COUNT);
<       MONITORING_MAN_WAIT_FOR_JOBS(JOB_NAME_PREFIX, JSTATS, 
<                                    JOBSTAB, JOB_NAME_PREFIX, 'Dictionary Schema');
---
>       TRACE_TABLE('waiting for jobs in gather_dictionary_stats_aux: ' || 
>                   JOBSTAB.COUNT);
>       MONITORING_MAN_WAIT_FOR_JOBS(JOB_NAME_PREFIX, JSTATS, JOBSTAB, 
>                                    JOB_NAME_PREFIX, 'Dictionary Schema');
39832c40165,40166
<         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || ' jobs were stopped.');
---
>         TRACE_TABLE(JSTATS.FAILED || ' jobs failed and ' || JSTATS.STOPPED || 
>                     ' jobs were stopped.');
39835c40169,40170
<       JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, JOBSTAB, TRUE, TRUE);
---
>       JOB_MAN_PERFORM_CLEANUPS(FORCE_DROP, FORCE_DROP, JOB_NAME_PREFIX, 
>                                JOBSTAB, TRUE, TRUE);
41147a41483
>   
41408c41744,41745
<     DBMS_STATS_INTERNAL.PART_TYPES(OWNER, TABNAMEU, DSC_KGLNTABL, PTYPE, SPTYPE);  
---
>     DBMS_STATS_INTERNAL.PART_TYPES(OWNER, TABNAMEU, DSC_KGLNTABL, PTYPE, 
>                                    SPTYPE);  
42927c43264
<     FOR RECI IN SYS.DBMS_STATS_INTERNAL.ALL_INDEXES(OWNNAME,TABNAME,                                                               NULL,NULL)
---
>     FOR RECI IN SYS.DBMS_STATS_INTERNAL.ALL_INDEXES(OWNNAME,TABNAME,NULL,NULL)
43501c43838
<                                          
---
>                                       
44052,44054c44389,44391
<       DBMS_STATS_INTERNAL.UPDATE_TARGET_LIST(SESID, SESSER, DEFAULT_GRANULARITY, 
<                          NULL, 
<                          TO_STALE_PERCENT_TYPE(GET_PREFS('STALE_PERCENT')));
---
>       DBMS_STATS_INTERNAL.UPDATE_TARGET_LIST(SESID, SESSER, 
>                                              DEFAULT_GRANULARITY, NULL, 
>                             TO_STALE_PERCENT_TYPE(GET_PREFS('STALE_PERCENT')));
44637,44638c44974,44975
<       RAISE_APPLICATION_ERROR (-20001,
<         'Invalid input value: valid values between 1 and 255 or DBMS_STATS.AUTO_TABLE_CACHED_BLOCKS');
---
>       RAISE_APPLICATION_ERROR (-20001, 'Invalid input value: valid values ' ||
>                    'between 1 and 255 or DBMS_STATS.AUTO_TABLE_CACHED_BLOCKS');
45456c45793,45794
<      || '          and SYS_OP_MAP_NONNULL(s.statid) = SYS_OP_MAP_NONNULL(:statidU)';
---
>      || '          and SYS_OP_MAP_NONNULL(s.statid) = '
>      || '              SYS_OP_MAP_NONNULL(:statidU)';
45535a45874
>       
45618a45958
>       
45695a46036
>       
45769a46111
>       
46219a46562
>       
46352a46696
>       
46493a46838
>       
47563,47564c47908,47909
<     LINE_LOC := PAD_CHR(LINE_LOC || END_STR, DSC_EXTN_LEN) || DSC_HEADER_DELIM ||
<                 USAGE || DSC_NEW_LINE;
---
>     LINE_LOC := PAD_CHR(LINE_LOC || END_STR, DSC_EXTN_LEN) || 
>                         DSC_HEADER_DELIM ||USAGE || DSC_NEW_LINE;
47748c48093,48094
<         USED_CNT := REPORT_TAB_COL_USAGE(TREC.USER_NAME, TREC.OBJ_NAME, REPORT);
---
>         USED_CNT := REPORT_TAB_COL_USAGE(TREC.USER_NAME, TREC.OBJ_NAME, 
>                                          REPORT);
48263,48264c48609,48611
<   COMMON_HINTS VARCHAR2(32767)
<   := 'dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring xmlindex_sel_idx_tbl ';
---
>   COMMON_HINTS VARCHAR2(32767) := 'dbms_stats cursor_sharing_exact ' || 
>                                   'use_weak_name_resl dynamic_sampling(0) ' ||
>                                   'no_monitoring xmlindex_sel_idx_tbl ';
SYS.SCHEDULER$_JOB_EVENT_HANDLER - PROCEDURE (BP):
47a48
>   DEQUEUE_OPTIONS.WAIT:=2;
284c285,293
< 
---
> EXCEPTION
>   WHEN OTHERS THEN
>     IF DO_TRC THEN
>       SYS.DBMS_ISCHED.TRACE_EMAIL('Failed to send email notification');
>       SYS.DBMS_ISCHED.TRACE_EMAIL(DBMS_UTILITY.FORMAT_CALL_STACK);
>       SYS.DBMS_ISCHED.TRACE_EMAIL(DBMS_UTILITY.FORMAT_ERROR_STACK);
>       SYS.DBMS_ISCHED.TRACE_EMAIL(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
>     END IF;
>     RAISE;
SYS.GV_$BACKUP_DATAFILE - VIEW (PSU):
1c1
< select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","INCREMENTAL_CHANGE#","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","DATAFILE_BLOCKS","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","COMPLETION_TIME","CONTROLFILE_TYPE","USED_CHANGE_TRACKING","BLOCKS_READ","USED_OPTIMIZATION","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","SECTION_SIZE","UNDO_OPTIMIZED","BLOCKS_SKIPPED_IN_CELL","CON_ID","BACKED_BY_PDB" from gv$backup_datafile
---
> select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","INCREMENTAL_CHANGE#","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","DATAFILE_BLOCKS","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","COMPLETION_TIME","CONTROLFILE_TYPE","USED_CHANGE_TRACKING","BLOCKS_READ","USED_OPTIMIZATION","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","SECTION_SIZE","UNDO_OPTIMIZED","BLOCKS_SKIPPED_IN_CELL","CON_ID","BACKED_BY_PDB","GUID" from gv$backup_datafile
SYS.GV_$BACKUP_PIECE - VIEW (PSU):
1c1
< select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","PIECE#","COPY#","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","CONCUR","TAG","STATUS","DELETED","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","BYTES","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","COMPRESSED","BACKED_BY_VSS","ENCRYPTED","BACKED_BY_OSB","FOR_XTTS","SAME_ENDIAN","CON_ID" from gv$backup_piece
---
> select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","PIECE#","COPY#","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","CONCUR","TAG","STATUS","DELETED","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","BYTES","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","COMPRESSED","BACKED_BY_VSS","ENCRYPTED","BACKED_BY_OSB","FOR_XTTS","SAME_ENDIAN","CON_ID","GUID" from gv$backup_piece
SYS.GV_$BACKUP_SET - VIEW (PSU):
1c1
< select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","BACKUP_TYPE","CONTROLFILE_INCLUDED","INCREMENTAL_LEVEL","PIECES","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","BLOCK_SIZE","INPUT_FILE_SCAN_ONLY","KEEP","KEEP_UNTIL","KEEP_OPTIONS","MULTI_SECTION","FOR_XTTS","SAME_ENDIAN","INC_DMPFILE","CON_ID" from gv$backup_set
---
> select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","BACKUP_TYPE","CONTROLFILE_INCLUDED","INCREMENTAL_LEVEL","PIECES","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","BLOCK_SIZE","INPUT_FILE_SCAN_ONLY","KEEP","KEEP_UNTIL","KEEP_OPTIONS","MULTI_SECTION","FOR_XTTS","SAME_ENDIAN","INC_DMPFILE","CON_ID","GUID" from gv$backup_set
SYS.GV_$BACKUP_SPFILE - VIEW (PSU):
1c1
< select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","MODIFICATION_TIME","BYTES","COMPLETION_TIME","DB_UNIQUE_NAME","CON_ID" from gv$backup_spfile
---
> select "INST_ID","RECID","STAMP","SET_STAMP","SET_COUNT","MODIFICATION_TIME","BYTES","COMPLETION_TIME","DB_UNIQUE_NAME","CON_ID","GUID" from gv$backup_spfile
SYS.GV_$DATAFILE_COPY - VIEW (PSU):
1c1
< select "INST_ID","RECID","STAMP","NAME","TAG","FILE#","RFILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","ONLINE_FUZZY","BACKUP_FUZZY","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","DELETED","STATUS","COMPLETION_TIME","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","SCANNED","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","CONVERTED_FILE","SAME_ENDIAN","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","BACKED_BY_VSS","CON_ID","BACKED_BY_PDB" from gv$datafile_copy
---
> select "INST_ID","RECID","STAMP","NAME","TAG","FILE#","RFILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","ONLINE_FUZZY","BACKUP_FUZZY","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","DELETED","STATUS","COMPLETION_TIME","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","SCANNED","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","CONVERTED_FILE","SAME_ENDIAN","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","BACKED_BY_VSS","CON_ID","BACKED_BY_PDB","GUID" from gv$datafile_copy
SYS.GV_$PROXY_DATAFILE - VIEW (PSU):
1c1
< select "INST_ID","RECID","STAMP","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","TAG","STATUS","DELETED","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","INCREMENTAL_LEVEL","ONLINE_FUZZY","BACKUP_FUZZY","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","CON_ID","BACKED_BY_PDB" from gv$proxy_datafile
---
> select "INST_ID","RECID","STAMP","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","TAG","STATUS","DELETED","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","INCREMENTAL_LEVEL","ONLINE_FUZZY","BACKUP_FUZZY","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","CON_ID","BACKED_BY_PDB","GUID" from gv$proxy_datafile
SYS.V_$BACKUP_DATAFILE - VIEW (PSU):
1c1
< select "RECID","STAMP","SET_STAMP","SET_COUNT","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","INCREMENTAL_CHANGE#","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","DATAFILE_BLOCKS","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","COMPLETION_TIME","CONTROLFILE_TYPE","USED_CHANGE_TRACKING","BLOCKS_READ","USED_OPTIMIZATION","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","SECTION_SIZE","UNDO_OPTIMIZED","BLOCKS_SKIPPED_IN_CELL","CON_ID","BACKED_BY_PDB" from v$backup_datafile
---
> select "RECID","STAMP","SET_STAMP","SET_COUNT","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","INCREMENTAL_CHANGE#","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","DATAFILE_BLOCKS","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","COMPLETION_TIME","CONTROLFILE_TYPE","USED_CHANGE_TRACKING","BLOCKS_READ","USED_OPTIMIZATION","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","SECTION_SIZE","UNDO_OPTIMIZED","BLOCKS_SKIPPED_IN_CELL","CON_ID","BACKED_BY_PDB","GUID" from v$backup_datafile
SYS.V_$BACKUP_PIECE - VIEW (PSU):
1c1
< select "RECID","STAMP","SET_STAMP","SET_COUNT","PIECE#","COPY#","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","CONCUR","TAG","STATUS","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","DELETED","BYTES","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","COMPRESSED","BACKED_BY_VSS","ENCRYPTED","BACKED_BY_OSB","FOR_XTTS","SAME_ENDIAN","CON_ID" from v$backup_piece
---
> select "RECID","STAMP","SET_STAMP","SET_COUNT","PIECE#","COPY#","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","CONCUR","TAG","STATUS","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","DELETED","BYTES","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","COMPRESSED","BACKED_BY_VSS","ENCRYPTED","BACKED_BY_OSB","FOR_XTTS","SAME_ENDIAN","CON_ID","GUID" from v$backup_piece
SYS.V_$BACKUP_SET - VIEW (PSU):
1c1
< select "RECID","STAMP","SET_STAMP","SET_COUNT","BACKUP_TYPE","CONTROLFILE_INCLUDED","INCREMENTAL_LEVEL","PIECES","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","BLOCK_SIZE","INPUT_FILE_SCAN_ONLY","KEEP","KEEP_UNTIL","KEEP_OPTIONS","MULTI_SECTION","FOR_XTTS","SAME_ENDIAN","INC_DMPFILE","CON_ID" from v$backup_set
---
> select "RECID","STAMP","SET_STAMP","SET_COUNT","BACKUP_TYPE","CONTROLFILE_INCLUDED","INCREMENTAL_LEVEL","PIECES","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","BLOCK_SIZE","INPUT_FILE_SCAN_ONLY","KEEP","KEEP_UNTIL","KEEP_OPTIONS","MULTI_SECTION","FOR_XTTS","SAME_ENDIAN","INC_DMPFILE","CON_ID","GUID" from v$backup_set
SYS.V_$BACKUP_SPFILE - VIEW (PSU):
1c1
< select "RECID","STAMP","SET_STAMP","SET_COUNT","MODIFICATION_TIME","BYTES","COMPLETION_TIME","DB_UNIQUE_NAME","CON_ID" from v$backup_spfile
---
> select "RECID","STAMP","SET_STAMP","SET_COUNT","MODIFICATION_TIME","BYTES","COMPLETION_TIME","DB_UNIQUE_NAME","CON_ID","GUID" from v$backup_spfile
SYS.V_$DATAFILE_COPY - VIEW (PSU):
1c1
< select "RECID","STAMP","NAME","TAG","FILE#","RFILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","ONLINE_FUZZY","BACKUP_FUZZY","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","DELETED","STATUS","COMPLETION_TIME","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","SCANNED","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","CONVERTED_FILE","SAME_ENDIAN","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","BACKED_BY_VSS","CON_ID","BACKED_BY_PDB" from v$datafile_copy
---
> select "RECID","STAMP","NAME","TAG","FILE#","RFILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","INCREMENTAL_LEVEL","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","ONLINE_FUZZY","BACKUP_FUZZY","MARKED_CORRUPT","MEDIA_CORRUPT","LOGICALLY_CORRUPT","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","DELETED","STATUS","COMPLETION_TIME","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","SCANNED","IS_RECOVERY_DEST_FILE","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","CONVERTED_FILE","SAME_ENDIAN","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","BACKED_BY_VSS","CON_ID","BACKED_BY_PDB","GUID" from v$datafile_copy
SYS.V_$PROXY_DATAFILE - VIEW (PSU):
1c1
< select "RECID","STAMP","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","TAG","STATUS","DELETED","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","INCREMENTAL_LEVEL","ONLINE_FUZZY","BACKUP_FUZZY","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","CON_ID","BACKED_BY_PDB" from v$proxy_datafile
---
> select "RECID","STAMP","DEVICE_TYPE","HANDLE","COMMENTS","MEDIA","MEDIA_POOL","TAG","STATUS","DELETED","FILE#","CREATION_CHANGE#","CREATION_TIME","RESETLOGS_CHANGE#","RESETLOGS_TIME","CHECKPOINT_CHANGE#","CHECKPOINT_TIME","ABSOLUTE_FUZZY_CHANGE#","RECOVERY_FUZZY_CHANGE#","RECOVERY_FUZZY_TIME","INCREMENTAL_LEVEL","ONLINE_FUZZY","BACKUP_FUZZY","BLOCKS","BLOCK_SIZE","OLDEST_OFFLINE_RANGE","START_TIME","COMPLETION_TIME","ELAPSED_SECONDS","CONTROLFILE_TYPE","KEEP","KEEP_UNTIL","KEEP_OPTIONS","RMAN_STATUS_RECID","RMAN_STATUS_STAMP","FOREIGN_DBID","PLUGGED_READONLY","PLUGIN_CHANGE#","PLUGIN_RESETLOGS_CHANGE#","PLUGIN_RESETLOGS_TIME","CON_ID","BACKED_BY_PDB","GUID" from v$proxy_datafile

12.2.0.1

DVSYS.DBMS_MACADM - PACKAGE BODY (RU):
2492a2493,2498
>     
>     
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PATCH%' THEN
>       RETURN 'Y';
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PARAMETER%' THEN
>       RETURN 'Y';
SYS.DBMS_RCVMAN - PACKAGE BODY (RU):
6174c6174
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6380c6380
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6542c6542
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6629c6629
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
7779,7792d7778
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7832c7818,7830
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
7987c7985,7997
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
SYS.DBMS_RCVMAN - PACKAGE BODY (APR2020RUR):
7779,7792d7778
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7832c7818,7830
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
7987c7985,7997
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC

18.0.0.0

DVSYS.DBMS_MACADM - PACKAGE BODY (RU):
2570a2571,2576
>     
>     
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PATCH%' THEN
>       RETURN 'Y';
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PARAMETER%' THEN
>       RETURN 'Y';
MDSYS.SDO_JOIN - FUNCTION (RU):
495,498c495,503
<         FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
---
>         IF ( IPTN1 IS NULL ) THEN
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE);
>         ELSE
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
>         END IF;
506,509c511,519
<         FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
---
>         IF ( IPTN2 IS NULL ) THEN
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE);
>         ELSE
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
>         END IF;
517,520c527,535
<         FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
---
>         IF ( IPTN1 IS NULL ) THEN
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE);
>         ELSE
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
>         END IF;
528,531c543,551
<         FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
---
>         IF ( IPTN2 IS NULL ) THEN
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE);
>         ELSE
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
>         END IF;
SYS.DBMS_BACKUP_RESTORE - PACKAGE (18.9RUR):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '18.09.01.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '18.09.02.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('18.09.01.00', '.');
<   msn  CONSTANT NUMBER := instr('18.09.01.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('18.09.01.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('18.09.02.00', '.');
>   msn  CONSTANT NUMBER := instr('18.09.02.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('18.09.02.00', '.', msn + 1);
29c29
<                            to_number(substr('18.09.01.00', 1, fsn - 1));
---
>                            to_number(substr('18.09.02.00', 1, fsn - 1));
31c31
<                to_number(substr('18.09.01.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('18.09.02.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('18.09.01.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('18.09.02.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('18.09.01.00',  psn + 1));
---
>                              to_number(substr('18.09.02.00',  psn + 1));
SYS.DBMS_BACKUP_RESTORE - PACKAGE (18.10RUR):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '18.10.00.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '18.10.01.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('18.10.00.00', '.');
<   msn  CONSTANT NUMBER := instr('18.10.00.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('18.10.00.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('18.10.01.00', '.');
>   msn  CONSTANT NUMBER := instr('18.10.01.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('18.10.01.00', '.', msn + 1);
29c29
<                            to_number(substr('18.10.00.00', 1, fsn - 1));
---
>                            to_number(substr('18.10.01.00', 1, fsn - 1));
31c31
<                to_number(substr('18.10.00.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('18.10.01.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('18.10.00.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('18.10.01.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('18.10.00.00',  psn + 1));
---
>                              to_number(substr('18.10.01.00',  psn + 1));
SYS.DBMS_BACKUP_RESTORE - PACKAGE (RU):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '18.10.00.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '18.11.00.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('18.10.00.00', '.');
<   msn  CONSTANT NUMBER := instr('18.10.00.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('18.10.00.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('18.11.00.00', '.');
>   msn  CONSTANT NUMBER := instr('18.11.00.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('18.11.00.00', '.', msn + 1);
29c29
<                            to_number(substr('18.10.00.00', 1, fsn - 1));
---
>                            to_number(substr('18.11.00.00', 1, fsn - 1));
31c31
<                to_number(substr('18.10.00.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('18.11.00.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('18.10.00.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('18.11.00.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('18.10.00.00',  psn + 1));
---
>                              to_number(substr('18.11.00.00',  psn + 1));
SYS.DBMS_REGISTRY - PACKAGE (18.9RUR):
13c13
<                                '18.9.1.0.0';
---
>                                '18.9.2.0.0';
SYS.DBMS_REGISTRY - PACKAGE (18.10RUR):
13c13
<                                '18.10.0.0.0';
---
>                                '18.10.1.0.0';
SYS.DBMS_REGISTRY - PACKAGE (RU):
13c13
<                                '18.10.0.0.0';
---
>                                '18.11.0.0.0';
SYS.DBMS_REPORT - PACKAGE (RU):
667c667,672
<   --
---
>   --    p_cloud_service_type
>   --                     (OUT)  - 0 NONE
>   --                              1 DWCS (Autonomous Data Warehouse)
>   --                              2 EECS (Exadata Express Cloud Service)
>   --                              3 PAAS (Platform As A Service (MDBCS))
>   --                              4 OLTP (ATP)
678c683,684
<     p_packs                 OUT      NUMBER
---
>     p_packs                 OUT      NUMBER,
>     p_cloud_service_type    OUT      NUMBER
SYS.DBMS_SQLTUNE_UTIL2 - PACKAGE (RU):
15a16,23
>   -- Cloud Service Type Constants
>   CLOUD_SERVICE_TYPE_NONE    CONSTANT VARCHAR2(30) := 'NONE';
>   CLOUD_SERVICE_TYPE_ADW_D   CONSTANT VARCHAR2(30) := 'ADW-D';
>   CLOUD_SERVICE_TYPE_ADW_S   CONSTANT VARCHAR2(30) := 'ADW-S';
>   CLOUD_SERVICE_TYPE_ATP_D   CONSTANT VARCHAR2(30) := 'ATP-D';
>   CLOUD_SERVICE_TYPE_ATP_S   CONSTANT VARCHAR2(30) := 'ATP-S';
>   CLOUD_SERVICE_TYPE_OTHER   CONSTANT VARCHAR2(30) := 'OTHER';
> 
313a322,381
> 
>   -------------------------- get_cloud_service_type  --------------------------
>   -- NAME:
>   --     get_cloud_service_type
>   --
>   -- DESCRIPTION:
>   --     return value of _cloud_service_type parameter for cloud service type
>   --
>   -- RETURN:
>   --   CLOUD_SERVICE_TYPE_NONE    =>  'NONE';
>   --   CLOUD_SERVICE_TYPE_ADW_D   =>  'ADW-D';
>   --   CLOUD_SERVICE_TYPE_ADW_S   =>  'ADW-S';
>   --   CLOUD_SERVICE_TYPE_ATP_D   =>  'ATP-D';
>   --   CLOUD_SERVICE_TYPE_ATP_S   =>  'ATP-S';
>   --   CLOUD_SERVICE_TYPE_OTHER   =>  'OTHER';
>   -----------------------------------------------------------------------------
>   FUNCTION get_cloud_service_type
>   RETURN varchar2;
> 
>   -------------------------- get_tz_offset  -----------------------------------
>   -- NAME:
>   --     get_tz_offset
>   --
>   -- DESCRIPTION:
>   --     get timezone offset from systimestamp
>   --
>   -- RETURN:
>   --     timezone offset in TZ_HOUR:TZ_MINUTE format
>   -----------------------------------------------------------------------------
>   FUNCTION get_tz_offset
>   RETURN VARCHAR2;
> 
>   ----------------------------- chooseAwrForPdb -------------------------
>   -- NAME:
>   --     chooseAwrForPdb
>   --
>   -- DESCRIPTION:
>   --     This function determines the location/prefix of the AWR view to use
>   --     for the database considering the following conditions:
>   --     1. Check whether local awr_pdb has snapshots.
>   --        If not, return AWR_VIEW_ROOT
>   --     2. If local awr has some snapshots use AWR_VIEW_PDB
>   --     3. If by change local awr was stopped/disabled for some time
>   --         (say for eg., last 3 hrs not local awr snapshots)
>   --         then use AWR_VIEW_ROOT
>   --
>   --
>   -- NOTE: The beginTime and endTime used are in DB Timezone.
>   --       Unlike the case of ASH, no need to convert to UTC,
>   --       since end_interval_time in awr_root, awr_pdb  are in same TZ
>   --
>   -- PARAMETERS:
>   --     dbid            (IN)  - database id
>   --
>   -- RETURN:
>   --     Returned type can be 'AWR_ROOT' or 'AWR_PDB'.
>   --
>   -----------------------------------------------------------------------------
>   FUNCTION chooseAwrForPdb(beginTime IN DATE)
>   RETURN VARCHAR2;
SYS.PRVT_AWR_VIEWER - PACKAGE (RU):
417a418,419
>   
>   
429a432
>     INCLUDE_SQLS      IN NUMBER         DEFAULT NULL,
882a886,904
>   PROCEDURE CREATE_CONSUMER_GROUP_MAP(
>     P_CON_ID     IN     NUMBER,
>     P_AWR_PERIOD IN OUT NOCOPY PRVT_AWRV_METADATA,
>     P_CGRP_MAP   IN OUT NOCOPY PRVT_AWRV_INSTTAB);
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
911a934,1153
>   RETURN XMLTYPE;
> 
>   
>   
>   
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_RMMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME      IN DATE               DEFAULT NULL,
>     END_TIME        IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT 0)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SQL_N_PARSE_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_WAIT_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SYSMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_STORAGE_METRICS_XML(
>     SERVICE_TYPE IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL     IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SESSION_METRICS_XML(
>     SHOW_SQL        IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION REPORT_WORKLOAD(
>     SERVICE_TYPE   IN VARCHAR2 DEFAULT NULL,
>     IS_REALTIME    IN NUMBER   DEFAULT 1,
>     DBID           IN NUMBER   DEFAULT NULL,
>     START_TIME     IN DATE     DEFAULT NULL,
>     END_TIME       IN DATE     DEFAULT NULL,
>     REPORT_LEVEL   IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL       IN NUMBER   DEFAULT 0)
SYS.DBMS_RCVMAN - PACKAGE BODY (18.9RUR):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '18.09.01.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '18.09.02.00'; 
SYS.DBMS_RCVMAN - PACKAGE BODY (RU):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '18.10.00.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '18.11.00.00'; 
6266c6266
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6472c6472
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6634c6634
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6721c6721
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
7871,7884d7870
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7924c7910,7922
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
8079c8077,8089
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
SYS.DBMS_RCVMAN - PACKAGE BODY (18.10RUR):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '18.10.00.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '18.10.01.00'; 
SYS.DBMS_REPORT - PACKAGE BODY (RU):
1055a1056,1060
>   EXCEPTION
>     WHEN OTHERS THEN
>       CONTENT_TYPE := CONTENT_TYPE_XML;
>       RETURN XMLTYPE('<mesg type="oraerr">'|| SQLERRM || 
>                      '</mesg>').GETCLOBVAL();
2011a2017,2021
>   
>   
>   
>   
>   
2021c2031,2032
<     P_PACKS                 OUT      NUMBER
---
>     P_PACKS                 OUT      NUMBER,
>     P_CLOUD_SERVICE_TYPE    OUT      NUMBER
2257a2269,2299
>     
>     IF (V_RESOLVED_DB_TYPE
>         IN (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP)) 
>     THEN
>         SELECT CASE MAX(VALUE)
>                  WHEN 'DWCS' THEN 1
>                  WHEN 'EECS' THEN 2
>                  WHEN 'PAAS' THEN 3
>                  WHEN 'OLTP' THEN 4
>                  ELSE 0
>                END
>           INTO P_CLOUD_SERVICE_TYPE
>           FROM SYS.AWR_PDB_PARAMETER
>          WHERE DBID = P_DBID
>            AND SNAP_ID = V_END_SNAP
>            AND PARAMETER_NAME = '_cloud_service_type';
>     ELSE
>         SELECT CASE MAX(VALUE)
>                  WHEN 'DWCS' THEN 1
>                  WHEN 'EECS' THEN 2
>                  WHEN 'PAAS' THEN 3
>                  WHEN 'OLTP' THEN 4
>                  ELSE 0
>                END
>           INTO P_CLOUD_SERVICE_TYPE
>           FROM SYS.AWR_ROOT_PARAMETER
>          WHERE DBID = P_DBID
>            AND SNAP_ID = V_END_SNAP
>            AND PARAMETER_NAME = '_cloud_service_type';
>     END IF;
>       
SYS.DBMS_SQLTUNE - PACKAGE BODY (RU):
25990a25991,26033
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
> 
>     IF ( (LOCAL_DB = 1) 
>           AND
>          (DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE() IN 
>           (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D))
>           AND 
>          (DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(START_TIME) = 
>                         DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB)
>        )
>     THEN  
>         TARGET_DBID := CON_DBID;
>     END IF;
> 
>     
SYS.DBMS_SQLTUNE_UTIL2 - PACKAGE BODY (RU):
593a594,750
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_CLOUD_SERVICE_TYPE
>   RETURN VARCHAR2
>   IS
>     CLOUD_SERVICE_TYPE VARCHAR2(32);
>   BEGIN
> 
>     SELECT 
>       CASE 
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='PAAS' THEN
>           CASE 
>             WHEN UPPER(MAX(PROPERTY_VALUE)) LIKE '%ADW.ORACLECLOUD.COM' THEN
>               CLOUD_SERVICE_TYPE_ADW_D
>       	    WHEN UPPER(MAX(PROPERTY_VALUE)) LIKE '%ATP.ORACLECLOUD.COM' THEN 
>               CLOUD_SERVICE_TYPE_ATP_D
>       	    ELSE CLOUD_SERVICE_TYPE_OTHER
>           END
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='DWCS' THEN 
>           CLOUD_SERVICE_TYPE_ADW_S
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='OLTP' THEN 
>           CLOUD_SERVICE_TYPE_ATP_S
>         ELSE
>           UPPER(NVL(SYS_CONTEXT('USERENV','CLOUD_SERVICE'), 
>                 CLOUD_SERVICE_TYPE_NONE))
>       END
>     INTO CLOUD_SERVICE_TYPE
>     FROM DATABASE_PROPERTIES
>     WHERE UPPER(PROPERTY_NAME) = 'GLOBAL_DB_NAME';
> 
>     RETURN CLOUD_SERVICE_TYPE;
> 
>   END GET_CLOUD_SERVICE_TYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_TZ_OFFSET
>   RETURN VARCHAR2
>   IS
>     L_TZ VARCHAR2(10);
>   BEGIN
>     
>     
>     L_TZ := EXTRACT(TIMEZONE_HOUR FROM SYSTIMESTAMP) || ':' ||
>                    EXTRACT(TIMEZONE_MINUTE FROM SYSTIMESTAMP);
>     RETURN L_TZ;
>   END GET_TZ_OFFSET;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION CHOOSEAWRFORPDB(
>         BEGINTIME IN DATE) 
>   RETURN VARCHAR2
>   IS
>     L_AWR_LOCATION VARCHAR2(32) := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>     L_SQLTEXT   VARCHAR2(4000);
>     L_PDB_TIME  DATE;
>     L_ROOT_TIME DATE;
> 
>   BEGIN
>     
>     
>     L_SQLTEXT := 
>       'SELECT CAST(MAX(end_interval_time) AS DATE)
>        FROM   AWR_PDB_SNAPSHOT
>        WHERE  dbid = :1';
>     EXECUTE IMMEDIATE L_SQLTEXT 
>     INTO L_PDB_TIME
>     USING SYS_CONTEXT('USERENV', 'CON_DBID');
> 
>     IF L_PDB_TIME IS NULL THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>       RETURN L_AWR_LOCATION;
>     END IF;
> 
>     IF L_PDB_TIME >= BEGINTIME THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB;
>       RETURN L_AWR_LOCATION;
>     END IF;
> 
>     
>     
>     
>     L_SQLTEXT := 
>       'SELECT CAST(MAX(end_interval_time) AS DATE)
>        FROM   AWR_ROOT_SNAPSHOT
>        WHERE  dbid = :1';
>     EXECUTE IMMEDIATE L_SQLTEXT
>     INTO L_ROOT_TIME
>     USING SYS_CONTEXT('USERENV', 'DBID');
>     
>     IF ((L_ROOT_TIME IS NOT NULL) AND 
>         (L_ROOT_TIME >= BEGINTIME) 
>        ) 
>     THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>       RETURN L_AWR_LOCATION;
> 
>     ELSE 
>         
>         L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB;
>         RETURN L_AWR_LOCATION;
>     END IF;
> 
>     RETURN L_AWR_LOCATION;
> 
>   END CHOOSEAWRFORPDB;
> 
SYS.PRVTEMX_PERF - PACKAGE BODY (RU):
7a8,13
>   AWR_PREFIX_ROOT   VARCHAR2(16) := 'sys.awr_root';
>   AWR_PREFIX_PDB    VARCHAR2(16) := 'sys.awr_pdb';
>   G_CLOUD_SERVICE_TYPE CONSTANT VARCHAR2(32) := 
>                     DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE();
> 
>   
379c385
<             from sys.dba_hist_active_sess_history a
---
>             from #AWR_VIEW_PREFIX#_active_sess_history a
462c468
<                             from sys.dba_hist_pdb_instance)) c');
---
>                             from #AWR_VIEW_PREFIX#_pdb_instance)) c');
485,502c491,550
<       SELECT MIN(SNAP_ID)
<         INTO L_BEGIN_SNAP
<         FROM SYS.DBA_HIST_ASH_SNAPSHOT
<        WHERE DBID            = L_DBID
<          AND INSTANCE_NUMBER = P_INST_ID
<          AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
<            OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
<            OR P_START_TIME BETWEEN BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
< 
<          
<       SELECT MAX(SNAP_ID)
<         INTO L_END_SNAP
<         FROM SYS.DBA_HIST_ASH_SNAPSHOT
<        WHERE DBID            = L_DBID
<          AND INSTANCE_NUMBER = P_INST_ID
<          AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
<            OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
<            OR P_END_TIME BETWEEN BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
---
>       
>       IF ((G_CLOUD_SERVICE_TYPE IN 
>             (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D))
>           AND 
>             (L_IS_ROOT = FALSE))
>       THEN  
>           L_QRY := REPLACE(L_QRY,'#AWR_VIEW_PREFIX#', AWR_PREFIX_PDB);
> 
>           
>           SELECT MIN(SNAP_ID)
>             INTO L_BEGIN_SNAP
>             FROM SYS.AWR_PDB_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_START_TIME BETWEEN 
>                                BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>              
>           SELECT MAX(SNAP_ID)
>             INTO L_END_SNAP
>             FROM SYS.AWR_PDB_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_END_TIME BETWEEN 
>                              BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>       ELSE 
>           
>           L_QRY := REPLACE(L_QRY,'#AWR_VIEW_PREFIX#', AWR_PREFIX_ROOT);
> 
>           
>           SELECT MIN(SNAP_ID)
>             INTO L_BEGIN_SNAP
>             FROM SYS.AWR_ROOT_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_START_TIME BETWEEN 
>                                BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>              
>           SELECT MAX(SNAP_ID)
>             INTO L_END_SNAP
>             FROM SYS.AWR_ROOT_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_END_TIME BETWEEN 
>                              BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>       END IF;
SYS.PRVTEMX_RSRCMGR - PACKAGE BODY (RU):
2530,2578d2529
<   PROCEDURE I_CREATE_AWR_CG_MAP(
<     P_CON_ID     IN     NUMBER,
<     P_AWR_PERIOD IN OUT NOCOPY PRVT_AWRV_METADATA,
<     P_CGRP_MAP   IN OUT NOCOPY PRVT_AWRV_INSTTAB)
<   IS
<     
<     SQLSTMT_MAP CONSTANT VARCHAR2(32767) := q'[
<       select sys.prvt_awrv_inst(id, name)
<         from (
<           select distinct 
<                  consumer_group_id id, 
<                  consumer_group_name name 
<             from sys.awr_root_rsrc_consumer_group s
<            where s.dbid             = :m_dbid
<              and s.snap_id          > :m_begin_snap
<              and s.snap_id         <= :m_end_snap
<              and s.con_dbid         = :m_con_dbid
<              and ]' || P_AWR_PERIOD.GET_INST_CLAUSE('s') ||')';
<          
<   BEGIN
<     IF (P_CON_ID = 0 OR P_CON_ID > 2) THEN
<       EXECUTE IMMEDIATE SQLSTMT_MAP
<         BULK COLLECT INTO P_CGRP_MAP
<         USING P_AWR_PERIOD.M_DBID,
<               P_AWR_PERIOD.M_BEGIN_SNAP, P_AWR_PERIOD.M_END_SNAP,
<               SYS.DBMS_SQLTUNE_UTIL0.CDBCON_ID_TO_DBID(P_CON_ID),
<               P_AWR_PERIOD.M_INST_ID_LOW, P_AWR_PERIOD.M_INST_ID_HIGH,
<               P_AWR_PERIOD.M_INST_ID_LIST;
<     ELSE
<       
<       P_CGRP_MAP := PRVT_AWRV_INSTTAB();
<     END IF;
<   END I_CREATE_AWR_CG_MAP;
< 
< 
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
2883c2834,2835
<         I_CREATE_AWR_CG_MAP(L_CON_ID, AWR_PERIOD, L_DIM_MAP);  
---
>         PRVT_AWR_VIEWER.CREATE_CONSUMER_GROUP_MAP(
>           L_CON_ID, AWR_PERIOD, L_DIM_MAP);  
SYS.PRVT_AWR_VIEWER - PACKAGE BODY (RU):
1183a1184,1273
>   
>   
>   RMMETRICS_COMMON CONSTANT VARCHAR2(32767) := q'[
>       with rmmetrics_data as (-- autonomous DB workload main query
>         select bucket_id, 
>                new_id consumer_group_id,
>                case 
>                  when rn = 1 and :is_awr = 1
>                    then (select /*+ cardinality(t 1) */ instance_name
>                            from table(cast(:p_contTab 
>                                       as sys.prvt_awrv_instTab)) t
>                           where t.inst_id = consumer_group_id)
>                  when rn = 1 
>                    then consumer_group_name 
>                  else null 
>                end consumer_group_name,
>                avg_cpu_utilization,
>                cpu_usage_per_sec,
>                avg_running_stmts,
>                avg_active_parallel_stmts,
>                avg_queued_parallel_stmts
>           from ( -- generate an id since default ids can be high numbers
>             select bucket_id,
>                    consumer_group_id,
>                    consumer_group_name,
>                    avg_cpu_utilization,
>                    cpu_usage_per_sec,
>                    avg_running_stmts,
>                    avg_active_parallel_stmts,
>                    avg_queued_parallel_stmts,
>                    row_number() over (partition by consumer_group_id, 
>                                                consumer_group_name
>                                       order by bucket_id, 
>                                                consumer_group_id, 
>                                                consumer_group_name) rn,
>                    -- generate an id
>                    dense_rank() over (order by consumer_group_id, 
>                                                consumer_group_name) new_id
>               from (#GENERATE_METRICS_BUCKETID#) rsrc
>               where avg_cpu_utilization + cpu_usage_per_sec + 
>                     avg_running_stmts +
>                     avg_active_parallel_stmts + avg_queued_parallel_stmts > 0) 
>        )
> 
>       -- construct xml
>       select xmlagg(
>                nvl2(buckets,
>                     xmlelement("stattype",
>                      xmlattributes('rsrcmgrmetric' as "name"),
>                      xmlelement("stat_info",
>                        nvl(stat_id, 
>                            xmlelement("stat", 
>                              xmlattributes(
>                                consumer_group_id as "id", 
>                                consumer_group_id as "name")))),
>                      #GENERATE_BUCKETS_TAG#),
>                     null))
>         from ( -- aggregate buckets
>           select #GENERATE_BUCKETID_TAG#,
>                  xmlagg(stat_id)  stat_id, 
>                  max(consumer_group_id) consumer_group_id
>             from ( -- aggregate stats in each bucket
>               select bucket_id, 
>                      max(consumer_group_id) consumer_group_id,
>                      xmlagg(stat_id order by consumer_group_id) stat_id,
>                      xmlagg(xmlelement("stat",
>                       xmlattributes(consumer_group_id as "id",
>                             round(avg_cpu_utilization, 2)         as "cpu",
>                             round(cpu_usage_per_sec, 2)           as "cpuUsage",
>                             round(avg_running_stmts, 2)           as "rst",
>                             round(avg_active_parallel_stmts, 2)   as "apst",
>                             round(avg_queued_parallel_stmts, 2)   as "qpst"
>                         )
>                       )
>                       order by consumer_group_id)  stats
>                 from ( -- generate id name map
>                   select bucket_id, consumer_group_id,
>                          nvl2(consumer_group_name,
>                               xmlelement("stat",
>                                xmlattributes(consumer_group_id as "id",
>                                  consumer_group_name as "name")),
>                               null)      stat_id,
>                          avg_cpu_utilization,
>                          cpu_usage_per_sec,
>                          avg_running_stmts,
>                          avg_active_parallel_stmts,
>                          avg_queued_parallel_stmts
>                    from rmmetrics_data)
>                group by bucket_id))]';
> 
1311a1402,1461
>   PROCEDURE CREATE_CONSUMER_GROUP_MAP(
>     P_CON_ID     IN     NUMBER,
>     P_AWR_PERIOD IN OUT NOCOPY PRVT_AWRV_METADATA,
>     P_CGRP_MAP   IN OUT NOCOPY PRVT_AWRV_INSTTAB)
>   IS
> 
>     L_QRY VARCHAR2(32767) := NULL;
> 
>     
>     SQLSTMT_MAP CONSTANT VARCHAR2(32767) := q'[
>       select sys.prvt_awrv_inst(id, name)
>         from (
>           select distinct 
>                  consumer_group_id id, 
>                  consumer_group_name name 
>             from sys.awr_root_rsrc_consumer_group s
>            where s.dbid             = :m_dbid
>              and s.snap_id          > :m_begin_snap
>              and s.snap_id         <= :m_end_snap
>              and s.con_dbid         = :m_con_dbid
>              and ]' || P_AWR_PERIOD.GET_INST_CLAUSE('s') ||')';
> 
>   BEGIN
> 
>     L_QRY := SQLSTMT_MAP;
> 
>     DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(
>       L_QRY, P_AWR_PERIOD.M_AWR_VIEW_PREFIX);
> 
>     
>     IF (P_CON_ID = 0 OR P_CON_ID > 2) THEN
>       EXECUTE IMMEDIATE L_QRY
>         BULK COLLECT INTO P_CGRP_MAP
>         USING P_AWR_PERIOD.M_DBID,
>               P_AWR_PERIOD.M_BEGIN_SNAP, P_AWR_PERIOD.M_END_SNAP,
>               SYS.DBMS_SQLTUNE_UTIL0.CDBCON_ID_TO_DBID(P_CON_ID),
>               P_AWR_PERIOD.M_INST_ID_LOW, P_AWR_PERIOD.M_INST_ID_HIGH,
>               P_AWR_PERIOD.M_INST_ID_LIST;
>     
>     ELSE
>       
>       P_CGRP_MAP := PRVT_AWRV_INSTTAB();
>     END IF;
> 
>   END CREATE_CONSUMER_GROUP_MAP;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
16404a16555,16556
>   
>   
16416a16569
>     INCLUDE_SQLS      IN NUMBER         DEFAULT NULL,
16601c16754
<     IF (L_DIM_STAT IS NULL AND L_DIM_NAME IS NULL) THEN 
---
>     IF (INCLUDE_SQLS = 0) THEN
16602a16756,16758
>       L_TOPSQL_XML := NULL;
>     
>     ELSE
16604,16626c16760
<       IF (IS_REALTIME IS NULL OR IS_REALTIME = G_TIMEPICKER_HISTORICAL) THEN
<         
<       IF (L_START_TIME IS NOT NULL AND L_END_TIME IS NOT NULL AND
<           (L_END_TIME - L_START_TIME)*24*60 < L_SNAPINT_MINS) 
<       THEN
<         L_USEASH := TRUE;
<       END IF;
<       
<       
<       ELSE
<         L_USEASH := TRUE;
<       END IF;
< 
< 
<     IF (L_USEASH) THEN
<       SELECT XMLELEMENT("region_data",
<               XMLAGG(
<                 XMLELEMENT("stattype",
<                  XMLATTRIBUTES('topsql' AS "name",
<                                 '10' AS "topn",
<                                 'ash'   AS "source"))))
<         INTO L_TOPSQL_XML
<         FROM SYS.DUAL;
---
>       IF (L_DIM_STAT IS NULL AND L_DIM_NAME IS NULL) THEN 
16629,16630c16763,16773
<         IF (L_END_TIME IS NULL) THEN
<           L_END_TIME := SYSDATE;
---
>         IF (IS_REALTIME IS NULL OR IS_REALTIME = G_TIMEPICKER_HISTORICAL) THEN
>           
>           IF (L_START_TIME IS NOT NULL AND L_END_TIME IS NOT NULL AND
>              (L_END_TIME - L_START_TIME)*24*60 < L_SNAPINT_MINS) 
>           THEN
>             L_USEASH := TRUE;
>           END IF;
>           
>           
>         ELSE
>           L_USEASH := TRUE;
16633,16635d16775
<         IF (L_START_TIME IS NULL) THEN
<           L_START_TIME := L_END_TIME - 1/24;
<         END IF;
16637,16646c16777,16805
<         L_TOPSQL_XML := L_TOPSQL_XML.APPENDCHILDXML('/*/stattype',
<                         SYS.DBMS_ASH_INTERNAL.REPORT_ASHVIEWER_XML(
<                            DBID       => L_DBID,
<                            INST_ID    => L_INST_ID,
<                            BEGIN_TIME => 
<                              TO_CHAR(L_START_TIME,'hh24:mi:ss mm/dd/yyyy'),
<                            END_TIME   => 
<                              TO_CHAR(L_END_TIME,'hh24:mi:ss mm/dd/yyyy'),
<                            REPORT_LEVEL=>'<sqlid,wait_class>{treemap}', 
<                            PARENT_REPORT => 'topsql'));
---
>         IF (L_USEASH) THEN
>           SELECT XMLELEMENT("region_data",
>                    XMLAGG(
>                      XMLELEMENT("stattype",
>                        XMLATTRIBUTES('topsql' AS "name",
>                                      '10' AS "topn",
>                                      'ash'   AS "source"))))
>             INTO L_TOPSQL_XML
>             FROM SYS.DUAL;
> 
>             
>             IF (L_END_TIME IS NULL) THEN
>               L_END_TIME := SYSDATE;
>             END IF;
> 
>             IF (L_START_TIME IS NULL) THEN
>               L_START_TIME := L_END_TIME - 1/24;
>             END IF;
> 
>             L_TOPSQL_XML := L_TOPSQL_XML.APPENDCHILDXML('/*/stattype',
>                               SYS.DBMS_ASH_INTERNAL.REPORT_ASHVIEWER_XML(
>                                 DBID          => L_DBID,
>                                 INST_ID       => L_INST_ID,
>                                 BEGIN_TIME    => 
>                                   TO_CHAR(L_START_TIME,'hh24:mi:ss mm/dd/yyyy'),
>                                 END_TIME      => 
>                                   TO_CHAR(L_END_TIME,'hh24:mi:ss mm/dd/yyyy'),
>                                 REPORT_LEVEL  =>'<sqlid,wait_class>{treemap}', 
>                                 PARENT_REPORT => 'topsql'));
16648c16807
<     ELSE
---
>         ELSE
16650,16673c16809,16834
<       
<       L_TOPSQL_XML := I_REP_AWRDATA_XML(
<                         START_TIME       => L_START_TIME,
<                         END_TIME         => L_END_TIME,
<                         TIMEPICKER_START => NULL,
<                         TIMEPICKER_END   => NULL,
<                         INSTANCE_LIST    => L_INSTANCE_LIST,
<                         DBID             => L_DBID,
<                         BUCKET_MAX_COUNT => 1,  
<                         TIME_MODEL       => 'no',
<                         WAIT_CLASS       => 'no',
<                         WAIT_EVENT       => 'no',
<                         EVENT_CLASS      => 'no',
<                         SYSSTAT          => 'no',
<                         SQLSTAT          => 'EM_TOP_SQL',
<                         OSSTAT           => 'no',
<                         IOSTAT           => 'no',
<                         MEMORY           => 'no',
<                         SPACE            => 'no',
<                         KEY_STATISTICS   => 'no',
<                         INST_DETAIL      => L_SHOW_INST_DETAIL,
<                         MEMBERS          => 'no',
<                         SUMMARY          => 'no',
<                         SHOW_SQL         => SHOW_SQL);
---
>           
>           L_TOPSQL_XML := I_REP_AWRDATA_XML(
>                             START_TIME       => L_START_TIME,
>                             END_TIME         => L_END_TIME,
>                             TIMEPICKER_START => NULL,
>                             TIMEPICKER_END   => NULL,
>                             INSTANCE_LIST    => L_INSTANCE_LIST,
>                             DBID             => L_DBID,
>                             BUCKET_MAX_COUNT => 1,  
>                             TIME_MODEL       => 'no',
>                             WAIT_CLASS       => 'no',
>                             WAIT_EVENT       => 'no',
>                             EVENT_CLASS      => 'no',
>                             SYSSTAT          => 'no',
>                             SQLSTAT          => 'EM_TOP_SQL',
>                             OSSTAT           => 'no',
>                             IOSTAT           => 'no',
>                             MEMORY           => 'no',
>                             SPACE            => 'no',
>                             KEY_STATISTICS   => 'no',
>                             INST_DETAIL      => L_SHOW_INST_DETAIL,
>                             MEMBERS          => 'no',
>                             SUMMARY          => 'no',
>                             SHOW_SQL         => SHOW_SQL);
>         END IF;
>       END IF;
16675d16835
<   END IF;
18086a18247,20960
>   
>   
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_RMMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME      IN DATE               DEFAULT NULL,
>     END_TIME        IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT 0)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER        := IS_REALTIME;
>     L_DBID            NUMBER        := DBID;
>     L_START_TIME      DATE          := START_TIME;
>     L_END_TIME        DATE          := END_TIME;
>     L_BUCKET_COUNT    NUMBER        := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER        := BUCKET_INTERVAL;
>     L_AWR_PERIOD PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(10)  := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_BUCKET_MAP PRVT_AWRV_MAPTAB;
> 
>     
>     L_CON_ID   NUMBER;
>     L_CON_DBID NUMBER;
> 
>     
>     L_RESOURCE_MANAGER_ENABLED NUMBER := 0;
>     
>     
>     L_NUM_CPUS NUMBER := NULL;
> 
>     
>     L_CG_MAP PRVT_AWRV_INSTTAB := NULL;
> 
>     
>     RMMETRICS_RT CONSTANT VARCHAR2(32767) := q'[
>     select bucket_id,
>            consumer_group_id, consumer_group_name,
>            case
>              when avg(avg_cpu_utilization) > 100 then 100
>              else avg(avg_cpu_utilization) 
>            end avg_cpu_utilization,
>            avg(cpu_usage_per_sec) cpu_usage_per_sec,
>            sum(avg_running_stmts) avg_running_stmts,
>            sum(avg_active_parallel_stmts) 
>                                      avg_active_parallel_stmts,
>            sum(avg_queued_parallel_stmts) 
>                                      avg_queued_parallel_stmts
>       from table(sys.gv$(cursor(
>            select trunc(
>                   ((extract(day from 
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                     * 86400 +
>                     extract(hour from 
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                     * 3600 + 
>                     extract(minute from
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                     * 60 + 
>                     extract(second from
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                    )
>                    / :p_bucket_interval)) + 1 bucket_id,
>                   consumer_group_name,
>                   consumer_group_id,
>                   (case 
>                      -- resource manager enabled, use running_sessions_limit
>                      when :resource_manager_enabled > 0 then
>                        (case
>                           -- if running_sessions_limit is not set
>                           when running_sessions_limit is null or
>                                running_sessions_limit = 0 then
>                             avg_cpu_utilization
>                           else
>                             (avg_running_sessions/running_sessions_limit)*100
>                         end)
>                      -- resource manager disabled, use system cpu limit
>                      else
>                        (case
>                           when :num_cpus > 0 then
>                             (avg_running_sessions/:num_cpus)*100
>                           -- system cpu limit not available
>                           -- use running_sessions_limit
>                           else
>                             (case
>                                when running_sessions_limit is null or
>                                     running_sessions_limit = 0 then
>                                  avg_cpu_utilization
>                                else
>                                 (avg_running_sessions/running_sessions_limit)*100
>                              end)
>                         end)
>                      end) avg_cpu_utilization,
>                   cpu_consumed_time/(intsize_csec*10) cpu_usage_per_sec,
>                   avg_running_sessions + avg_waiting_sessions
>                     as avg_running_stmts,
>                   avg_active_parallel_stmts,
>                   avg_queued_parallel_stmts
>              from sys.v_$rsrcmgrmetric_history
>             where end_time >= to_date(:b_start_time, :date_fmt)
>               and end_time <  to_date(:b_end_time, :date_fmt))))
>          group by bucket_id, consumer_group_id, consumer_group_name]';
> 
>     
>     RMMETRICS_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var is_awr                   number;
>       var p_contTab                prvt_awrv_instTab;
>       var b_start_time             varchar2(4000);
>       var b_end_time               varchar2(4000);
>       var p_bucket_interval        number;
>       var p_bucket_count           number;
>       var b_min_time               varchar2(4000);
>       var b_max_time               varchar2(4000);
>       var b_duration               number;
>       var date_fmt                 varchar2(4000);
>       var resource_manager_enabled number;
>       var num_cpus                 number;
>       begin
>         :is_awr                   := #is_awr#;
>         :p_contTab                := #p_contTab#;
>         :b_start_time             := '#b_start_time#';
>         :b_end_time               := '#b_end_time#';
>         :p_bucket_interval        := #p_bucket_interval#;
>         :p_bucket_count           := #p_bucket_count#;
>         :b_min_time               := '#b_min_time#';
>         :b_max_time               := '#b_max_time#';
>         :b_duration               := #b_duration#;
>         :date_fmt                 := '#date_fmt#';
>         :resource_manager_enabled := #resource_manager_enabled#;
>         :num_cpus                 := #num_cpus#;
>       end;
>       /]';
> 
>     
>     RMMETRICS_AWR CONSTANT VARCHAR2(32767) := q'[
>     select bucket_id,
>            consumer_group_id,
>            consumer_group_name,
>            case
>              when sum(avg_cpu_utilization) > 100 then 100
>              else sum(avg_cpu_utilization) 
>            end avg_cpu_utilization,
>            sum(cpu_usage_per_sec) cpu_usage_per_sec,
>            sum(avg_running_stmts) avg_running_stmts,
>            sum(avg_active_parallel_stmts) avg_active_parallel_stmts,
>            sum(avg_queued_parallel_stmts) avg_queued_parallel_stmts
>      from (
>         select bucket_id,
>                consumer_group_name,  
>                consumer_group_id,
>                -- avg
>                avg(avg_cpu_utilization) avg_cpu_utilization,
>                avg(cpu_usage_per_sec) cpu_usage_per_sec,
>                avg(avg_running_stmts) avg_running_stmts,
>                avg(avg_active_parallel_stmts) 
>                   avg_active_parallel_stmts,
>                avg(avg_queued_parallel_stmts) 
>                   avg_queued_parallel_stmts
>           from table(cast(:bucket_map as sys.prvt_awrv_mapTab)) b,
>                (select /*+ no_merge */ nvl(m.snap_id, c.snap_id) as snap_id,
>                        nvl(m.instance_number, c.instance_number) 
>                                                  as instance_number,
>                        m.consumer_group_id consumer_group_id,
>                        null consumer_group_name,
>                        case 
>                          when c.cpu_limit is null or
>                               c.cpu_limit = 0 then
>                            m.avg_cpu_utilization
>                          else
>                            (m.avg_running_sessions/c.cpu_limit)*100
>                          end                       as avg_cpu_utilization,
>                        m.cpu_consumed_time/(m.intsize_csec*10) cpu_usage_per_sec,
>                        m.avg_running_sessions + m.avg_waiting_sessions
>                                                    as avg_running_stmts,
>                        m.avg_active_parallel_stmts as avg_active_parallel_stmts,
>                        m.avg_queued_parallel_stmts as avg_queued_parallel_stmts
>                   from awr_root_rsrc_metric m,
>                        (SELECT /*+ no_merge */ 
>                                nvl(s.snap_id, p.snap_id) as snap_id,
>                                nvl(s.instance_number, p.instance_number) 
>                                                          as instance_number,
>                                CASE WHEN p.cpu_count IS NULL 
>                                     THEN nvl(s.num_cpus, s.num_cpu_cores)
>                                     ELSE LEAST(p.cpu_count, 
>                                                NVL(s.num_cpus, s.num_cpu_cores))
>                                END as cpu_limit
>                           FROM   
>                             (SELECT /*+ NO_MERGE */ snap_id, instance_number,
>                                     MAX(num_cpus)      num_cpus,
>                                     MAX(num_cpu_cores) num_cpu_cores
>                                FROM 
>                                  (SELECT snap_id, instance_number,
>                                          CASE
>                                            WHEN stat_name = 'NUM_CPUS' 
>                                            THEN value
>                                            ELSE NULL
>                                          END as num_cpus,
>                                          CASE
>                                            WHEN stat_name = 'NUM_CPU_CORES'
>                                            THEN value
>                                            ELSE NULL
>                                          END as num_cpu_cores
>                                     FROM awr_root_osstat
>                                    WHERE stat_name IN 
>                                            ('NUM_CPUS','NUM_CPU_CORES'))
>                                   GROUP BY snap_id, instance_number) s,
>                             (SELECT /*+ NO_MERGE */ snap_id, instance_number,
>                                     MAX(
>                                       CASE 
>                                         WHEN resource_plan IS NULL THEN NULL 
>                                         ELSE TO_NUMBER(cpu_count)
>                                       END) as cpu_count
>                                FROM 
>                                  (SELECT snap_id, instance_number,
>                                          CASE
>                                            WHEN parameter_name = 'cpu_count' 
>                                            THEN value
>                                            ELSE NULL
>                                          END cpu_count,
>                                          CASE
>                                            WHEN parameter_name = 
>                                                   'resource_manager_plan'
>                                            THEN value
>                                            ELSE NULL
>                                          END resource_plan
>                                     FROM awr_root_parameter
>                                    WHERE parameter_name IN 
>                                           ('cpu_count', 'resource_manager_plan'))
>                                   GROUP BY snap_id, instance_number) p
>                          WHERE s.snap_id = p.snap_id
>                            AND s.instance_number = p.instance_number) c
>                  where m.dbid = :m_dbid 
>                    and m.snap_id between :m_begin_snap and :m_end_snap
>                    and m.con_dbid = :l_con_dbid
>                    and m.snap_id = c.snap_id(+)
>                    and m.instance_number = c.instance_number(+)) y
>          where b.snap_id         = y.snap_id
>            and b.instance_number = y.instance_number
>          group by bucket_id, 
>                y.instance_number, 
>                y.consumer_group_id, 
>                y.consumer_group_name)
>       group by bucket_id, 
>                consumer_group_id,
>                consumer_group_name]'; 
> 
>     
>     RMMETRICS_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var is_awr            number;
>       var p_contTab         prvt_awrv_instTab;
>       var bucket_map        prvt_awrv_mapTab;
>       var m_dbid            number;
>       var m_begin_snap      number;
>       var m_end_snap        number;
>       var l_con_dbid        number;
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_min_time        varchar2(4000);
>       var b_max_time        varchar2(4000);
>       var b_duration        number;
>       begin
>         :is_awr            := #is_awr#;
>         :p_contTab         := #p_contTab#;
>         :bucket_map        := #bucket_map#;
>         :m_dbid            := #m_dbid#;
>         :m_begin_snap      := #m_begin_snap#;
>         :m_end_snap        := #m_end_snap#;
>         :l_con_dbid        := #l_con_dbid#;
>         :p_bucket_interval := #p_bucket_interval#;
>         :p_bucket_count    := #p_bucket_count#;
>         :b_min_time        := '#b_min_time#';
>         :b_max_time        := '#b_max_time#';
>         :b_duration        := #b_duration#;
>       end;
>       /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
>     
>     
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME IS NULL) THEN
>       L_END_TIME := SYSDATE;
>     END IF;
> 
>     
>     IF (START_TIME IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME := L_END_TIME - 1/24;
>       
>       ELSE
>         L_START_TIME := L_END_TIME - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
>       
>       
>       BEGIN
>         SELECT COUNT(VALUE)
>           INTO L_RESOURCE_MANAGER_ENABLED
>           FROM SYS.V_$SYSTEM_PARAMETER2        
>          WHERE NAME = 'resource_manager_plan'
>            AND (VALUE IS NOT NULL AND VALUE != '');
>       EXCEPTION
>         WHEN OTHERS THEN
>           L_RESOURCE_MANAGER_ENABLED := 0;
>       END;
> 
>       
>       BEGIN
>         SELECT SUM(NUM_CPUS)
>           INTO L_NUM_CPUS
>           FROM (
>             SELECT HOST_NAME, SUM(NUM_CPUS) AS NUM_CPUS
>               FROM TABLE(GV$(CURSOR(
>                      SELECT I.INSTANCE_NUMBER AS INST_ID, I.HOST_NAME,
>                             NVL(OS.NUM_CPUS, OS.NUM_CPU_CORES) AS NUM_CPUS
>                        FROM SYS.V$INSTANCE I, 
>                             (SELECT MAX(DECODE(STAT_NAME, 'NUM_CPUS', 
>                                                VALUE, NULL)) AS NUM_CPUS,
>                                     MAX(DECODE(STAT_NAME, 'NUM_CPU_CORES', 
>                                                VALUE, NULL)) AS NUM_CPU_CORES
>                                FROM SYS.V$OSSTAT
>                               WHERE STAT_NAME IN ('NUM_CPUS', 'NUM_CPU_CORES')
>                             ) OS)))
>             GROUP BY HOST_NAME);
>       EXCEPTION
>         WHEN OTHERS THEN
>           L_NUM_CPUS := 0;
>       END;
> 
>       
>       L_QRY := RMMETRICS_COMMON;
>    
>       
>       L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETS_TAG#', 
>                               GENERATE_BUCKETS_TAG2);
>       L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETID_TAG#', 
>                               GENERATE_BUCKETID_TAG);
>       L_QRY := REPLACE(L_QRY,'#GENERATE_METRICS_BUCKETID#', 
>                               RMMETRICS_RT);
> 
>       IF (SHOW_SQL = 1) THEN
>         
>         L_SQL := RMMETRICS_RT_HEADER;
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#is_awr#', 0);
>         L_SQL := REPLACE(L_SQL, '#p_contTab#', 'null');
>         L_SQL := REPLACE(L_SQL, '#b_start_time#',
>                                  TO_CHAR(L_START_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time#',
>                                  TO_CHAR(L_END_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_min_time#', TO_CHAR(L_START_TIME, 
>                                                         DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_max_time#', TO_CHAR(L_END_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                  ROUND((L_END_TIME - L_START_TIME)*DTOS));
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
> 
>         L_SQL := REPLACE(L_SQL, '#resource_manager_enabled#', 
>                                 L_RESOURCE_MANAGER_ENABLED);
> 
>         L_SQL := REPLACE(L_SQL, '#num_cpus#', L_NUM_CPUS);
> 
>         L_RESULT_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_SQL);
> 
>       ELSE
>         
>         EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING 0, L_CG_MAP,
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 L_BUCKET_INTERVAL,
>                 L_RESOURCE_MANAGER_ENABLED,
>                 L_NUM_CPUS, L_NUM_CPUS,
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_END_TIME, DATE_FMT), DATE_FMT,
>                 
>                 L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME,DATE_FMT), TO_CHAR(L_END_TIME,DATE_FMT),
>                 (L_END_TIME - L_START_TIME)*DTOS;
>       END IF;
>     
>     
>     ELSE
> 
>       IF (L_AWR_PERIOD IS NOT NULL) THEN
>         
>         CREATE_BUCKET_SNAP_MAP(L_AWR_PERIOD, L_BUCKET_MAP, 
>                                L_BUCKET_COUNT, L_BUCKET_INTERVAL);
> 
>         L_CON_ID := SYS_CONTEXT('USERENV','CON_ID');
> 
>         CREATE_CONSUMER_GROUP_MAP(L_CON_ID, L_AWR_PERIOD, L_CG_MAP);
> 
>         
>         L_QRY := RMMETRICS_COMMON;
>    
>         
>         L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETS_TAG#', 
>                                 GENERATE_BUCKETS_TAG2);
>         L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETID_TAG#', 
>                                 GENERATE_BUCKETID_TAG);
>         L_QRY := REPLACE(L_QRY,'#GENERATE_METRICS_BUCKETID#', 
>                                 RMMETRICS_AWR);
> 
>         
>         
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := RMMETRICS_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#is_awr#', 1);
>           L_SQL := REPLACE(L_SQL, '#p_contTab#', '');
>           L_SQL := REPLACE(L_SQL, '#bucket_map#', '');
>           L_SQL := REPLACE(L_SQL, '#m_dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#m_begin_snap#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#m_end_snap#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#l_con_dbid#', L_CON_DBID);
>           L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#b_min_time#', 
>                                    TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#b_max_time#', 
>                                    TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                            L_AWR_PERIOD.M_MAX_TIME, 
>                                            L_AWR_PERIOD.M_MIN_TIME)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING 1, 
>                 L_CG_MAP, 
>                 L_BUCKET_MAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_CON_DBID,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT),
>                 TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT),
>                 ROUND(
>                   INTERVAL_TO_SECOND(
>                     L_AWR_PERIOD.M_MAX_TIME, L_AWR_PERIOD.M_MIN_TIME));
>         END IF;
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_RMMETRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SQL_N_PARSE_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     SQL_AND_PARSE_TIME_RT CONSTANT VARCHAR2(32767) := q'[
>       with base_data as (
>         SELECT bucket_id,
>                SUM(parse_time_sec) / :p_bucket_interval AS parse_aas,
>                SUM(sql_exec_time_sec) / :p_bucket_interval AS sql_exec_aas,
>                SUM(plsql_exec_time_sec) / :p_bucket_interval AS plsql_exec_aas
>           FROM TABLE(GV$(CURSOR(
>                  SELECT bucket_id, 
>                         SUM(parse_time_usec) / 1000000    as parse_time_sec,
>                         SUM(sql_exec_time_usec) / 1000000 as sql_exec_time_sec,
>                         SUM(plsql_exec_time_usec) / 1000000 
>                                                           as plsql_exec_time_sec
>                    FROM (
>                          SELECT TRUNC(((
>                                   cast(sample_time_utc as date) - 
>                                   to_date(:b_start_time_utc, :date_fmt)) 
>                                   * 86400 ) / :p_bucket_interval) + 1 
>                                     as bucket_id,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_parse = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as parse_time_usec,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_sql_execution = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as sql_exec_time_usec,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_plsql_execution = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as plsql_exec_time_usec
>                            FROM sys.v_$active_session_history 
>                           WHERE sample_time_utc > to_timestamp(
>                                                     :b_start_time_utc,
>                                                     :date_fmt) 
>                             AND sample_time_utc <= to_timestamp(
>                                                     :b_end_time_utc,:date_fmt)
>                         )
>                   WHERE bucket_id > 0
>                   GROUP BY bucket_id
>                )))
>         GROUP BY bucket_id
>         ORDER BY bucket_id)
>       select xmlelement("stattype",
>                xmlattributes('sql' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id    as "bucket_id"),
>                   xmlforest(round(parse_aas, 2)      as "parse_aas",
>                             round(sql_exec_aas, 2)   as "sql_aas",
>                             round(plsql_exec_aas, 2) as "plsql_aas")))))
>         from base_data
>        where (parse_aas + sql_exec_aas + plsql_exec_aas) > 0]';
> 
>     
>     SQL_AND_PARSE_TIME_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>     var date_fmt          varchar2(32);
>     var b_start_time_utc  varchar2(32);
>     var b_end_time_utc    varchar2(32);
>     var p_bucket_interval number;
>     var p_bucket_count    number;
>     var b_duration        number;
>     begin 
>       :date_fmt            := '#date_fmt#';
>       :b_start_time_utc    := '#b_start_time_utc#';
>       :b_end_time_utc      := '#b_end_time_utc#';
>       :p_bucket_interval   := #p_bucket_interval#;
>       :p_bucket_count      := #p_bucket_count#;
>       :b_duration          := #b_duration#;
>     end;
>     /]';
> 
> 
>     
>     SQL_AND_PARSE_TIME_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, s.stat_name, 
>                   s.value / 1000000 as value_secs 
>              FROM awr_root_con_sys_time_model s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.stat_name IN ('parse time elapsed', 
>                                   'sql execute elapsed time', 
>                                   'PL/SQL execution elapsed time')
>           ),
>         diff_stats AS 
>           (SELECT estat.instance_number, estat.snap_id, estat.stat_name, 
>                   s.begin_time_utc, s.end_time_utc,
>                   GREATEST(estat.value_secs - 
>                            (s.diff_logic * NVL(bstat.value_secs,0)),0) /
>                   ((s.end_time_utc - s.begin_time_utc)*86400)
>                   as value_per_sec
>              FROM base_stats estat, snaps s, base_stats bstat
>             WHERE estat.instance_number = s.instance_number
>               AND estat.snap_id = s.snap_id
>               AND estat.instance_number = bstat.instance_number(+)
>               AND estat.snap_id-1 = bstat.snap_id(+)
>               AND estat.stat_name = bstat.stat_name(+)
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400)      as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         final_stats AS
>           (SELECT bucket_id, stat_name, 
>                   SUM(value_per_sec * bucket_ratio) as aas
>              FROM (
>                    SELECT b.bucket_id, s.stat_name, s.value_per_sec, 
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM diff_stats s, buckets b
>                     WHERE s.value_per_sec > 0
>                       AND b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, stat_name
>           ),
>         pivoted_stats AS
>           (SELECT * FROM final_stats
>            PIVOT(SUM(aas) FOR stat_name IN 
>                              ('parse time elapsed' as parse_aas,
>                               'sql execute elapsed time' as sql_exec_aas,
>                               'PL/SQL execution elapsed time' as plsql_exec_aas)
>                 )
>           ),
>         base_data AS
>           (SELECT bucket_id, parse_aas, sql_exec_aas, plsql_exec_aas
>              FROM pivoted_stats
>            ORDER BY bucket_id)
>       select xmlelement("stattype",
>                xmlattributes('sql' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id    as "bucket_id"),
>                   xmlforest(round(parse_aas, 2)      as "parse_aas",
>                             round(sql_exec_aas, 2)   as "sql_aas",
>                             round(plsql_exec_aas, 2) as "plsql_aas")))))
>         from base_data
>        where (parse_aas + sql_exec_aas + plsql_exec_aas) > 0]';
> 
>     
>     SQL_AND_PARSE_TIME_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
>       
>       L_QRY := SQL_AND_PARSE_TIME_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := SQL_AND_PARSE_TIME_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('sql_and_parse_time', L_SQL);
> 
>       ELSE
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>  
>     
>     ELSE
>       IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := SQL_AND_PARSE_TIME_AWR;
> 
>         
>         
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := SQL_AND_PARSE_TIME_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#', ROUND(INTERVAL_TO_SECOND(
>                                    L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('sql_and_parse_time', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                 ROUND(
>                   INTERVAL_TO_SECOND(L_END_TIME_UTC, L_START_TIME_UTC));
> 
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SQL_N_PARSE_TIME_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_WAIT_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     WAIT_TIME_RT CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         inst_data AS
>           (SELECT inst_id, bucket_id, metric_name, value
>              FROM TABLE(GV$(CURSOR(
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id, metric_name,
>                            SUM(value*bucket_ratio) as value
>                       FROM (
>                             SELECT USERENV('INSTANCE') as inst_id,
>                                    buckets.bucket_id,
>                                    met.metric_name,
>                                    met.value,
>                                    (LEAST(met.end_time_utc, 
>                                           buckets.end_time_utc) - 
>                                     GREATEST(met.begin_time_utc, 
>                                              buckets.begin_time_utc)) / 
>                                     (met.end_time_utc - met.begin_time_utc) 
>                                       as bucket_ratio
>                              FROM ( 
>                                    SELECT /*+ no_merge */ USERENV('INSTANCE') 
>                                                               as inst_id,
>                                           m.begin_time-tz.time_zone 
>                                                               as begin_time_utc,
>                                           m.end_time-tz.time_zone 
>                                                               as end_time_utc,
>                                           CASE
>                                             WHEN m.metric_name = 
>                                                    'Average Active Sessions'
>                                               THEN 'DBTime'
>                                             ELSE 'CPU'
>                                           END as metric_name,
>                                           CASE 
>                                             WHEN m.metric_name = 
>                                                    'CPU Usage Per Sec' 
>                                             THEN m.value*m.intsize_csec/10000
>                                             ELSE m.value*m.intsize_csec/100
>                                           END as value
>                                      FROM sys.v_$con_sysmetric_history m,
>                                           (SELECT ROUND(
>                                                     (cast(latest_sample_time 
>                                                           as date) - 
>                                                      cast(sys_extract_utc(
>                                                             systimestamp) 
>                                                           as date))
>                                                     *900,0)/900 as time_zone
>                                              FROM sys.v_$ash_info) tz
>                                     WHERE m.group_id = 18
>                                       AND m.metric_name IN 
>                                             ('Average Active Sessions',
>                                              'CPU Usage Per Sec')
>                                       AND m.begin_time-tz.time_zone < 
>                                           to_date(:b_end_time_utc, :date_fmt)
>                                       AND m.end_time-tz.time_zone >= 
>                                           to_date(:b_start_time_utc, :date_fmt)
>                                   ) met,    
>                                   ( 
>                                    SELECT /*+ no_merge */ level as bucket_id,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           ((level -1) * :p_bucket_interval 
>                                            / 86400) as begin_time_utc,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           (level * :p_bucket_interval / 86400) 
>                                                     as end_time_utc
>                                      FROM sys.v_$instance 
>                                           -- note: DUAL not allowed inside GV$
>                                    CONNECT BY level <= 
>                                               (to_date(:b_end_time_utc,
>                                                        :date_fmt) - 
>                                                to_date(:b_start_time_utc, 
>                                                        :date_fmt)) 
>                                               * 86400 / :p_bucket_interval
>                                   ) buckets
>                             WHERE buckets.begin_time_utc < met.end_time_utc
>                               AND buckets.end_time_utc > met.begin_time_utc
>                            )
>                     GROUP BY bucket_id, metric_name
>                     UNION ALL
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id,
>                            metric_name,
>                            SUM(value) as value
>                       FROM (
>                             SELECT TRUNC(((cast(sample_time_utc as date) - 
>                                                 to_date(:b_start_time_utc, 
>                                                         :date_fmt)) * 86400) / 
>                                    :p_bucket_interval) + 1 AS bucket_id,
>                                    DECODE(session_state, 'WAITING', wait_class, 
>                                                          'ASH_CPU') 
>                                                            AS metric_name,
>                                    CASE 
>                                      WHEN session_type = 'FOREGROUND' 
>                                      THEN usecs_per_row/1000000 
>                                      ELSE 0 
>                                    END AS value
>                               FROM sys.v_$active_session_history
>                              WHERE sample_time_utc >= 
>                                    to_timestamp(:b_start_time_utc, :date_fmt)
>                                AND sample_time_utc < 
>                                    to_timestamp(:b_end_time_utc, :date_fmt)
>                            )
>                     WHERE bucket_id > 0
>                     GROUP BY bucket_id, metric_name
>           )))),
>         db_data AS 
>           (SELECT bucket_id, metric_name, 
>                   SUM(value) as value
>              FROM inst_data
>            GROUP BY bucket_id, metric_name
>           ),
>         wait_for_cpu AS
>           (SELECT bucket_id, 'wait for CPU' as metric_name, 
>                   GREATEST(SUM(DECODE(metric_name, 'ASH_CPU', value, 
>                                       -value)), 0)    AS value
>              FROM db_data
>             WHERE metric_name IN ('CPU', 'ASH_CPU')
>            GROUP BY bucket_id
>           ),
>         final_data AS
>           (SELECT bucket_id, metric_name,
>                   value / :p_bucket_interval    AS value
>              FROM db_data
>             WHERE metric_name <> 'ASH_CPU'
>               AND value > 0
>            UNION ALL
>            SELECT bucket_id, metric_name, 
>                   value /:p_bucket_interval     AS value
>              FROM wait_for_cpu
>             WHERE value > 0
>           ),
>         base_data AS
>           (SELECT * FROM final_data
>            ORDER BY bucket_id, metric_name)
>       select xmlelement("stattype",
>                xmlattributes('wait_time' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")
>              ))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     WAIT_TIME_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var date_fmt          varchar2(32);
>       var b_start_time_utc  varchar2(32);
>       var b_end_time_utc    varchar2(32);
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_duration        number;
>       begin 
>         :date_fmt            := '#date_fmt#';
>         :b_start_time_utc    := '#b_start_time_utc#';
>         :b_end_time_utc      := '#b_end_time_utc#';
>         :p_bucket_interval   := #p_bucket_interval#;
>         :p_bucket_count      := #p_bucket_count#;
>         :b_duration          := #b_duration#;
>       end;
>       /]';
> 
>     
>     WAIT_TIME_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT e.instance_number, e.snap_id, e.wait_class, 
>                   SUM(e.time_waited_micro_fg)/1000000 as value
>              FROM awr_root_con_system_event e
>             WHERE e.dbid = :dbid
>               AND e.snap_id >= :begin_snap_id
>               AND e.snap_id <= :end_snap_id
>               AND e.wait_class <> 'Idle'
>            GROUP BY e.instance_number, e.snap_id, e.wait_class  
>            UNION ALL
>            SELECT s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN s.stat_name = 'DB time'
>                     THEN 'DBTime' 
>                     ELSE 'CPU'
>                   END as wait_class,
>                   s.value/1000000 as value
>              FROM awr_root_con_sys_time_model s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.stat_name IN ('DB time', 'DB CPU')
>           ),
>         agg_stats AS
>           (SELECT /*+ no_merge */ instance_number, snap_id, wait_class, 
>                   SUM(value) as value
>              FROM base_stats
>             WHERE value > 0
>            GROUP BY instance_number, snap_id, wait_class
>           ),
>         diff_stats AS 
>           (SELECT estat.instance_number, estat.snap_id, estat.wait_class, 
>                   s.begin_time_utc, s.end_time_utc,
>                   GREATEST(estat.value - 
>                            (s.diff_logic * NVL(bstat.value,0)),0) /
>                   ((s.end_time_utc - s.begin_time_utc)*86400)
>                   as value
>              FROM agg_stats estat, snaps s, agg_stats bstat
>             WHERE estat.instance_number = s.instance_number
>               AND estat.snap_id = s.snap_id
>               AND estat.instance_number = bstat.instance_number(+)
>               AND estat.snap_id-1 = bstat.snap_id(+)
>               AND estat.wait_class = bstat.wait_class(+)
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400) as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         db_stats AS
>           (SELECT bucket_id, wait_class, 
>                   SUM(value * bucket_ratio) as value
>              FROM (
>                    SELECT b.bucket_id, s.wait_class, s.value,
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM diff_stats s, buckets b
>                     WHERE b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, wait_class
>           ),
>         wait_for_cpu AS
>           (SELECT bucket_id, 'wait for CPU' as wait_class,
>                   GREATEST(SUM(DECODE(wait_class, 'DBTime', value, -value)), 
>                            0) as value
>              FROM db_stats
>            GROUP BY bucket_id
>           ),
>         final_stats AS 
>           (SELECT bucket_id, wait_class, value
>              FROM db_stats
>            UNION ALL
>            SELECT bucket_id, wait_class, value
>              FROM wait_for_cpu
>           ),
>        base_data AS
>          (SELECT bucket_id, wait_class, value
>             FROM final_stats
>           ORDER BY 1,2)
>       select xmlelement("stattype",
>                xmlattributes('wait_time' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("wait_class",
>                               xmlattributes(wait_class      as "name",
>                                             round(value, 2) as "value")))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     WAIT_TIME_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
> 
>       L_QRY := WAIT_TIME_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := WAIT_TIME_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#', 
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('wait_time', L_SQL);
> 
>       ELSE
> 
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>     
>     
>     ELSE
>      IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := WAIT_TIME_AWR;
> 
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := WAIT_TIME_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                      L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('wait_time', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT),
>                 ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_WAIT_TIME_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SYSMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     SYSMETRIC_RT CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         inst_data AS
>           (SELECT inst_id, bucket_id, metric_name, value
>              FROM TABLE(GV$(CURSOR(
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id, metric_name,
>                            SUM(value*bucket_ratio) as value
>                       FROM (
>                             SELECT USERENV('INSTANCE') as inst_id,
>                                    buckets.bucket_id,
>                                    met.metric_name,
>                                    met.value,
>                                    (LEAST(met.end_time_utc, 
>                                           buckets.end_time_utc) - 
>                                     GREATEST(met.begin_time_utc, 
>                                              buckets.begin_time_utc)) / 
>                                     (met.end_time_utc - met.begin_time_utc) 
>                                       as bucket_ratio
>                              FROM ( 
>                                    SELECT /*+ no_merge */ USERENV('INSTANCE') 
>                                                               as inst_id,
>                                           m.begin_time-tz.time_zone 
>                                                               as begin_time_utc,
>                                           m.end_time-tz.time_zone 
>                                                               as end_time_utc,
>                                           m.metric_name,
>                                           CASE 
>                                             WHEN m.metric_name = 
>                                                    'CPU Usage Per Sec' 
>                                             THEN m.value/100
>                                             ELSE m.value
>                                           END as value
>                                      FROM sys.v_$con_sysmetric_history m,
>                                           (SELECT ROUND(
>                                                     (cast(latest_sample_time 
>                                                           as date) - 
>                                                      cast(sys_extract_utc(
>                                                             systimestamp) 
>                                                           as date))
>                                                     *900,0)/900 as time_zone
>                                              FROM sys.v_$ash_info) tz
>                                     WHERE m.group_id = 18
>                                       AND m.metric_name IN 
>                                             ('Average Active Sessions',
>                                              'CPU Usage Per Sec',
>                                              'Executions Per Sec',
>                                              'User Calls Per Sec', 
>                                              'Total Parse Count Per Sec',
>                                              'User Commits Per Sec', 
>                                              'User Rollbacks Per Sec', 
>                                              'Session Count',
>                                              'Current Logons Count', 
>                                              'Logons Per Sec',
>                                              'Logons Per Txn',
>                                              'Redo Generated Per Sec',
>                                              'Redo Generated Per Txn',
>                                              'User Transaction Per Sec',
>                                              'Network Traffic Volume Per Sec',
>                                              'Hard Parse Count Per Sec',
>                                              'Parse Failure Count Per Sec',
>                                              'Current Open Cursors Count')
>                                       AND m.begin_time-tz.time_zone < 
>                                           to_date(:b_end_time_utc, :date_fmt)
>                                       AND m.end_time-tz.time_zone >= 
>                                           to_date(:b_start_time_utc, :date_fmt)
>                                   ) met,    
>                                   ( 
>                                    SELECT /*+ no_merge */ level as bucket_id,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           ((level -1) * :p_bucket_interval 
>                                            / 86400) as begin_time_utc,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           (level * :p_bucket_interval / 86400) 
>                                                     as end_time_utc
>                                      FROM sys.v_$instance 
>                                           -- note: DUAL not allowed inside GV$
>                                    CONNECT BY level <= 
>                                               (to_date(:b_end_time_utc,
>                                                        :date_fmt) - 
>                                                to_date(:b_start_time_utc, 
>                                                        :date_fmt)) 
>                                               * 86400 / :p_bucket_interval
>                                   ) buckets
>                             WHERE buckets.begin_time_utc < met.end_time_utc
>                               AND buckets.end_time_utc > met.begin_time_utc
>                            )
>                     GROUP BY bucket_id, metric_name)))),
>         db_data AS 
>           (SELECT bucket_id, metric_name, 
>                   SUM(value) as value
>              FROM inst_data
>            GROUP BY bucket_id, metric_name
>           ),
>         final_data AS
>           (SELECT bucket_id, metric_name,
>                   value AS value
>              FROM db_data
>             WHERE value > 0
>           ),
>         base_data AS
>           (SELECT * FROM final_data
>            ORDER BY bucket_id, metric_name)
>       select xmlelement("stattype",
>                xmlattributes('sysmetric' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")
>              ))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     SYSMETRIC_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var date_fmt          varchar2(32);
>       var b_start_time_utc  varchar2(32);
>       var b_end_time_utc    varchar2(32);
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_duration        number;
>       begin 
>         :date_fmt            := '#date_fmt#';
>         :b_start_time_utc    := '#b_start_time_utc#';
>         :b_end_time_utc      := '#b_end_time_utc#';
>         :p_bucket_interval   := #p_bucket_interval#;
>         :p_bucket_count      := #p_bucket_count#;
>         :b_duration          := #b_duration#;
>       end;
>       /]';
> 
>     
>     SYSMETRIC_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT s.instance_number, s.snap_id,
>                   s.metric_name,
>                   CASE 
>                     WHEN s.metric_name = 
>                            'CPU Usage Per Sec' 
>                     THEN s.average/100
>                     ELSE s.average
>                   END as value
>              FROM awr_root_con_sysmetric_summ s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.metric_name IN ('Average Active Sessions',
>                                     'CPU Usage Per Sec',
>                                     'Executions Per Sec',
>                                     'User Calls Per Sec', 
>                                     'Total Parse Count Per Sec',
>                                     'User Commits Per Sec', 
>                                     'User Rollbacks Per Sec', 
>                                     'Session Count',
>                                     'Current Logons Count', 
>                                     'Logons Per Sec',
>                                     'Logons Per Txn',
>                                     'Redo Generated Per Sec',
>                                     'Redo Generated Per Txn',
>                                     'User Transaction Per Sec',
>                                     'Network Traffic Volume Per Sec',
>                                     'Hard Parse Count Per Sec',
>                                     'Parse Failure Count Per Sec',
>                                     'Current Open Cursors Count')
>           ),
>         agg_stats AS
>           (SELECT /*+ no_merge */ instance_number, snap_id, metric_name, 
>                   SUM(value) as value
>              FROM base_stats
>             WHERE value > 0
>            GROUP BY instance_number, snap_id, metric_name
>           ),
>         snap_stats AS 
>           (SELECT a.instance_number, a.snap_id, a.metric_name, a.value,  
>                   s.begin_time_utc, s.end_time_utc
>              FROM agg_stats a, snaps s
>             WHERE a.instance_number = s.instance_number
>               AND a.snap_id = s.snap_id
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400) as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         db_stats AS
>           (SELECT bucket_id, metric_name, 
>                   SUM(value * bucket_ratio) as value
>              FROM (
>                    SELECT b.bucket_id, s.metric_name, s.value,
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM snap_stats s, buckets b
>                     WHERE b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, metric_name
>           ),
>         base_data AS 
>           (SELECT bucket_id, metric_name, value
>              FROM db_stats
>            ORDER BY 1, 2)
>       select xmlelement("stattype",
>                xmlattributes('sysmetric' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     SYSMETRIC_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
> 
>       L_QRY := SYSMETRIC_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := SYSMETRIC_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#', 
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('sysmetric', L_SQL);
> 
>       ELSE
> 
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>     
>     
>     ELSE
>      IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := SYSMETRIC_AWR;
> 
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := SYSMETRIC_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                      L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('sysmetric', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT),
>                 ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SYSMETRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_STORAGE_METRICS_XML(
>     SERVICE_TYPE IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL     IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     STORAGE_SERVERLESS CONSTANT VARCHAR2(32767) := q'[
>       select xmlelement("stattype",
>                xmlattributes(
>                  'storage'         as "name",
>                  max(c.max_size)   as "total",
>                  max(c.total_size) as "used",
>                  decode(max(c.max_size), 0, 0,
>                         (max(c.total_size)/max(c.max_size))*100) 
>                                    as "utilization"))
>         from sys.v_$containers c
>        where c.con_id > 2
>          and c.name <> 'PAASSEED']';
> 
>     
>     STORAGE_DEDICATED CONSTANT VARCHAR2(32767) := q'[
>       select xmlelement("stattype",
>                xmlattributes(
>                  'storage'         as "name",
>                  max(c.max_size)   as "total",
>                  max(c.total_size) as "used",
>                  decode(max(c.max_size), 0, 0,
>                         (max(c.total_size)/max(c.max_size))*100) 
>                                    as "utilization"),
>                xmlelement("tablespaces",
>                  xmlagg(
>                    xmlelement("tbs",
>                      xmlattributes(
>                        m.tablespace_name as "name",
>                        t.contents        as "type",
>                        ROUND((m.tablespace_size)*t.block_size, 3) total_space,
>                        ROUND((m.used_space)*t.block_size, 3) used_space,
>                        ROUND(m.used_percent, 2) used_pct)))))
>         from cdb_tablespace_usage_metrics m, 
>              cdb_tablespaces t,
>              sys.v_$containers c
>        where t.tablespace_name = m.tablespace_name
>          and c.con_id > 2
>          and c.name <> 'PAASSEED'
>          and m.con_id = c.con_id
>          and t.con_id = m.con_id]';
> 
>   BEGIN
> 
>     IF (SERVICE_TYPE IN (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D, 
>                          DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D)) THEN
>       L_QRY := STORAGE_DEDICATED;
>     ELSIF (SERVICE_TYPE IN (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S, 
>                             DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S)) THEN
>       L_QRY := STORAGE_SERVERLESS;
>     ELSE
>       L_QRY := STORAGE_DEDICATED;
>     END IF;
>    
>     
>     IF (SHOW_SQL = 1) THEN
> 
>       
>       L_SQL := L_QRY;
> 
>       
>       L_RESULT_XML := I_SHOW_SQL_XML('storage', L_SQL);
> 
>     ELSE
> 
>       
>       EXECUTE IMMEDIATE L_QRY
>                    INTO L_RESULT_XML;
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_STORAGE_METRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SESSION_METRICS_XML(
>     SHOW_SQL        IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
>   
>     
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML        XMLTYPE := NULL;
>     L_FAILED_LOGONS_XML XMLTYPE := NULL;
> 
>     
>     NUM_CONNECTIONS_RT CONSTANT VARCHAR2(32767) := q'[
>       SELECT xmlelement("stattype",
>                xmlattributes('session' as "name"),
>                xmlelement("num_connections", count(*)))
>         FROM sys.gv_$session s
>        WHERE UPPER(s.service_name) not in 
>              (SELECT p.name FROM sys.v_$pdbs p WHERE p.con_id=s.con_id) 
>          AND UPPER(s.service_name) not in ('SYS$BACKGROUND','SYS$USERS') 
>          AND s.type='USER'
>          AND s.sid not in 
>              (SELECT ps.sid FROM sys.gv_$px_session ps)]';
> 
>     
>     NUM_FAILED_LOGONS_RT CONSTANT VARCHAR2(32767) := q'[
>       SELECT xmlelement("failed_logons", count(*))
>         FROM cdb_unified_audit_trail
>        WHERE action_name = 'LOGON'
>          AND return_code != 0]';
> 
>   BEGIN
>      
>     
>     IF (SHOW_SQL = 1) THEN
> 
>       L_SQL := NUM_CONNECTIONS_RT || NUM_FAILED_LOGONS_RT;
> 
>       
>       L_RESULT_XML := I_SHOW_SQL_XML('session', L_SQL);
> 
>     ELSE
> 
>       
>       EXECUTE IMMEDIATE NUM_CONNECTIONS_RT
>                    INTO L_RESULT_XML;
> 
>       EXECUTE IMMEDIATE NUM_FAILED_LOGONS_RT
>                    INTO L_FAILED_LOGONS_XML;
> 
>       IF (L_FAILED_LOGONS_XML IS NOT NULL) THEN
>         L_RESULT_XML := L_RESULT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                     L_FAILED_LOGONS_XML);
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SESSION_METRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION REPORT_WORKLOAD(
>     SERVICE_TYPE   IN VARCHAR2 DEFAULT NULL,
>     IS_REALTIME    IN NUMBER   DEFAULT 1,
>     DBID           IN NUMBER   DEFAULT NULL,
>     START_TIME     IN DATE     DEFAULT NULL,
>     END_TIME       IN DATE     DEFAULT NULL,
>     REPORT_LEVEL   IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL       IN NUMBER   DEFAULT 0)
>   RETURN XMLTYPE
>   IS
>     
>     L_ELAPSED NUMBER;
>     L_CPU     NUMBER;
> 
>     
>     L_REF_PARAMS DBMS_REPORT.REF_STRING_IDSPEC;
> 
>     
>     L_ORIG_ENV DBMS_REPORT.FORMAT_PARAM_VALUES;
>     L_SET_ENV  BOOLEAN;
> 
>     
>     L_REPORT_XML          XMLTYPE := NULL;
>     L_RM_METRICS_XML      XMLTYPE := NULL;
>     L_SYS_METRICS_XML     XMLTYPE := NULL;
>     L_SQL_TIME_XML        XMLTYPE := NULL;
>     L_WAIT_TIME_XML       XMLTYPE := NULL;
>     L_STORAGE_METRICS_XML XMLTYPE := NULL;
>     L_SESSION_METRICS_XML XMLTYPE := NULL;
> 
>     
>     L_SERVICE_TYPE   VARCHAR2(32767) := SERVICE_TYPE;
>     L_IS_REALTIME    NUMBER          := IS_REALTIME;
>     L_DBID           NUMBER          := DBID;
>     L_START_TIME     DATE            := START_TIME;
>     L_END_TIME       DATE            := END_TIME;
>     L_REPORT_LEVEL   VARCHAR2(32767) := REPORT_LEVEL;
>     L_TZ             VARCHAR2(10)    := NULL;
>     L_START_TIME_UTC DATE            := NULL;
>     L_END_TIME_UTC   DATE            := NULL;
>     L_BEGIN_SNAP_ID  NUMBER          := NULL;
>     L_END_SNAP_ID    NUMBER          := NULL;
> 
>     
>     L_BUCKET_COUNT    NUMBER;
>     L_BUCKET_INTERVAL NUMBER;
> 
>     
>     L_AWR_PERIOD PRVT_AWRV_METADATA;
> 
>     L_SNAP_QRY        VARCHAR2(32767) := NULL;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)    := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_ERRMSG    VARCHAR2(32767);
>     L_ERROR_XML XMLTYPE := NULL;
> 
>     
>     L_RSRCMGR_DETAIL   NUMBER;
>     L_SYSMETRIC_DETAIL NUMBER;
>     L_SQL_TIME_DETAIL  NUMBER;
>     L_WAIT_TIME_DETAIL NUMBER;
>     L_STORAGE_DETAIL   NUMBER;
>     L_SESSION_DETAIL   NUMBER;
> 
>     
>     
>     
>     FUNCTION I_PARSE_REPORT_LEVEL(
>       P_REPORT_LEVEL     IN  VARCHAR2,
>       P_RSRCMGR_DETAIL   OUT NUMBER,
>       P_SYSMETRIC_DETAIL OUT NUMBER,
>       P_SQL_TIME_DETAIL  OUT NUMBER,
>       P_WAIT_TIME_DETAIL OUT NUMBER,
>       P_STORAGE_DETAIL   OUT NUMBER,
>       P_SESSION_DETAIL   OUT NUMBER)
>     RETURN BOOLEAN
>     IS
>       L_REPORT_LEVEL VARCHAR2(32767) := 
>         REPLACE(LOWER(P_REPORT_LEVEL), ' ', NULL);
>       L_POS          NUMBER := 1;
>       L_SETVAL       NUMBER;
>     BEGIN
>       
>       P_RSRCMGR_DETAIL   := 1; 
>       P_SYSMETRIC_DETAIL := 1; 
>       P_SQL_TIME_DETAIL  := 1; 
>       P_WAIT_TIME_DETAIL := 1; 
>       P_STORAGE_DETAIL   := 1; 
>       P_SESSION_DETAIL   := 1; 
> 
>        
>       IF (L_REPORT_LEVEL IS NULL) THEN
>         RETURN TRUE;
>       END IF;
> 
>       
>       L_POS := 1;
> 
>       
>       IF (SUBSTR(L_REPORT_LEVEL, L_POS, 3) = 'all') THEN
>         
>         
>         L_POS := L_POS + 3;
>       
>       ELSIF (SUBSTR(L_REPORT_LEVEL, L_POS, 4) = 'none') THEN
>         P_RSRCMGR_DETAIL := 0;
>         P_SYSMETRIC_DETAIL := 0;
>         P_SQL_TIME_DETAIL := 0;
>         P_WAIT_TIME_DETAIL := 0;
>         P_STORAGE_DETAIL := 0;
>         P_SESSION_DETAIL := 0;
>         L_POS := L_POS + 4;
>       END IF;
> 
>       
>       WHILE (L_POS < LENGTH(L_REPORT_LEVEL))
>       LOOP
>         IF (SUBSTR(L_REPORT_LEVEL, L_POS, 1) = '-') THEN
>           L_SETVAL   := 0;
>           L_POS      := L_POS + 1;
>         ELSE
>           L_SETVAL   := 1;
>           IF (SUBSTR(L_REPORT_LEVEL, L_POS, 1) = '+') THEN
>             L_POS := L_POS + 1;
>           END IF;
>         END IF;
> 
>         CASE
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'rsrcmgr') THEN
>             P_RSRCMGR_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 9) = 'sysmetric') THEN
>             P_SYSMETRIC_DETAIL := L_SETVAL;
>             L_POS := L_POS + 9;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 3) = 'sql') THEN
>             P_SQL_TIME_DETAIL := L_SETVAL;
>             L_POS := L_POS + 3;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 4) = 'wait') THEN
>             P_WAIT_TIME_DETAIL := L_SETVAL;
>             L_POS := L_POS + 4;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'storage') THEN
>             P_STORAGE_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'session') THEN
>             P_SESSION_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
>             
>           ELSE
>             
>             RETURN FALSE;
>         END CASE;
>       END LOOP;
> 
>       
>       RETURN TRUE;
>       
>     END I_PARSE_REPORT_LEVEL;
> 
>   BEGIN
>     
>     
>     L_ORIG_ENV := DBMS_REPORT.FORMAT_PARAM_VALUES();
>     L_SET_ENV  := DBMS_REPORT.SETUP_REPORT_ENV(L_ORIG_ENV);
> 
>     
>     DBMS_REPORT.GET_TIMING_INFO(0, L_ELAPSED, L_CPU);
> 
>     
> 
>     
>     IF (SERVICE_TYPE IS NOT NULL) THEN
>       L_REF_PARAMS('service_type') := SERVICE_TYPE;
>     END IF;
> 
>     IF (IS_REALTIME IS NOT NULL) THEN
>       L_REF_PARAMS('is_realtime') := IS_REALTIME;
>     END IF;
> 
>     IF (DBID IS NOT NULL) THEN
>       L_REF_PARAMS('dbid') := DBID;
>     END IF;
> 
>     IF (START_TIME IS NOT NULL) THEN
>       L_REF_PARAMS('start_time') :=
>         TO_CHAR(START_TIME,DBMS_REPORT.DATE_FMT_MOD);
>     END IF;
> 
>     IF (END_TIME IS NOT NULL) THEN
>       L_REF_PARAMS('end_time') :=
>         TO_CHAR(END_TIME,DBMS_REPORT.DATE_FMT_MOD);
>     END IF;
> 
>     IF (REPORT_LEVEL IS NOT NULL) THEN
>       L_REF_PARAMS('report_level') := REPORT_LEVEL;
>     END IF;
> 
>     IF (SHOW_SQL IS NOT NULL) THEN
>       L_REF_PARAMS('show_sql') := SHOW_SQL; 
>     END IF;
>    
>     
>     
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     IF (DBID IS NULL) THEN
>       L_DBID := SYS_CONTEXT('USERENV','CON_DBID');
>     END IF;
> 
>     
>     IF (REPORT_LEVEL IS NULL) THEN
>       L_REPORT_LEVEL := 'all';
>     END IF;
> 
>     
>     IF (END_TIME IS NULL) THEN
>       L_END_TIME := SYSDATE;
>     END IF;
> 
>     
>     IF (START_TIME IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME := L_END_TIME - 1/24;
>       
>       ELSE
>         L_START_TIME := L_END_TIME - 1;
>       END IF;
>     END IF;
> 
>     
>     L_TZ := DBMS_SQLTUNE_UTIL2.GET_TZ_OFFSET();
>     L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(
>                             TO_TIMESTAMP_TZ(
>                               TO_CHAR(L_END_TIME, 'yyyy-mm-dd hh24:mi:ss') 
>                               || L_TZ,
>                               'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE);
> 
> 
>     
>     L_START_TIME_UTC := CAST(SYS_EXTRACT_UTC(
>                               TO_TIMESTAMP_TZ(
>                                 TO_CHAR(L_START_TIME, 'yyyy-mm-dd hh24:mi:ss') 
>                                 || L_TZ,
>                                 'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE);
> 
>     
>     IF (L_IS_REALTIME = 1) THEN
>       CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
>                         (L_END_TIME - L_START_TIME)*DTOS,
>                         G_METRIC_SOURCE_HISTORY);
>     ELSE
>       
>       CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
>                         (L_END_TIME - L_START_TIME)*DTOS,
>                         NULL);
> 
>       
>       L_SNAP_QRY := q'[
>         SELECT MIN(snap_id)-1, MAX(snap_id)
>           FROM awr_root_snapshot
>          WHERE dbid = :l_dbid
>            AND cast((end_interval_time_tz at time zone 'UTC') as DATE)
>                 > to_date(:l_start_time_utc, :date_fmt)
>            AND cast((begin_interval_time_tz at time zone 'UTC') as DATE)
>                 < to_date(:l_end_time_utc, :date_fmt)]';
> 
>       IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>         L_AWR_VIEW_PREFIX := 
>           DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_START_TIME);
> 
>         DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_SNAP_QRY, 
>                                                    L_AWR_VIEW_PREFIX);
>       END IF;
> 
>       IF (L_AWR_VIEW_PREFIX = DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT) THEN
>         L_DBID := SYS_CONTEXT('USERENV','DBID');
>       END IF;
> 
>       BEGIN
>         EXECUTE IMMEDIATE L_SNAP_QRY
>         INTO L_BEGIN_SNAP_ID, L_END_SNAP_ID
>         USING L_DBID, 
>               TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>               TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT;
>       EXCEPTION
>         WHEN NO_DATA_FOUND THEN
>           L_BEGIN_SNAP_ID := NULL;
>           L_END_SNAP_ID := NULL;
>       END;
> 
>       
>       
>       L_AWR_PERIOD := PRVT_AWRV_METADATA(P_START_TIME => L_START_TIME, 
>                                          P_END_TIME => L_END_TIME,
>                                          P_DBID => L_DBID);
> 
>       L_AWR_PERIOD.M_BEGIN_SNAP := L_BEGIN_SNAP_ID;
>       L_AWR_PERIOD.M_END_SNAP := L_END_SNAP_ID;
>       L_AWR_PERIOD.M_MIN_TIME := L_START_TIME;
>       L_AWR_PERIOD.M_MAX_TIME := L_END_TIME;
> 
>       
>       IF (L_AWR_PERIOD.M_BEGIN_SNAP IS NULL OR
>           L_AWR_PERIOD.M_BEGIN_SNAP = L_AWR_PERIOD.M_END_SNAP)
>       THEN
> 
>         L_ERRMSG := '[' || L_AWR_PERIOD.M_DBID || ']' ||
>                     '[' || L_AWR_PERIOD.M_INST_ID_LOW || '.' ||
>                            L_AWR_PERIOD.M_INST_ID_HIGH || ']' ||
>                     '[' || L_AWR_PERIOD.M_BEGIN_SNAP || '.' || 
>                            L_AWR_PERIOD.M_END_SNAP || ']' ||
>                     '[' || TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, 
>                                    DBMS_REPORT.DATE_FMT) || '-' ||
>                            TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, 
>                                    DBMS_REPORT.DATE_FMT) || ']';
>         
>         L_AWR_PERIOD := NULL;
> 
>         
>         L_ERROR_XML := ERROR_XML('report_workload',
>                                  -20800,
>                                  'Insufficient awr data', 
>                                  L_ERRMSG);
>       ELSE
> 
>         L_ERRMSG := NULL;
>         L_ERROR_XML := NULL;
> 
>       END IF;
> 
>     END IF;
> 
>     
>     IF (NOT I_PARSE_REPORT_LEVEL(L_REPORT_LEVEL, L_RSRCMGR_DETAIL, 
>                                  L_SYSMETRIC_DETAIL, L_SQL_TIME_DETAIL,
>                                  L_WAIT_TIME_DETAIL, L_STORAGE_DETAIL,
>                                  L_SESSION_DETAIL)) THEN
>       SYS.DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(SYS_ERR_PARAM, 'report_level');
>     END IF;
> 
>     
>     IF (L_RSRCMGR_DETAIL = 1) THEN
>       L_RM_METRICS_XML := GET_RMMETRICS_XML(L_IS_REALTIME, 
>                                             L_DBID,
>                                             L_START_TIME,
>                                             L_END_TIME,
>                                             L_BUCKET_COUNT,
>                                             L_BUCKET_INTERVAL,
>                                             L_AWR_PERIOD,
>                                             SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_SYSMETRIC_DETAIL = 1) THEN        
>         L_SYS_METRICS_XML := GET_SYSMETRICS_XML(L_IS_REALTIME,
>                                                 L_DBID,
>                                                 L_START_TIME_UTC,
>                                                 L_END_TIME_UTC,
>                                                 L_BUCKET_COUNT,
>                                                 L_BUCKET_INTERVAL,
>                                                 L_AWR_PERIOD,
>                                                 SHOW_SQL);
>     END IF;
> 
>     
>     
>     
>     
>     
>     IF (L_SQL_TIME_DETAIL = 1) THEN
>       L_SQL_TIME_XML := GET_SQL_N_PARSE_TIME_XML(L_IS_REALTIME,
>                                                  L_DBID,
>                                                  L_START_TIME_UTC,
>                                                  L_END_TIME_UTC,
>                                                  L_BUCKET_COUNT,
>                                                  L_BUCKET_INTERVAL,
>                                                  L_AWR_PERIOD,
>                                                  SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_WAIT_TIME_DETAIL = 1) THEN
>       L_WAIT_TIME_XML := GET_WAIT_TIME_XML(L_IS_REALTIME,
>                                            L_DBID,
>                                            L_START_TIME_UTC,
>                                            L_END_TIME_UTC,
>                                            L_BUCKET_COUNT,
>                                            L_BUCKET_INTERVAL,
>                                            L_AWR_PERIOD,
>                                            SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_STORAGE_DETAIL = 1) THEN
>       L_STORAGE_METRICS_XML := GET_STORAGE_METRICS_XML(L_SERVICE_TYPE,
>                                                        SHOW_SQL);
>     END IF;
> 
>     
>     
>     
>     IF (L_SESSION_DETAIL = 1) THEN
>       L_SESSION_METRICS_XML := GET_SESSION_METRICS_XML(SHOW_SQL);
>     END IF;
> 
>     
>     DBMS_REPORT.GET_TIMING_INFO(1, L_ELAPSED, L_CPU);
> 
>     
>     
>     L_REPORT_XML :=
>       PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
>                          DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
>                            'awrv','topsql', L_REF_PARAMS),
>                          L_ELAPSED, L_CPU);
> 
>     
>     
>     IF (L_RM_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_RM_METRICS_XML);
>     END IF;
> 
>     IF (L_SYS_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_SYS_METRICS_XML);
>     END IF;
> 
>     IF (L_SQL_TIME_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_SQL_TIME_XML);
>     END IF;
> 
>     IF (L_WAIT_TIME_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_WAIT_TIME_XML);
>     END IF;
> 
>     IF (L_STORAGE_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_STORAGE_METRICS_XML);
>     END IF;
>     
>     IF (L_SESSION_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_SESSION_METRICS_XML);
>     END IF;
> 
>     IF (L_ERROR_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_ERROR_XML);
>     END IF;
> 
>     <<DONE>>
>     
>     
>     IF (L_REPORT_XML IS NULL) THEN
>       
>       L_REPORT_XML :=
>         PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
>           DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
>             'awrv','topsql',L_REF_PARAMS),
>           NULL, NULL);
>     END IF;
> 
>     IF (L_SET_ENV) THEN
>       
>       DBMS_REPORT.RESTORE_REPORT_ENV(L_ORIG_ENV);
>     END IF;
>  
>     
>     RETURN L_REPORT_XML;
> 
>   END REPORT_WORKLOAD;
> 
> 
SYS.PRVT_AWRV_METADATA - TYPE BODY (RU):
288,290c288,294
<         IF (M_RESOLVED_DB_TYPE 
<           IN (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, 
<                 DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP))
---
> 
>         IF (M_RESOLVED_DB_TYPE IN
>               (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, 
>                DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP)
>             AND
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(P_START_TIME) = 
>               DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB)
432c436,438
<     IF (SYS.DBMS_SQLTUNE_UTIL0.CDB_IS_PDB(L_CON_NAME, L_CON_ID)) THEN  
---
>     IF (SYS.DBMS_SQLTUNE_UTIL0.CDB_IS_PDB(L_CON_NAME, L_CON_ID) AND
>         DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(P_START_TIME) = 
>           DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB) THEN  
SYS.WRI$_REPT_AWRV - TYPE BODY (RU):
62a63,65
>     P_INCLUDE_SQLS     NUMBER := 1;
>     P_JET              NUMBER := 0;
>     L_SERVICE_TYPE     VARCHAR2(32);
532,537d534
<       P_LAST_REFRESH_TIME := TO_DATE(
<                                DBMS_REPORT.GET_PARAM(PARAMS,
<                                                       'last_refresh_time',
<                                                       NULLABLE=>TRUE),
<                                DBMS_REPORT.DATE_FMT_MOD);
< 
539,540c536
<       P_INST_ID := TO_NUMBER(
<                      DBMS_REPORT.GET_PARAM(PARAMS,'inst_id',NULLABLE=>TRUE));
---
>       P_DBID := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'dbid',NULLABLE=>TRUE));
543c539,540
<       P_DBID := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'dbid',NULLABLE=>TRUE));
---
>       P_INST_ID := TO_NUMBER(
>                        DBMS_REPORT.GET_PARAM(PARAMS,'inst_id',NULLABLE=>TRUE));
553a551
>       L_SERVICE_TYPE := DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE();
556,557c554
<       P_TOP_N_DETAIL := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'top_n_detail',
<                                                    NULLABLE=>TRUE));
---
>       P_JET := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'is_jet', NULLABLE=>TRUE));
560,564d556
<       P_OUTER_START_TIME := TO_DATE(
<                               DBMS_REPORT.GET_PARAM(PARAMS,'outer_start_time',
<                                                     NULLABLE=>TRUE),
<                               DBMS_REPORT.DATE_FMT_MOD);
< 
566,569c558,577
<       P_OUTER_END_TIME := TO_DATE(
<                       DBMS_REPORT.GET_PARAM(PARAMS,'outer_end_time',
<                                                     NULLABLE=>TRUE),
<                             DBMS_REPORT.DATE_FMT_MOD);
---
>       IF (P_JET = 1 OR
>           (L_SERVICE_TYPE IN 
>             (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D)
>            AND SYS_CONTEXT('USERENV', 'CON_ID') > 2)) THEN
> 
>         
>         P_REPORT_LEVEL := DBMS_REPORT.GET_PARAM(PARAMS,'report_level',
>                                                 NULLABLE=>TRUE);
> 
>         REPORT_XML := PRVT_AWR_VIEWER.REPORT_WORKLOAD(
>                         SERVICE_TYPE => L_SERVICE_TYPE,
>                         IS_REALTIME  => P_IS_REALTIME,
>                         START_TIME   => P_START_TIME,
>                         END_TIME     => P_END_TIME,
>                         DBID         => P_DBID,
>                         REPORT_LEVEL => P_REPORT_LEVEL,
>                         SHOW_SQL     => P_SHOW_SQL);
572,573c580
<       P_DIM_NAME := DBMS_REPORT.GET_PARAM(PARAMS,'dim_name',NULLABLE=>TRUE);
<       P_DIM_STAT := DBMS_REPORT.GET_PARAM(PARAMS,'dim_stat',NULLABLE=>TRUE);
---
>       ELSE
575,587c582,601
<       REPORT_XML := PRVT_AWR_VIEWER.REPORT_TOPSQL_XML(
<                       START_TIME        => P_START_TIME,
<                       END_TIME          => P_END_TIME,
<                       LAST_REFRESH_TIME => P_LAST_REFRESH_TIME,
<                       INST_ID           => P_INST_ID,
<                       DBID              => P_DBID,
<                       IS_REALTIME       => P_IS_REALTIME,
<                       TOP_N_DETAIL      => P_TOP_N_DETAIL,
<                       OUTER_START_TIME  => P_OUTER_START_TIME,
<                       OUTER_END_TIME    => P_OUTER_END_TIME,
<                       DIM_NAME          => P_DIM_NAME,
<                       DIM_STAT          => P_DIM_STAT,
<                       SHOW_SQL          => P_SHOW_SQL);
---
>         
>         P_INCLUDE_SQLS := TO_NUMBER(
>                             DBMS_REPORT.GET_PARAM(PARAMS,'include_sqls', 
>                                                   NULLABLE=>TRUE));
> 
>         P_LAST_REFRESH_TIME := TO_DATE(
>                                  DBMS_REPORT.GET_PARAM(PARAMS,
>                                                         'last_refresh_time',
>                                                         NULLABLE=>TRUE),
>                                  DBMS_REPORT.DATE_FMT_MOD);
> 
>         
>         P_TOP_N_DETAIL := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'top_n_detail',
>                                                      NULLABLE=>TRUE));
> 
>         
>         P_OUTER_START_TIME := TO_DATE(
>                                 DBMS_REPORT.GET_PARAM(PARAMS,'outer_start_time',
>                                                       NULLABLE=>TRUE),
>                                 DBMS_REPORT.DATE_FMT_MOD);
588a603,627
>         
>         P_OUTER_END_TIME := TO_DATE(
>                               DBMS_REPORT.GET_PARAM(PARAMS,'outer_end_time',
>                                                     NULLABLE=>TRUE),
>                               DBMS_REPORT.DATE_FMT_MOD);
> 
>         
>         P_DIM_NAME := DBMS_REPORT.GET_PARAM(PARAMS,'dim_name',NULLABLE=>TRUE);
>         P_DIM_STAT := DBMS_REPORT.GET_PARAM(PARAMS,'dim_stat',NULLABLE=>TRUE);
> 
>         REPORT_XML := PRVT_AWR_VIEWER.REPORT_TOPSQL_XML(
>                         START_TIME        => P_START_TIME,
>                         END_TIME          => P_END_TIME,
>                         LAST_REFRESH_TIME => P_LAST_REFRESH_TIME,
>                         INST_ID           => P_INST_ID,
>                         DBID              => P_DBID,
>                         IS_REALTIME       => P_IS_REALTIME,
>                         TOP_N_DETAIL      => P_TOP_N_DETAIL,
>                         OUTER_START_TIME  => P_OUTER_START_TIME,
>                         OUTER_END_TIME    => P_OUTER_END_TIME,
>                         DIM_NAME          => P_DIM_NAME,
>                         DIM_STAT          => P_DIM_STAT,
>                         INCLUDE_SQLS      => P_INCLUDE_SQLS,
>                         SHOW_SQL          => P_SHOW_SQL);
>       END IF;

19.0.0.0

DVSYS.DBMS_MACADM - PACKAGE BODY (RU):
2570a2571,2576
>     
>     
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PATCH%' THEN
>       RETURN 'Y';
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PARAMETER%' THEN
>       RETURN 'Y';
MDSYS.SDO_JOIN - FUNCTION (RU):
495,498c495,503
<         FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
---
>         IF ( IPTN1 IS NULL ) THEN
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE);
>         ELSE
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
>         END IF;
506,509c511,519
<         FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
---
>         IF ( IPTN2 IS NULL ) THEN
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE);
>         ELSE
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
>         END IF;
517,520c527,535
<         FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
---
>         IF ( IPTN1 IS NULL ) THEN
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE);
>         ELSE
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
>         END IF;
528,531c543,551
<         FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
---
>         IF ( IPTN2 IS NULL ) THEN
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE);
>         ELSE
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
>         END IF;
SYS.DBMS_BACKUP_RESTORE - PACKAGE (18.9RUR):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '18.09.01.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '18.09.02.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('18.09.01.00', '.');
<   msn  CONSTANT NUMBER := instr('18.09.01.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('18.09.01.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('18.09.02.00', '.');
>   msn  CONSTANT NUMBER := instr('18.09.02.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('18.09.02.00', '.', msn + 1);
29c29
<                            to_number(substr('18.09.01.00', 1, fsn - 1));
---
>                            to_number(substr('18.09.02.00', 1, fsn - 1));
31c31
<                to_number(substr('18.09.01.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('18.09.02.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('18.09.01.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('18.09.02.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('18.09.01.00',  psn + 1));
---
>                              to_number(substr('18.09.02.00',  psn + 1));
SYS.DBMS_BACKUP_RESTORE - PACKAGE (18.10RUR):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '18.10.00.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '18.10.01.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('18.10.00.00', '.');
<   msn  CONSTANT NUMBER := instr('18.10.00.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('18.10.00.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('18.10.01.00', '.');
>   msn  CONSTANT NUMBER := instr('18.10.01.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('18.10.01.00', '.', msn + 1);
29c29
<                            to_number(substr('18.10.00.00', 1, fsn - 1));
---
>                            to_number(substr('18.10.01.00', 1, fsn - 1));
31c31
<                to_number(substr('18.10.00.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('18.10.01.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('18.10.00.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('18.10.01.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('18.10.00.00',  psn + 1));
---
>                              to_number(substr('18.10.01.00',  psn + 1));
SYS.DBMS_BACKUP_RESTORE - PACKAGE (RU):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '18.10.00.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '18.11.00.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('18.10.00.00', '.');
<   msn  CONSTANT NUMBER := instr('18.10.00.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('18.10.00.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('18.11.00.00', '.');
>   msn  CONSTANT NUMBER := instr('18.11.00.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('18.11.00.00', '.', msn + 1);
29c29
<                            to_number(substr('18.10.00.00', 1, fsn - 1));
---
>                            to_number(substr('18.11.00.00', 1, fsn - 1));
31c31
<                to_number(substr('18.10.00.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('18.11.00.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('18.10.00.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('18.11.00.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('18.10.00.00',  psn + 1));
---
>                              to_number(substr('18.11.00.00',  psn + 1));
SYS.DBMS_REGISTRY - PACKAGE (18.9RUR):
13c13
<                                '18.9.1.0.0';
---
>                                '18.9.2.0.0';
SYS.DBMS_REGISTRY - PACKAGE (18.10RUR):
13c13
<                                '18.10.0.0.0';
---
>                                '18.10.1.0.0';
SYS.DBMS_REGISTRY - PACKAGE (RU):
13c13
<                                '18.10.0.0.0';
---
>                                '18.11.0.0.0';
SYS.DBMS_REPORT - PACKAGE (RU):
667c667,672
<   --
---
>   --    p_cloud_service_type
>   --                     (OUT)  - 0 NONE
>   --                              1 DWCS (Autonomous Data Warehouse)
>   --                              2 EECS (Exadata Express Cloud Service)
>   --                              3 PAAS (Platform As A Service (MDBCS))
>   --                              4 OLTP (ATP)
678c683,684
<     p_packs                 OUT      NUMBER
---
>     p_packs                 OUT      NUMBER,
>     p_cloud_service_type    OUT      NUMBER
SYS.DBMS_SQLTUNE_UTIL2 - PACKAGE (RU):
15a16,23
>   -- Cloud Service Type Constants
>   CLOUD_SERVICE_TYPE_NONE    CONSTANT VARCHAR2(30) := 'NONE';
>   CLOUD_SERVICE_TYPE_ADW_D   CONSTANT VARCHAR2(30) := 'ADW-D';
>   CLOUD_SERVICE_TYPE_ADW_S   CONSTANT VARCHAR2(30) := 'ADW-S';
>   CLOUD_SERVICE_TYPE_ATP_D   CONSTANT VARCHAR2(30) := 'ATP-D';
>   CLOUD_SERVICE_TYPE_ATP_S   CONSTANT VARCHAR2(30) := 'ATP-S';
>   CLOUD_SERVICE_TYPE_OTHER   CONSTANT VARCHAR2(30) := 'OTHER';
> 
313a322,381
> 
>   -------------------------- get_cloud_service_type  --------------------------
>   -- NAME:
>   --     get_cloud_service_type
>   --
>   -- DESCRIPTION:
>   --     return value of _cloud_service_type parameter for cloud service type
>   --
>   -- RETURN:
>   --   CLOUD_SERVICE_TYPE_NONE    =>  'NONE';
>   --   CLOUD_SERVICE_TYPE_ADW_D   =>  'ADW-D';
>   --   CLOUD_SERVICE_TYPE_ADW_S   =>  'ADW-S';
>   --   CLOUD_SERVICE_TYPE_ATP_D   =>  'ATP-D';
>   --   CLOUD_SERVICE_TYPE_ATP_S   =>  'ATP-S';
>   --   CLOUD_SERVICE_TYPE_OTHER   =>  'OTHER';
>   -----------------------------------------------------------------------------
>   FUNCTION get_cloud_service_type
>   RETURN varchar2;
> 
>   -------------------------- get_tz_offset  -----------------------------------
>   -- NAME:
>   --     get_tz_offset
>   --
>   -- DESCRIPTION:
>   --     get timezone offset from systimestamp
>   --
>   -- RETURN:
>   --     timezone offset in TZ_HOUR:TZ_MINUTE format
>   -----------------------------------------------------------------------------
>   FUNCTION get_tz_offset
>   RETURN VARCHAR2;
> 
>   ----------------------------- chooseAwrForPdb -------------------------
>   -- NAME:
>   --     chooseAwrForPdb
>   --
>   -- DESCRIPTION:
>   --     This function determines the location/prefix of the AWR view to use
>   --     for the database considering the following conditions:
>   --     1. Check whether local awr_pdb has snapshots.
>   --        If not, return AWR_VIEW_ROOT
>   --     2. If local awr has some snapshots use AWR_VIEW_PDB
>   --     3. If by change local awr was stopped/disabled for some time
>   --         (say for eg., last 3 hrs not local awr snapshots)
>   --         then use AWR_VIEW_ROOT
>   --
>   --
>   -- NOTE: The beginTime and endTime used are in DB Timezone.
>   --       Unlike the case of ASH, no need to convert to UTC,
>   --       since end_interval_time in awr_root, awr_pdb  are in same TZ
>   --
>   -- PARAMETERS:
>   --     dbid            (IN)  - database id
>   --
>   -- RETURN:
>   --     Returned type can be 'AWR_ROOT' or 'AWR_PDB'.
>   --
>   -----------------------------------------------------------------------------
>   FUNCTION chooseAwrForPdb(beginTime IN DATE)
>   RETURN VARCHAR2;
SYS.PRVT_AWR_VIEWER - PACKAGE (RU):
417a418,419
>   
>   
429a432
>     INCLUDE_SQLS      IN NUMBER         DEFAULT NULL,
882a886,904
>   PROCEDURE CREATE_CONSUMER_GROUP_MAP(
>     P_CON_ID     IN     NUMBER,
>     P_AWR_PERIOD IN OUT NOCOPY PRVT_AWRV_METADATA,
>     P_CGRP_MAP   IN OUT NOCOPY PRVT_AWRV_INSTTAB);
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
911a934,1153
>   RETURN XMLTYPE;
> 
>   
>   
>   
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_RMMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME      IN DATE               DEFAULT NULL,
>     END_TIME        IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT 0)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SQL_N_PARSE_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_WAIT_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SYSMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_STORAGE_METRICS_XML(
>     SERVICE_TYPE IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL     IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SESSION_METRICS_XML(
>     SHOW_SQL        IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION REPORT_WORKLOAD(
>     SERVICE_TYPE   IN VARCHAR2 DEFAULT NULL,
>     IS_REALTIME    IN NUMBER   DEFAULT 1,
>     DBID           IN NUMBER   DEFAULT NULL,
>     START_TIME     IN DATE     DEFAULT NULL,
>     END_TIME       IN DATE     DEFAULT NULL,
>     REPORT_LEVEL   IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL       IN NUMBER   DEFAULT 0)
SYS.DBMS_RCVMAN - PACKAGE BODY (18.9RUR):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '18.09.01.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '18.09.02.00'; 
SYS.DBMS_RCVMAN - PACKAGE BODY (RU):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '18.10.00.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '18.11.00.00'; 
6266c6266
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6472c6472
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6634c6634
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6721c6721
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
7871,7884d7870
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7924c7910,7922
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
8079c8077,8089
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
SYS.DBMS_RCVMAN - PACKAGE BODY (18.10RUR):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '18.10.00.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '18.10.01.00'; 
SYS.DBMS_REPORT - PACKAGE BODY (RU):
1055a1056,1060
>   EXCEPTION
>     WHEN OTHERS THEN
>       CONTENT_TYPE := CONTENT_TYPE_XML;
>       RETURN XMLTYPE('<mesg type="oraerr">'|| SQLERRM || 
>                      '</mesg>').GETCLOBVAL();
2011a2017,2021
>   
>   
>   
>   
>   
2021c2031,2032
<     P_PACKS                 OUT      NUMBER
---
>     P_PACKS                 OUT      NUMBER,
>     P_CLOUD_SERVICE_TYPE    OUT      NUMBER
2257a2269,2299
>     
>     IF (V_RESOLVED_DB_TYPE
>         IN (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP)) 
>     THEN
>         SELECT CASE MAX(VALUE)
>                  WHEN 'DWCS' THEN 1
>                  WHEN 'EECS' THEN 2
>                  WHEN 'PAAS' THEN 3
>                  WHEN 'OLTP' THEN 4
>                  ELSE 0
>                END
>           INTO P_CLOUD_SERVICE_TYPE
>           FROM SYS.AWR_PDB_PARAMETER
>          WHERE DBID = P_DBID
>            AND SNAP_ID = V_END_SNAP
>            AND PARAMETER_NAME = '_cloud_service_type';
>     ELSE
>         SELECT CASE MAX(VALUE)
>                  WHEN 'DWCS' THEN 1
>                  WHEN 'EECS' THEN 2
>                  WHEN 'PAAS' THEN 3
>                  WHEN 'OLTP' THEN 4
>                  ELSE 0
>                END
>           INTO P_CLOUD_SERVICE_TYPE
>           FROM SYS.AWR_ROOT_PARAMETER
>          WHERE DBID = P_DBID
>            AND SNAP_ID = V_END_SNAP
>            AND PARAMETER_NAME = '_cloud_service_type';
>     END IF;
>       
SYS.DBMS_SQLTUNE - PACKAGE BODY (RU):
25990a25991,26033
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
> 
>     IF ( (LOCAL_DB = 1) 
>           AND
>          (DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE() IN 
>           (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D))
>           AND 
>          (DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(START_TIME) = 
>                         DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB)
>        )
>     THEN  
>         TARGET_DBID := CON_DBID;
>     END IF;
> 
>     
SYS.DBMS_SQLTUNE_UTIL2 - PACKAGE BODY (RU):
593a594,750
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_CLOUD_SERVICE_TYPE
>   RETURN VARCHAR2
>   IS
>     CLOUD_SERVICE_TYPE VARCHAR2(32);
>   BEGIN
> 
>     SELECT 
>       CASE 
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='PAAS' THEN
>           CASE 
>             WHEN UPPER(MAX(PROPERTY_VALUE)) LIKE '%ADW.ORACLECLOUD.COM' THEN
>               CLOUD_SERVICE_TYPE_ADW_D
>       	    WHEN UPPER(MAX(PROPERTY_VALUE)) LIKE '%ATP.ORACLECLOUD.COM' THEN 
>               CLOUD_SERVICE_TYPE_ATP_D
>       	    ELSE CLOUD_SERVICE_TYPE_OTHER
>           END
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='DWCS' THEN 
>           CLOUD_SERVICE_TYPE_ADW_S
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='OLTP' THEN 
>           CLOUD_SERVICE_TYPE_ATP_S
>         ELSE
>           UPPER(NVL(SYS_CONTEXT('USERENV','CLOUD_SERVICE'), 
>                 CLOUD_SERVICE_TYPE_NONE))
>       END
>     INTO CLOUD_SERVICE_TYPE
>     FROM DATABASE_PROPERTIES
>     WHERE UPPER(PROPERTY_NAME) = 'GLOBAL_DB_NAME';
> 
>     RETURN CLOUD_SERVICE_TYPE;
> 
>   END GET_CLOUD_SERVICE_TYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_TZ_OFFSET
>   RETURN VARCHAR2
>   IS
>     L_TZ VARCHAR2(10);
>   BEGIN
>     
>     
>     L_TZ := EXTRACT(TIMEZONE_HOUR FROM SYSTIMESTAMP) || ':' ||
>                    EXTRACT(TIMEZONE_MINUTE FROM SYSTIMESTAMP);
>     RETURN L_TZ;
>   END GET_TZ_OFFSET;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION CHOOSEAWRFORPDB(
>         BEGINTIME IN DATE) 
>   RETURN VARCHAR2
>   IS
>     L_AWR_LOCATION VARCHAR2(32) := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>     L_SQLTEXT   VARCHAR2(4000);
>     L_PDB_TIME  DATE;
>     L_ROOT_TIME DATE;
> 
>   BEGIN
>     
>     
>     L_SQLTEXT := 
>       'SELECT CAST(MAX(end_interval_time) AS DATE)
>        FROM   AWR_PDB_SNAPSHOT
>        WHERE  dbid = :1';
>     EXECUTE IMMEDIATE L_SQLTEXT 
>     INTO L_PDB_TIME
>     USING SYS_CONTEXT('USERENV', 'CON_DBID');
> 
>     IF L_PDB_TIME IS NULL THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>       RETURN L_AWR_LOCATION;
>     END IF;
> 
>     IF L_PDB_TIME >= BEGINTIME THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB;
>       RETURN L_AWR_LOCATION;
>     END IF;
> 
>     
>     
>     
>     L_SQLTEXT := 
>       'SELECT CAST(MAX(end_interval_time) AS DATE)
>        FROM   AWR_ROOT_SNAPSHOT
>        WHERE  dbid = :1';
>     EXECUTE IMMEDIATE L_SQLTEXT
>     INTO L_ROOT_TIME
>     USING SYS_CONTEXT('USERENV', 'DBID');
>     
>     IF ((L_ROOT_TIME IS NOT NULL) AND 
>         (L_ROOT_TIME >= BEGINTIME) 
>        ) 
>     THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>       RETURN L_AWR_LOCATION;
> 
>     ELSE 
>         
>         L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB;
>         RETURN L_AWR_LOCATION;
>     END IF;
> 
>     RETURN L_AWR_LOCATION;
> 
>   END CHOOSEAWRFORPDB;
> 
SYS.PRVTEMX_PERF - PACKAGE BODY (RU):
7a8,13
>   AWR_PREFIX_ROOT   VARCHAR2(16) := 'sys.awr_root';
>   AWR_PREFIX_PDB    VARCHAR2(16) := 'sys.awr_pdb';
>   G_CLOUD_SERVICE_TYPE CONSTANT VARCHAR2(32) := 
>                     DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE();
> 
>   
379c385
<             from sys.dba_hist_active_sess_history a
---
>             from #AWR_VIEW_PREFIX#_active_sess_history a
462c468
<                             from sys.dba_hist_pdb_instance)) c');
---
>                             from #AWR_VIEW_PREFIX#_pdb_instance)) c');
485,502c491,550
<       SELECT MIN(SNAP_ID)
<         INTO L_BEGIN_SNAP
<         FROM SYS.DBA_HIST_ASH_SNAPSHOT
<        WHERE DBID            = L_DBID
<          AND INSTANCE_NUMBER = P_INST_ID
<          AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
<            OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
<            OR P_START_TIME BETWEEN BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
< 
<          
<       SELECT MAX(SNAP_ID)
<         INTO L_END_SNAP
<         FROM SYS.DBA_HIST_ASH_SNAPSHOT
<        WHERE DBID            = L_DBID
<          AND INSTANCE_NUMBER = P_INST_ID
<          AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
<            OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
<            OR P_END_TIME BETWEEN BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
---
>       
>       IF ((G_CLOUD_SERVICE_TYPE IN 
>             (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D))
>           AND 
>             (L_IS_ROOT = FALSE))
>       THEN  
>           L_QRY := REPLACE(L_QRY,'#AWR_VIEW_PREFIX#', AWR_PREFIX_PDB);
> 
>           
>           SELECT MIN(SNAP_ID)
>             INTO L_BEGIN_SNAP
>             FROM SYS.AWR_PDB_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_START_TIME BETWEEN 
>                                BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>              
>           SELECT MAX(SNAP_ID)
>             INTO L_END_SNAP
>             FROM SYS.AWR_PDB_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_END_TIME BETWEEN 
>                              BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>       ELSE 
>           
>           L_QRY := REPLACE(L_QRY,'#AWR_VIEW_PREFIX#', AWR_PREFIX_ROOT);
> 
>           
>           SELECT MIN(SNAP_ID)
>             INTO L_BEGIN_SNAP
>             FROM SYS.AWR_ROOT_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_START_TIME BETWEEN 
>                                BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>              
>           SELECT MAX(SNAP_ID)
>             INTO L_END_SNAP
>             FROM SYS.AWR_ROOT_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_END_TIME BETWEEN 
>                              BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>       END IF;
SYS.PRVTEMX_RSRCMGR - PACKAGE BODY (RU):
2530,2578d2529
<   PROCEDURE I_CREATE_AWR_CG_MAP(
<     P_CON_ID     IN     NUMBER,
<     P_AWR_PERIOD IN OUT NOCOPY PRVT_AWRV_METADATA,
<     P_CGRP_MAP   IN OUT NOCOPY PRVT_AWRV_INSTTAB)
<   IS
<     
<     SQLSTMT_MAP CONSTANT VARCHAR2(32767) := q'[
<       select sys.prvt_awrv_inst(id, name)
<         from (
<           select distinct 
<                  consumer_group_id id, 
<                  consumer_group_name name 
<             from sys.awr_root_rsrc_consumer_group s
<            where s.dbid             = :m_dbid
<              and s.snap_id          > :m_begin_snap
<              and s.snap_id         <= :m_end_snap
<              and s.con_dbid         = :m_con_dbid
<              and ]' || P_AWR_PERIOD.GET_INST_CLAUSE('s') ||')';
<          
<   BEGIN
<     IF (P_CON_ID = 0 OR P_CON_ID > 2) THEN
<       EXECUTE IMMEDIATE SQLSTMT_MAP
<         BULK COLLECT INTO P_CGRP_MAP
<         USING P_AWR_PERIOD.M_DBID,
<               P_AWR_PERIOD.M_BEGIN_SNAP, P_AWR_PERIOD.M_END_SNAP,
<               SYS.DBMS_SQLTUNE_UTIL0.CDBCON_ID_TO_DBID(P_CON_ID),
<               P_AWR_PERIOD.M_INST_ID_LOW, P_AWR_PERIOD.M_INST_ID_HIGH,
<               P_AWR_PERIOD.M_INST_ID_LIST;
<     ELSE
<       
<       P_CGRP_MAP := PRVT_AWRV_INSTTAB();
<     END IF;
<   END I_CREATE_AWR_CG_MAP;
< 
< 
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
<   
2883c2834,2835
<         I_CREATE_AWR_CG_MAP(L_CON_ID, AWR_PERIOD, L_DIM_MAP);  
---
>         PRVT_AWR_VIEWER.CREATE_CONSUMER_GROUP_MAP(
>           L_CON_ID, AWR_PERIOD, L_DIM_MAP);  
SYS.PRVT_AWR_VIEWER - PACKAGE BODY (RU):
1183a1184,1273
>   
>   
>   RMMETRICS_COMMON CONSTANT VARCHAR2(32767) := q'[
>       with rmmetrics_data as (-- autonomous DB workload main query
>         select bucket_id, 
>                new_id consumer_group_id,
>                case 
>                  when rn = 1 and :is_awr = 1
>                    then (select /*+ cardinality(t 1) */ instance_name
>                            from table(cast(:p_contTab 
>                                       as sys.prvt_awrv_instTab)) t
>                           where t.inst_id = consumer_group_id)
>                  when rn = 1 
>                    then consumer_group_name 
>                  else null 
>                end consumer_group_name,
>                avg_cpu_utilization,
>                cpu_usage_per_sec,
>                avg_running_stmts,
>                avg_active_parallel_stmts,
>                avg_queued_parallel_stmts
>           from ( -- generate an id since default ids can be high numbers
>             select bucket_id,
>                    consumer_group_id,
>                    consumer_group_name,
>                    avg_cpu_utilization,
>                    cpu_usage_per_sec,
>                    avg_running_stmts,
>                    avg_active_parallel_stmts,
>                    avg_queued_parallel_stmts,
>                    row_number() over (partition by consumer_group_id, 
>                                                consumer_group_name
>                                       order by bucket_id, 
>                                                consumer_group_id, 
>                                                consumer_group_name) rn,
>                    -- generate an id
>                    dense_rank() over (order by consumer_group_id, 
>                                                consumer_group_name) new_id
>               from (#GENERATE_METRICS_BUCKETID#) rsrc
>               where avg_cpu_utilization + cpu_usage_per_sec + 
>                     avg_running_stmts +
>                     avg_active_parallel_stmts + avg_queued_parallel_stmts > 0) 
>        )
> 
>       -- construct xml
>       select xmlagg(
>                nvl2(buckets,
>                     xmlelement("stattype",
>                      xmlattributes('rsrcmgrmetric' as "name"),
>                      xmlelement("stat_info",
>                        nvl(stat_id, 
>                            xmlelement("stat", 
>                              xmlattributes(
>                                consumer_group_id as "id", 
>                                consumer_group_id as "name")))),
>                      #GENERATE_BUCKETS_TAG#),
>                     null))
>         from ( -- aggregate buckets
>           select #GENERATE_BUCKETID_TAG#,
>                  xmlagg(stat_id)  stat_id, 
>                  max(consumer_group_id) consumer_group_id
>             from ( -- aggregate stats in each bucket
>               select bucket_id, 
>                      max(consumer_group_id) consumer_group_id,
>                      xmlagg(stat_id order by consumer_group_id) stat_id,
>                      xmlagg(xmlelement("stat",
>                       xmlattributes(consumer_group_id as "id",
>                             round(avg_cpu_utilization, 2)         as "cpu",
>                             round(cpu_usage_per_sec, 2)           as "cpuUsage",
>                             round(avg_running_stmts, 2)           as "rst",
>                             round(avg_active_parallel_stmts, 2)   as "apst",
>                             round(avg_queued_parallel_stmts, 2)   as "qpst"
>                         )
>                       )
>                       order by consumer_group_id)  stats
>                 from ( -- generate id name map
>                   select bucket_id, consumer_group_id,
>                          nvl2(consumer_group_name,
>                               xmlelement("stat",
>                                xmlattributes(consumer_group_id as "id",
>                                  consumer_group_name as "name")),
>                               null)      stat_id,
>                          avg_cpu_utilization,
>                          cpu_usage_per_sec,
>                          avg_running_stmts,
>                          avg_active_parallel_stmts,
>                          avg_queued_parallel_stmts
>                    from rmmetrics_data)
>                group by bucket_id))]';
> 
1311a1402,1461
>   PROCEDURE CREATE_CONSUMER_GROUP_MAP(
>     P_CON_ID     IN     NUMBER,
>     P_AWR_PERIOD IN OUT NOCOPY PRVT_AWRV_METADATA,
>     P_CGRP_MAP   IN OUT NOCOPY PRVT_AWRV_INSTTAB)
>   IS
> 
>     L_QRY VARCHAR2(32767) := NULL;
> 
>     
>     SQLSTMT_MAP CONSTANT VARCHAR2(32767) := q'[
>       select sys.prvt_awrv_inst(id, name)
>         from (
>           select distinct 
>                  consumer_group_id id, 
>                  consumer_group_name name 
>             from sys.awr_root_rsrc_consumer_group s
>            where s.dbid             = :m_dbid
>              and s.snap_id          > :m_begin_snap
>              and s.snap_id         <= :m_end_snap
>              and s.con_dbid         = :m_con_dbid
>              and ]' || P_AWR_PERIOD.GET_INST_CLAUSE('s') ||')';
> 
>   BEGIN
> 
>     L_QRY := SQLSTMT_MAP;
> 
>     DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(
>       L_QRY, P_AWR_PERIOD.M_AWR_VIEW_PREFIX);
> 
>     
>     IF (P_CON_ID = 0 OR P_CON_ID > 2) THEN
>       EXECUTE IMMEDIATE L_QRY
>         BULK COLLECT INTO P_CGRP_MAP
>         USING P_AWR_PERIOD.M_DBID,
>               P_AWR_PERIOD.M_BEGIN_SNAP, P_AWR_PERIOD.M_END_SNAP,
>               SYS.DBMS_SQLTUNE_UTIL0.CDBCON_ID_TO_DBID(P_CON_ID),
>               P_AWR_PERIOD.M_INST_ID_LOW, P_AWR_PERIOD.M_INST_ID_HIGH,
>               P_AWR_PERIOD.M_INST_ID_LIST;
>     
>     ELSE
>       
>       P_CGRP_MAP := PRVT_AWRV_INSTTAB();
>     END IF;
> 
>   END CREATE_CONSUMER_GROUP_MAP;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
16404a16555,16556
>   
>   
16416a16569
>     INCLUDE_SQLS      IN NUMBER         DEFAULT NULL,
16601c16754
<     IF (L_DIM_STAT IS NULL AND L_DIM_NAME IS NULL) THEN 
---
>     IF (INCLUDE_SQLS = 0) THEN
16602a16756,16758
>       L_TOPSQL_XML := NULL;
>     
>     ELSE
16604,16626c16760
<       IF (IS_REALTIME IS NULL OR IS_REALTIME = G_TIMEPICKER_HISTORICAL) THEN
<         
<       IF (L_START_TIME IS NOT NULL AND L_END_TIME IS NOT NULL AND
<           (L_END_TIME - L_START_TIME)*24*60 < L_SNAPINT_MINS) 
<       THEN
<         L_USEASH := TRUE;
<       END IF;
<       
<       
<       ELSE
<         L_USEASH := TRUE;
<       END IF;
< 
< 
<     IF (L_USEASH) THEN
<       SELECT XMLELEMENT("region_data",
<               XMLAGG(
<                 XMLELEMENT("stattype",
<                  XMLATTRIBUTES('topsql' AS "name",
<                                 '10' AS "topn",
<                                 'ash'   AS "source"))))
<         INTO L_TOPSQL_XML
<         FROM SYS.DUAL;
---
>       IF (L_DIM_STAT IS NULL AND L_DIM_NAME IS NULL) THEN 
16629,16630c16763,16773
<         IF (L_END_TIME IS NULL) THEN
<           L_END_TIME := SYSDATE;
---
>         IF (IS_REALTIME IS NULL OR IS_REALTIME = G_TIMEPICKER_HISTORICAL) THEN
>           
>           IF (L_START_TIME IS NOT NULL AND L_END_TIME IS NOT NULL AND
>              (L_END_TIME - L_START_TIME)*24*60 < L_SNAPINT_MINS) 
>           THEN
>             L_USEASH := TRUE;
>           END IF;
>           
>           
>         ELSE
>           L_USEASH := TRUE;
16633,16635d16775
<         IF (L_START_TIME IS NULL) THEN
<           L_START_TIME := L_END_TIME - 1/24;
<         END IF;
16637,16646c16777,16805
<         L_TOPSQL_XML := L_TOPSQL_XML.APPENDCHILDXML('/*/stattype',
<                         SYS.DBMS_ASH_INTERNAL.REPORT_ASHVIEWER_XML(
<                            DBID       => L_DBID,
<                            INST_ID    => L_INST_ID,
<                            BEGIN_TIME => 
<                              TO_CHAR(L_START_TIME,'hh24:mi:ss mm/dd/yyyy'),
<                            END_TIME   => 
<                              TO_CHAR(L_END_TIME,'hh24:mi:ss mm/dd/yyyy'),
<                            REPORT_LEVEL=>'<sqlid,wait_class>{treemap}', 
<                            PARENT_REPORT => 'topsql'));
---
>         IF (L_USEASH) THEN
>           SELECT XMLELEMENT("region_data",
>                    XMLAGG(
>                      XMLELEMENT("stattype",
>                        XMLATTRIBUTES('topsql' AS "name",
>                                      '10' AS "topn",
>                                      'ash'   AS "source"))))
>             INTO L_TOPSQL_XML
>             FROM SYS.DUAL;
> 
>             
>             IF (L_END_TIME IS NULL) THEN
>               L_END_TIME := SYSDATE;
>             END IF;
> 
>             IF (L_START_TIME IS NULL) THEN
>               L_START_TIME := L_END_TIME - 1/24;
>             END IF;
> 
>             L_TOPSQL_XML := L_TOPSQL_XML.APPENDCHILDXML('/*/stattype',
>                               SYS.DBMS_ASH_INTERNAL.REPORT_ASHVIEWER_XML(
>                                 DBID          => L_DBID,
>                                 INST_ID       => L_INST_ID,
>                                 BEGIN_TIME    => 
>                                   TO_CHAR(L_START_TIME,'hh24:mi:ss mm/dd/yyyy'),
>                                 END_TIME      => 
>                                   TO_CHAR(L_END_TIME,'hh24:mi:ss mm/dd/yyyy'),
>                                 REPORT_LEVEL  =>'<sqlid,wait_class>{treemap}', 
>                                 PARENT_REPORT => 'topsql'));
16648c16807
<     ELSE
---
>         ELSE
16650,16673c16809,16834
<       
<       L_TOPSQL_XML := I_REP_AWRDATA_XML(
<                         START_TIME       => L_START_TIME,
<                         END_TIME         => L_END_TIME,
<                         TIMEPICKER_START => NULL,
<                         TIMEPICKER_END   => NULL,
<                         INSTANCE_LIST    => L_INSTANCE_LIST,
<                         DBID             => L_DBID,
<                         BUCKET_MAX_COUNT => 1,  
<                         TIME_MODEL       => 'no',
<                         WAIT_CLASS       => 'no',
<                         WAIT_EVENT       => 'no',
<                         EVENT_CLASS      => 'no',
<                         SYSSTAT          => 'no',
<                         SQLSTAT          => 'EM_TOP_SQL',
<                         OSSTAT           => 'no',
<                         IOSTAT           => 'no',
<                         MEMORY           => 'no',
<                         SPACE            => 'no',
<                         KEY_STATISTICS   => 'no',
<                         INST_DETAIL      => L_SHOW_INST_DETAIL,
<                         MEMBERS          => 'no',
<                         SUMMARY          => 'no',
<                         SHOW_SQL         => SHOW_SQL);
---
>           
>           L_TOPSQL_XML := I_REP_AWRDATA_XML(
>                             START_TIME       => L_START_TIME,
>                             END_TIME         => L_END_TIME,
>                             TIMEPICKER_START => NULL,
>                             TIMEPICKER_END   => NULL,
>                             INSTANCE_LIST    => L_INSTANCE_LIST,
>                             DBID             => L_DBID,
>                             BUCKET_MAX_COUNT => 1,  
>                             TIME_MODEL       => 'no',
>                             WAIT_CLASS       => 'no',
>                             WAIT_EVENT       => 'no',
>                             EVENT_CLASS      => 'no',
>                             SYSSTAT          => 'no',
>                             SQLSTAT          => 'EM_TOP_SQL',
>                             OSSTAT           => 'no',
>                             IOSTAT           => 'no',
>                             MEMORY           => 'no',
>                             SPACE            => 'no',
>                             KEY_STATISTICS   => 'no',
>                             INST_DETAIL      => L_SHOW_INST_DETAIL,
>                             MEMBERS          => 'no',
>                             SUMMARY          => 'no',
>                             SHOW_SQL         => SHOW_SQL);
>         END IF;
>       END IF;
16675d16835
<   END IF;
18086a18247,20960
>   
>   
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_RMMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME      IN DATE               DEFAULT NULL,
>     END_TIME        IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT 0)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER        := IS_REALTIME;
>     L_DBID            NUMBER        := DBID;
>     L_START_TIME      DATE          := START_TIME;
>     L_END_TIME        DATE          := END_TIME;
>     L_BUCKET_COUNT    NUMBER        := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER        := BUCKET_INTERVAL;
>     L_AWR_PERIOD PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(10)  := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_BUCKET_MAP PRVT_AWRV_MAPTAB;
> 
>     
>     L_CON_ID   NUMBER;
>     L_CON_DBID NUMBER;
> 
>     
>     L_RESOURCE_MANAGER_ENABLED NUMBER := 0;
>     
>     
>     L_NUM_CPUS NUMBER := NULL;
> 
>     
>     L_CG_MAP PRVT_AWRV_INSTTAB := NULL;
> 
>     
>     RMMETRICS_RT CONSTANT VARCHAR2(32767) := q'[
>     select bucket_id,
>            consumer_group_id, consumer_group_name,
>            case
>              when avg(avg_cpu_utilization) > 100 then 100
>              else avg(avg_cpu_utilization) 
>            end avg_cpu_utilization,
>            avg(cpu_usage_per_sec) cpu_usage_per_sec,
>            sum(avg_running_stmts) avg_running_stmts,
>            sum(avg_active_parallel_stmts) 
>                                      avg_active_parallel_stmts,
>            sum(avg_queued_parallel_stmts) 
>                                      avg_queued_parallel_stmts
>       from table(sys.gv$(cursor(
>            select trunc(
>                   ((extract(day from 
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                     * 86400 +
>                     extract(hour from 
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                     * 3600 + 
>                     extract(minute from
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                     * 60 + 
>                     extract(second from
>                       (cast(trunc(end_time,'mi') as timestamp) -
>                        cast(trunc(to_date(:b_start_time, :date_fmt),'mi') 
>                          as timestamp))) 
>                    )
>                    / :p_bucket_interval)) + 1 bucket_id,
>                   consumer_group_name,
>                   consumer_group_id,
>                   (case 
>                      -- resource manager enabled, use running_sessions_limit
>                      when :resource_manager_enabled > 0 then
>                        (case
>                           -- if running_sessions_limit is not set
>                           when running_sessions_limit is null or
>                                running_sessions_limit = 0 then
>                             avg_cpu_utilization
>                           else
>                             (avg_running_sessions/running_sessions_limit)*100
>                         end)
>                      -- resource manager disabled, use system cpu limit
>                      else
>                        (case
>                           when :num_cpus > 0 then
>                             (avg_running_sessions/:num_cpus)*100
>                           -- system cpu limit not available
>                           -- use running_sessions_limit
>                           else
>                             (case
>                                when running_sessions_limit is null or
>                                     running_sessions_limit = 0 then
>                                  avg_cpu_utilization
>                                else
>                                 (avg_running_sessions/running_sessions_limit)*100
>                              end)
>                         end)
>                      end) avg_cpu_utilization,
>                   cpu_consumed_time/(intsize_csec*10) cpu_usage_per_sec,
>                   avg_running_sessions + avg_waiting_sessions
>                     as avg_running_stmts,
>                   avg_active_parallel_stmts,
>                   avg_queued_parallel_stmts
>              from sys.v_$rsrcmgrmetric_history
>             where end_time >= to_date(:b_start_time, :date_fmt)
>               and end_time <  to_date(:b_end_time, :date_fmt))))
>          group by bucket_id, consumer_group_id, consumer_group_name]';
> 
>     
>     RMMETRICS_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var is_awr                   number;
>       var p_contTab                prvt_awrv_instTab;
>       var b_start_time             varchar2(4000);
>       var b_end_time               varchar2(4000);
>       var p_bucket_interval        number;
>       var p_bucket_count           number;
>       var b_min_time               varchar2(4000);
>       var b_max_time               varchar2(4000);
>       var b_duration               number;
>       var date_fmt                 varchar2(4000);
>       var resource_manager_enabled number;
>       var num_cpus                 number;
>       begin
>         :is_awr                   := #is_awr#;
>         :p_contTab                := #p_contTab#;
>         :b_start_time             := '#b_start_time#';
>         :b_end_time               := '#b_end_time#';
>         :p_bucket_interval        := #p_bucket_interval#;
>         :p_bucket_count           := #p_bucket_count#;
>         :b_min_time               := '#b_min_time#';
>         :b_max_time               := '#b_max_time#';
>         :b_duration               := #b_duration#;
>         :date_fmt                 := '#date_fmt#';
>         :resource_manager_enabled := #resource_manager_enabled#;
>         :num_cpus                 := #num_cpus#;
>       end;
>       /]';
> 
>     
>     RMMETRICS_AWR CONSTANT VARCHAR2(32767) := q'[
>     select bucket_id,
>            consumer_group_id,
>            consumer_group_name,
>            case
>              when sum(avg_cpu_utilization) > 100 then 100
>              else sum(avg_cpu_utilization) 
>            end avg_cpu_utilization,
>            sum(cpu_usage_per_sec) cpu_usage_per_sec,
>            sum(avg_running_stmts) avg_running_stmts,
>            sum(avg_active_parallel_stmts) avg_active_parallel_stmts,
>            sum(avg_queued_parallel_stmts) avg_queued_parallel_stmts
>      from (
>         select bucket_id,
>                consumer_group_name,  
>                consumer_group_id,
>                -- avg
>                avg(avg_cpu_utilization) avg_cpu_utilization,
>                avg(cpu_usage_per_sec) cpu_usage_per_sec,
>                avg(avg_running_stmts) avg_running_stmts,
>                avg(avg_active_parallel_stmts) 
>                   avg_active_parallel_stmts,
>                avg(avg_queued_parallel_stmts) 
>                   avg_queued_parallel_stmts
>           from table(cast(:bucket_map as sys.prvt_awrv_mapTab)) b,
>                (select /*+ no_merge */ nvl(m.snap_id, c.snap_id) as snap_id,
>                        nvl(m.instance_number, c.instance_number) 
>                                                  as instance_number,
>                        m.consumer_group_id consumer_group_id,
>                        null consumer_group_name,
>                        case 
>                          when c.cpu_limit is null or
>                               c.cpu_limit = 0 then
>                            m.avg_cpu_utilization
>                          else
>                            (m.avg_running_sessions/c.cpu_limit)*100
>                          end                       as avg_cpu_utilization,
>                        m.cpu_consumed_time/(m.intsize_csec*10) cpu_usage_per_sec,
>                        m.avg_running_sessions + m.avg_waiting_sessions
>                                                    as avg_running_stmts,
>                        m.avg_active_parallel_stmts as avg_active_parallel_stmts,
>                        m.avg_queued_parallel_stmts as avg_queued_parallel_stmts
>                   from awr_root_rsrc_metric m,
>                        (SELECT /*+ no_merge */ 
>                                nvl(s.snap_id, p.snap_id) as snap_id,
>                                nvl(s.instance_number, p.instance_number) 
>                                                          as instance_number,
>                                CASE WHEN p.cpu_count IS NULL 
>                                     THEN nvl(s.num_cpus, s.num_cpu_cores)
>                                     ELSE LEAST(p.cpu_count, 
>                                                NVL(s.num_cpus, s.num_cpu_cores))
>                                END as cpu_limit
>                           FROM   
>                             (SELECT /*+ NO_MERGE */ snap_id, instance_number,
>                                     MAX(num_cpus)      num_cpus,
>                                     MAX(num_cpu_cores) num_cpu_cores
>                                FROM 
>                                  (SELECT snap_id, instance_number,
>                                          CASE
>                                            WHEN stat_name = 'NUM_CPUS' 
>                                            THEN value
>                                            ELSE NULL
>                                          END as num_cpus,
>                                          CASE
>                                            WHEN stat_name = 'NUM_CPU_CORES'
>                                            THEN value
>                                            ELSE NULL
>                                          END as num_cpu_cores
>                                     FROM awr_root_osstat
>                                    WHERE stat_name IN 
>                                            ('NUM_CPUS','NUM_CPU_CORES'))
>                                   GROUP BY snap_id, instance_number) s,
>                             (SELECT /*+ NO_MERGE */ snap_id, instance_number,
>                                     MAX(
>                                       CASE 
>                                         WHEN resource_plan IS NULL THEN NULL 
>                                         ELSE TO_NUMBER(cpu_count)
>                                       END) as cpu_count
>                                FROM 
>                                  (SELECT snap_id, instance_number,
>                                          CASE
>                                            WHEN parameter_name = 'cpu_count' 
>                                            THEN value
>                                            ELSE NULL
>                                          END cpu_count,
>                                          CASE
>                                            WHEN parameter_name = 
>                                                   'resource_manager_plan'
>                                            THEN value
>                                            ELSE NULL
>                                          END resource_plan
>                                     FROM awr_root_parameter
>                                    WHERE parameter_name IN 
>                                           ('cpu_count', 'resource_manager_plan'))
>                                   GROUP BY snap_id, instance_number) p
>                          WHERE s.snap_id = p.snap_id
>                            AND s.instance_number = p.instance_number) c
>                  where m.dbid = :m_dbid 
>                    and m.snap_id between :m_begin_snap and :m_end_snap
>                    and m.con_dbid = :l_con_dbid
>                    and m.snap_id = c.snap_id(+)
>                    and m.instance_number = c.instance_number(+)) y
>          where b.snap_id         = y.snap_id
>            and b.instance_number = y.instance_number
>          group by bucket_id, 
>                y.instance_number, 
>                y.consumer_group_id, 
>                y.consumer_group_name)
>       group by bucket_id, 
>                consumer_group_id,
>                consumer_group_name]'; 
> 
>     
>     RMMETRICS_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var is_awr            number;
>       var p_contTab         prvt_awrv_instTab;
>       var bucket_map        prvt_awrv_mapTab;
>       var m_dbid            number;
>       var m_begin_snap      number;
>       var m_end_snap        number;
>       var l_con_dbid        number;
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_min_time        varchar2(4000);
>       var b_max_time        varchar2(4000);
>       var b_duration        number;
>       begin
>         :is_awr            := #is_awr#;
>         :p_contTab         := #p_contTab#;
>         :bucket_map        := #bucket_map#;
>         :m_dbid            := #m_dbid#;
>         :m_begin_snap      := #m_begin_snap#;
>         :m_end_snap        := #m_end_snap#;
>         :l_con_dbid        := #l_con_dbid#;
>         :p_bucket_interval := #p_bucket_interval#;
>         :p_bucket_count    := #p_bucket_count#;
>         :b_min_time        := '#b_min_time#';
>         :b_max_time        := '#b_max_time#';
>         :b_duration        := #b_duration#;
>       end;
>       /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
>     
>     
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME IS NULL) THEN
>       L_END_TIME := SYSDATE;
>     END IF;
> 
>     
>     IF (START_TIME IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME := L_END_TIME - 1/24;
>       
>       ELSE
>         L_START_TIME := L_END_TIME - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
>       
>       
>       BEGIN
>         SELECT COUNT(VALUE)
>           INTO L_RESOURCE_MANAGER_ENABLED
>           FROM SYS.V_$SYSTEM_PARAMETER2        
>          WHERE NAME = 'resource_manager_plan'
>            AND (VALUE IS NOT NULL AND VALUE != '');
>       EXCEPTION
>         WHEN OTHERS THEN
>           L_RESOURCE_MANAGER_ENABLED := 0;
>       END;
> 
>       
>       BEGIN
>         SELECT SUM(NUM_CPUS)
>           INTO L_NUM_CPUS
>           FROM (
>             SELECT HOST_NAME, SUM(NUM_CPUS) AS NUM_CPUS
>               FROM TABLE(GV$(CURSOR(
>                      SELECT I.INSTANCE_NUMBER AS INST_ID, I.HOST_NAME,
>                             NVL(OS.NUM_CPUS, OS.NUM_CPU_CORES) AS NUM_CPUS
>                        FROM SYS.V$INSTANCE I, 
>                             (SELECT MAX(DECODE(STAT_NAME, 'NUM_CPUS', 
>                                                VALUE, NULL)) AS NUM_CPUS,
>                                     MAX(DECODE(STAT_NAME, 'NUM_CPU_CORES', 
>                                                VALUE, NULL)) AS NUM_CPU_CORES
>                                FROM SYS.V$OSSTAT
>                               WHERE STAT_NAME IN ('NUM_CPUS', 'NUM_CPU_CORES')
>                             ) OS)))
>             GROUP BY HOST_NAME);
>       EXCEPTION
>         WHEN OTHERS THEN
>           L_NUM_CPUS := 0;
>       END;
> 
>       
>       L_QRY := RMMETRICS_COMMON;
>    
>       
>       L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETS_TAG#', 
>                               GENERATE_BUCKETS_TAG2);
>       L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETID_TAG#', 
>                               GENERATE_BUCKETID_TAG);
>       L_QRY := REPLACE(L_QRY,'#GENERATE_METRICS_BUCKETID#', 
>                               RMMETRICS_RT);
> 
>       IF (SHOW_SQL = 1) THEN
>         
>         L_SQL := RMMETRICS_RT_HEADER;
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#is_awr#', 0);
>         L_SQL := REPLACE(L_SQL, '#p_contTab#', 'null');
>         L_SQL := REPLACE(L_SQL, '#b_start_time#',
>                                  TO_CHAR(L_START_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time#',
>                                  TO_CHAR(L_END_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_min_time#', TO_CHAR(L_START_TIME, 
>                                                         DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_max_time#', TO_CHAR(L_END_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                  ROUND((L_END_TIME - L_START_TIME)*DTOS));
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
> 
>         L_SQL := REPLACE(L_SQL, '#resource_manager_enabled#', 
>                                 L_RESOURCE_MANAGER_ENABLED);
> 
>         L_SQL := REPLACE(L_SQL, '#num_cpus#', L_NUM_CPUS);
> 
>         L_RESULT_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_SQL);
> 
>       ELSE
>         
>         EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING 0, L_CG_MAP,
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 L_BUCKET_INTERVAL,
>                 L_RESOURCE_MANAGER_ENABLED,
>                 L_NUM_CPUS, L_NUM_CPUS,
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_END_TIME, DATE_FMT), DATE_FMT,
>                 
>                 L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME,DATE_FMT), TO_CHAR(L_END_TIME,DATE_FMT),
>                 (L_END_TIME - L_START_TIME)*DTOS;
>       END IF;
>     
>     
>     ELSE
> 
>       IF (L_AWR_PERIOD IS NOT NULL) THEN
>         
>         CREATE_BUCKET_SNAP_MAP(L_AWR_PERIOD, L_BUCKET_MAP, 
>                                L_BUCKET_COUNT, L_BUCKET_INTERVAL);
> 
>         L_CON_ID := SYS_CONTEXT('USERENV','CON_ID');
> 
>         CREATE_CONSUMER_GROUP_MAP(L_CON_ID, L_AWR_PERIOD, L_CG_MAP);
> 
>         
>         L_QRY := RMMETRICS_COMMON;
>    
>         
>         L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETS_TAG#', 
>                                 GENERATE_BUCKETS_TAG2);
>         L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETID_TAG#', 
>                                 GENERATE_BUCKETID_TAG);
>         L_QRY := REPLACE(L_QRY,'#GENERATE_METRICS_BUCKETID#', 
>                                 RMMETRICS_AWR);
> 
>         
>         
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := RMMETRICS_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#is_awr#', 1);
>           L_SQL := REPLACE(L_SQL, '#p_contTab#', '');
>           L_SQL := REPLACE(L_SQL, '#bucket_map#', '');
>           L_SQL := REPLACE(L_SQL, '#m_dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#m_begin_snap#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#m_end_snap#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#l_con_dbid#', L_CON_DBID);
>           L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#b_min_time#', 
>                                    TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#b_max_time#', 
>                                    TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                            L_AWR_PERIOD.M_MAX_TIME, 
>                                            L_AWR_PERIOD.M_MIN_TIME)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING 1, 
>                 L_CG_MAP, 
>                 L_BUCKET_MAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_CON_DBID,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT),
>                 TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT),
>                 ROUND(
>                   INTERVAL_TO_SECOND(
>                     L_AWR_PERIOD.M_MAX_TIME, L_AWR_PERIOD.M_MIN_TIME));
>         END IF;
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_RMMETRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SQL_N_PARSE_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     SQL_AND_PARSE_TIME_RT CONSTANT VARCHAR2(32767) := q'[
>       with base_data as (
>         SELECT bucket_id,
>                SUM(parse_time_sec) / :p_bucket_interval AS parse_aas,
>                SUM(sql_exec_time_sec) / :p_bucket_interval AS sql_exec_aas,
>                SUM(plsql_exec_time_sec) / :p_bucket_interval AS plsql_exec_aas
>           FROM TABLE(GV$(CURSOR(
>                  SELECT bucket_id, 
>                         SUM(parse_time_usec) / 1000000    as parse_time_sec,
>                         SUM(sql_exec_time_usec) / 1000000 as sql_exec_time_sec,
>                         SUM(plsql_exec_time_usec) / 1000000 
>                                                           as plsql_exec_time_sec
>                    FROM (
>                          SELECT TRUNC(((
>                                   cast(sample_time_utc as date) - 
>                                   to_date(:b_start_time_utc, :date_fmt)) 
>                                   * 86400 ) / :p_bucket_interval) + 1 
>                                     as bucket_id,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_parse = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as parse_time_usec,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_sql_execution = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as sql_exec_time_usec,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_plsql_execution = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as plsql_exec_time_usec
>                            FROM sys.v_$active_session_history 
>                           WHERE sample_time_utc > to_timestamp(
>                                                     :b_start_time_utc,
>                                                     :date_fmt) 
>                             AND sample_time_utc <= to_timestamp(
>                                                     :b_end_time_utc,:date_fmt)
>                         )
>                   WHERE bucket_id > 0
>                   GROUP BY bucket_id
>                )))
>         GROUP BY bucket_id
>         ORDER BY bucket_id)
>       select xmlelement("stattype",
>                xmlattributes('sql' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id    as "bucket_id"),
>                   xmlforest(round(parse_aas, 2)      as "parse_aas",
>                             round(sql_exec_aas, 2)   as "sql_aas",
>                             round(plsql_exec_aas, 2) as "plsql_aas")))))
>         from base_data
>        where (parse_aas + sql_exec_aas + plsql_exec_aas) > 0]';
> 
>     
>     SQL_AND_PARSE_TIME_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>     var date_fmt          varchar2(32);
>     var b_start_time_utc  varchar2(32);
>     var b_end_time_utc    varchar2(32);
>     var p_bucket_interval number;
>     var p_bucket_count    number;
>     var b_duration        number;
>     begin 
>       :date_fmt            := '#date_fmt#';
>       :b_start_time_utc    := '#b_start_time_utc#';
>       :b_end_time_utc      := '#b_end_time_utc#';
>       :p_bucket_interval   := #p_bucket_interval#;
>       :p_bucket_count      := #p_bucket_count#;
>       :b_duration          := #b_duration#;
>     end;
>     /]';
> 
> 
>     
>     SQL_AND_PARSE_TIME_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, s.stat_name, 
>                   s.value / 1000000 as value_secs 
>              FROM awr_root_con_sys_time_model s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.stat_name IN ('parse time elapsed', 
>                                   'sql execute elapsed time', 
>                                   'PL/SQL execution elapsed time')
>           ),
>         diff_stats AS 
>           (SELECT estat.instance_number, estat.snap_id, estat.stat_name, 
>                   s.begin_time_utc, s.end_time_utc,
>                   GREATEST(estat.value_secs - 
>                            (s.diff_logic * NVL(bstat.value_secs,0)),0) /
>                   ((s.end_time_utc - s.begin_time_utc)*86400)
>                   as value_per_sec
>              FROM base_stats estat, snaps s, base_stats bstat
>             WHERE estat.instance_number = s.instance_number
>               AND estat.snap_id = s.snap_id
>               AND estat.instance_number = bstat.instance_number(+)
>               AND estat.snap_id-1 = bstat.snap_id(+)
>               AND estat.stat_name = bstat.stat_name(+)
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400)      as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         final_stats AS
>           (SELECT bucket_id, stat_name, 
>                   SUM(value_per_sec * bucket_ratio) as aas
>              FROM (
>                    SELECT b.bucket_id, s.stat_name, s.value_per_sec, 
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM diff_stats s, buckets b
>                     WHERE s.value_per_sec > 0
>                       AND b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, stat_name
>           ),
>         pivoted_stats AS
>           (SELECT * FROM final_stats
>            PIVOT(SUM(aas) FOR stat_name IN 
>                              ('parse time elapsed' as parse_aas,
>                               'sql execute elapsed time' as sql_exec_aas,
>                               'PL/SQL execution elapsed time' as plsql_exec_aas)
>                 )
>           ),
>         base_data AS
>           (SELECT bucket_id, parse_aas, sql_exec_aas, plsql_exec_aas
>              FROM pivoted_stats
>            ORDER BY bucket_id)
>       select xmlelement("stattype",
>                xmlattributes('sql' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id    as "bucket_id"),
>                   xmlforest(round(parse_aas, 2)      as "parse_aas",
>                             round(sql_exec_aas, 2)   as "sql_aas",
>                             round(plsql_exec_aas, 2) as "plsql_aas")))))
>         from base_data
>        where (parse_aas + sql_exec_aas + plsql_exec_aas) > 0]';
> 
>     
>     SQL_AND_PARSE_TIME_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
>       
>       L_QRY := SQL_AND_PARSE_TIME_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := SQL_AND_PARSE_TIME_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('sql_and_parse_time', L_SQL);
> 
>       ELSE
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>  
>     
>     ELSE
>       IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := SQL_AND_PARSE_TIME_AWR;
> 
>         
>         
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := SQL_AND_PARSE_TIME_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#', ROUND(INTERVAL_TO_SECOND(
>                                    L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('sql_and_parse_time', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                 ROUND(
>                   INTERVAL_TO_SECOND(L_END_TIME_UTC, L_START_TIME_UTC));
> 
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SQL_N_PARSE_TIME_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_WAIT_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     WAIT_TIME_RT CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         inst_data AS
>           (SELECT inst_id, bucket_id, metric_name, value
>              FROM TABLE(GV$(CURSOR(
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id, metric_name,
>                            SUM(value*bucket_ratio) as value
>                       FROM (
>                             SELECT USERENV('INSTANCE') as inst_id,
>                                    buckets.bucket_id,
>                                    met.metric_name,
>                                    met.value,
>                                    (LEAST(met.end_time_utc, 
>                                           buckets.end_time_utc) - 
>                                     GREATEST(met.begin_time_utc, 
>                                              buckets.begin_time_utc)) / 
>                                     (met.end_time_utc - met.begin_time_utc) 
>                                       as bucket_ratio
>                              FROM ( 
>                                    SELECT /*+ no_merge */ USERENV('INSTANCE') 
>                                                               as inst_id,
>                                           m.begin_time-tz.time_zone 
>                                                               as begin_time_utc,
>                                           m.end_time-tz.time_zone 
>                                                               as end_time_utc,
>                                           CASE
>                                             WHEN m.metric_name = 
>                                                    'Average Active Sessions'
>                                               THEN 'DBTime'
>                                             ELSE 'CPU'
>                                           END as metric_name,
>                                           CASE 
>                                             WHEN m.metric_name = 
>                                                    'CPU Usage Per Sec' 
>                                             THEN m.value*m.intsize_csec/10000
>                                             ELSE m.value*m.intsize_csec/100
>                                           END as value
>                                      FROM sys.v_$con_sysmetric_history m,
>                                           (SELECT ROUND(
>                                                     (cast(latest_sample_time 
>                                                           as date) - 
>                                                      cast(sys_extract_utc(
>                                                             systimestamp) 
>                                                           as date))
>                                                     *900,0)/900 as time_zone
>                                              FROM sys.v_$ash_info) tz
>                                     WHERE m.group_id = 18
>                                       AND m.metric_name IN 
>                                             ('Average Active Sessions',
>                                              'CPU Usage Per Sec')
>                                       AND m.begin_time-tz.time_zone < 
>                                           to_date(:b_end_time_utc, :date_fmt)
>                                       AND m.end_time-tz.time_zone >= 
>                                           to_date(:b_start_time_utc, :date_fmt)
>                                   ) met,    
>                                   ( 
>                                    SELECT /*+ no_merge */ level as bucket_id,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           ((level -1) * :p_bucket_interval 
>                                            / 86400) as begin_time_utc,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           (level * :p_bucket_interval / 86400) 
>                                                     as end_time_utc
>                                      FROM sys.v_$instance 
>                                           -- note: DUAL not allowed inside GV$
>                                    CONNECT BY level <= 
>                                               (to_date(:b_end_time_utc,
>                                                        :date_fmt) - 
>                                                to_date(:b_start_time_utc, 
>                                                        :date_fmt)) 
>                                               * 86400 / :p_bucket_interval
>                                   ) buckets
>                             WHERE buckets.begin_time_utc < met.end_time_utc
>                               AND buckets.end_time_utc > met.begin_time_utc
>                            )
>                     GROUP BY bucket_id, metric_name
>                     UNION ALL
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id,
>                            metric_name,
>                            SUM(value) as value
>                       FROM (
>                             SELECT TRUNC(((cast(sample_time_utc as date) - 
>                                                 to_date(:b_start_time_utc, 
>                                                         :date_fmt)) * 86400) / 
>                                    :p_bucket_interval) + 1 AS bucket_id,
>                                    DECODE(session_state, 'WAITING', wait_class, 
>                                                          'ASH_CPU') 
>                                                            AS metric_name,
>                                    CASE 
>                                      WHEN session_type = 'FOREGROUND' 
>                                      THEN usecs_per_row/1000000 
>                                      ELSE 0 
>                                    END AS value
>                               FROM sys.v_$active_session_history
>                              WHERE sample_time_utc >= 
>                                    to_timestamp(:b_start_time_utc, :date_fmt)
>                                AND sample_time_utc < 
>                                    to_timestamp(:b_end_time_utc, :date_fmt)
>                            )
>                     WHERE bucket_id > 0
>                     GROUP BY bucket_id, metric_name
>           )))),
>         db_data AS 
>           (SELECT bucket_id, metric_name, 
>                   SUM(value) as value
>              FROM inst_data
>            GROUP BY bucket_id, metric_name
>           ),
>         wait_for_cpu AS
>           (SELECT bucket_id, 'wait for CPU' as metric_name, 
>                   GREATEST(SUM(DECODE(metric_name, 'ASH_CPU', value, 
>                                       -value)), 0)    AS value
>              FROM db_data
>             WHERE metric_name IN ('CPU', 'ASH_CPU')
>            GROUP BY bucket_id
>           ),
>         final_data AS
>           (SELECT bucket_id, metric_name,
>                   value / :p_bucket_interval    AS value
>              FROM db_data
>             WHERE metric_name <> 'ASH_CPU'
>               AND value > 0
>            UNION ALL
>            SELECT bucket_id, metric_name, 
>                   value /:p_bucket_interval     AS value
>              FROM wait_for_cpu
>             WHERE value > 0
>           ),
>         base_data AS
>           (SELECT * FROM final_data
>            ORDER BY bucket_id, metric_name)
>       select xmlelement("stattype",
>                xmlattributes('wait_time' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")
>              ))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     WAIT_TIME_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var date_fmt          varchar2(32);
>       var b_start_time_utc  varchar2(32);
>       var b_end_time_utc    varchar2(32);
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_duration        number;
>       begin 
>         :date_fmt            := '#date_fmt#';
>         :b_start_time_utc    := '#b_start_time_utc#';
>         :b_end_time_utc      := '#b_end_time_utc#';
>         :p_bucket_interval   := #p_bucket_interval#;
>         :p_bucket_count      := #p_bucket_count#;
>         :b_duration          := #b_duration#;
>       end;
>       /]';
> 
>     
>     WAIT_TIME_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT e.instance_number, e.snap_id, e.wait_class, 
>                   SUM(e.time_waited_micro_fg)/1000000 as value
>              FROM awr_root_con_system_event e
>             WHERE e.dbid = :dbid
>               AND e.snap_id >= :begin_snap_id
>               AND e.snap_id <= :end_snap_id
>               AND e.wait_class <> 'Idle'
>            GROUP BY e.instance_number, e.snap_id, e.wait_class  
>            UNION ALL
>            SELECT s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN s.stat_name = 'DB time'
>                     THEN 'DBTime' 
>                     ELSE 'CPU'
>                   END as wait_class,
>                   s.value/1000000 as value
>              FROM awr_root_con_sys_time_model s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.stat_name IN ('DB time', 'DB CPU')
>           ),
>         agg_stats AS
>           (SELECT /*+ no_merge */ instance_number, snap_id, wait_class, 
>                   SUM(value) as value
>              FROM base_stats
>             WHERE value > 0
>            GROUP BY instance_number, snap_id, wait_class
>           ),
>         diff_stats AS 
>           (SELECT estat.instance_number, estat.snap_id, estat.wait_class, 
>                   s.begin_time_utc, s.end_time_utc,
>                   GREATEST(estat.value - 
>                            (s.diff_logic * NVL(bstat.value,0)),0) /
>                   ((s.end_time_utc - s.begin_time_utc)*86400)
>                   as value
>              FROM agg_stats estat, snaps s, agg_stats bstat
>             WHERE estat.instance_number = s.instance_number
>               AND estat.snap_id = s.snap_id
>               AND estat.instance_number = bstat.instance_number(+)
>               AND estat.snap_id-1 = bstat.snap_id(+)
>               AND estat.wait_class = bstat.wait_class(+)
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400) as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         db_stats AS
>           (SELECT bucket_id, wait_class, 
>                   SUM(value * bucket_ratio) as value
>              FROM (
>                    SELECT b.bucket_id, s.wait_class, s.value,
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM diff_stats s, buckets b
>                     WHERE b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, wait_class
>           ),
>         wait_for_cpu AS
>           (SELECT bucket_id, 'wait for CPU' as wait_class,
>                   GREATEST(SUM(DECODE(wait_class, 'DBTime', value, -value)), 
>                            0) as value
>              FROM db_stats
>            GROUP BY bucket_id
>           ),
>         final_stats AS 
>           (SELECT bucket_id, wait_class, value
>              FROM db_stats
>            UNION ALL
>            SELECT bucket_id, wait_class, value
>              FROM wait_for_cpu
>           ),
>        base_data AS
>          (SELECT bucket_id, wait_class, value
>             FROM final_stats
>           ORDER BY 1,2)
>       select xmlelement("stattype",
>                xmlattributes('wait_time' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("wait_class",
>                               xmlattributes(wait_class      as "name",
>                                             round(value, 2) as "value")))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     WAIT_TIME_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
> 
>       L_QRY := WAIT_TIME_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := WAIT_TIME_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#', 
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('wait_time', L_SQL);
> 
>       ELSE
> 
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>     
>     
>     ELSE
>      IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := WAIT_TIME_AWR;
> 
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := WAIT_TIME_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                      L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('wait_time', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT),
>                 ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_WAIT_TIME_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SYSMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     SYSMETRIC_RT CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         inst_data AS
>           (SELECT inst_id, bucket_id, metric_name, value
>              FROM TABLE(GV$(CURSOR(
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id, metric_name,
>                            SUM(value*bucket_ratio) as value
>                       FROM (
>                             SELECT USERENV('INSTANCE') as inst_id,
>                                    buckets.bucket_id,
>                                    met.metric_name,
>                                    met.value,
>                                    (LEAST(met.end_time_utc, 
>                                           buckets.end_time_utc) - 
>                                     GREATEST(met.begin_time_utc, 
>                                              buckets.begin_time_utc)) / 
>                                     (met.end_time_utc - met.begin_time_utc) 
>                                       as bucket_ratio
>                              FROM ( 
>                                    SELECT /*+ no_merge */ USERENV('INSTANCE') 
>                                                               as inst_id,
>                                           m.begin_time-tz.time_zone 
>                                                               as begin_time_utc,
>                                           m.end_time-tz.time_zone 
>                                                               as end_time_utc,
>                                           m.metric_name,
>                                           CASE 
>                                             WHEN m.metric_name = 
>                                                    'CPU Usage Per Sec' 
>                                             THEN m.value/100
>                                             ELSE m.value
>                                           END as value
>                                      FROM sys.v_$con_sysmetric_history m,
>                                           (SELECT ROUND(
>                                                     (cast(latest_sample_time 
>                                                           as date) - 
>                                                      cast(sys_extract_utc(
>                                                             systimestamp) 
>                                                           as date))
>                                                     *900,0)/900 as time_zone
>                                              FROM sys.v_$ash_info) tz
>                                     WHERE m.group_id = 18
>                                       AND m.metric_name IN 
>                                             ('Average Active Sessions',
>                                              'CPU Usage Per Sec',
>                                              'Executions Per Sec',
>                                              'User Calls Per Sec', 
>                                              'Total Parse Count Per Sec',
>                                              'User Commits Per Sec', 
>                                              'User Rollbacks Per Sec', 
>                                              'Session Count',
>                                              'Current Logons Count', 
>                                              'Logons Per Sec',
>                                              'Logons Per Txn',
>                                              'Redo Generated Per Sec',
>                                              'Redo Generated Per Txn',
>                                              'User Transaction Per Sec',
>                                              'Network Traffic Volume Per Sec',
>                                              'Hard Parse Count Per Sec',
>                                              'Parse Failure Count Per Sec',
>                                              'Current Open Cursors Count')
>                                       AND m.begin_time-tz.time_zone < 
>                                           to_date(:b_end_time_utc, :date_fmt)
>                                       AND m.end_time-tz.time_zone >= 
>                                           to_date(:b_start_time_utc, :date_fmt)
>                                   ) met,    
>                                   ( 
>                                    SELECT /*+ no_merge */ level as bucket_id,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           ((level -1) * :p_bucket_interval 
>                                            / 86400) as begin_time_utc,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           (level * :p_bucket_interval / 86400) 
>                                                     as end_time_utc
>                                      FROM sys.v_$instance 
>                                           -- note: DUAL not allowed inside GV$
>                                    CONNECT BY level <= 
>                                               (to_date(:b_end_time_utc,
>                                                        :date_fmt) - 
>                                                to_date(:b_start_time_utc, 
>                                                        :date_fmt)) 
>                                               * 86400 / :p_bucket_interval
>                                   ) buckets
>                             WHERE buckets.begin_time_utc < met.end_time_utc
>                               AND buckets.end_time_utc > met.begin_time_utc
>                            )
>                     GROUP BY bucket_id, metric_name)))),
>         db_data AS 
>           (SELECT bucket_id, metric_name, 
>                   SUM(value) as value
>              FROM inst_data
>            GROUP BY bucket_id, metric_name
>           ),
>         final_data AS
>           (SELECT bucket_id, metric_name,
>                   value AS value
>              FROM db_data
>             WHERE value > 0
>           ),
>         base_data AS
>           (SELECT * FROM final_data
>            ORDER BY bucket_id, metric_name)
>       select xmlelement("stattype",
>                xmlattributes('sysmetric' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")
>              ))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     SYSMETRIC_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var date_fmt          varchar2(32);
>       var b_start_time_utc  varchar2(32);
>       var b_end_time_utc    varchar2(32);
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_duration        number;
>       begin 
>         :date_fmt            := '#date_fmt#';
>         :b_start_time_utc    := '#b_start_time_utc#';
>         :b_end_time_utc      := '#b_end_time_utc#';
>         :p_bucket_interval   := #p_bucket_interval#;
>         :p_bucket_count      := #p_bucket_count#;
>         :b_duration          := #b_duration#;
>       end;
>       /]';
> 
>     
>     SYSMETRIC_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT s.instance_number, s.snap_id,
>                   s.metric_name,
>                   CASE 
>                     WHEN s.metric_name = 
>                            'CPU Usage Per Sec' 
>                     THEN s.average/100
>                     ELSE s.average
>                   END as value
>              FROM awr_root_con_sysmetric_summ s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.metric_name IN ('Average Active Sessions',
>                                     'CPU Usage Per Sec',
>                                     'Executions Per Sec',
>                                     'User Calls Per Sec', 
>                                     'Total Parse Count Per Sec',
>                                     'User Commits Per Sec', 
>                                     'User Rollbacks Per Sec', 
>                                     'Session Count',
>                                     'Current Logons Count', 
>                                     'Logons Per Sec',
>                                     'Logons Per Txn',
>                                     'Redo Generated Per Sec',
>                                     'Redo Generated Per Txn',
>                                     'User Transaction Per Sec',
>                                     'Network Traffic Volume Per Sec',
>                                     'Hard Parse Count Per Sec',
>                                     'Parse Failure Count Per Sec',
>                                     'Current Open Cursors Count')
>           ),
>         agg_stats AS
>           (SELECT /*+ no_merge */ instance_number, snap_id, metric_name, 
>                   SUM(value) as value
>              FROM base_stats
>             WHERE value > 0
>            GROUP BY instance_number, snap_id, metric_name
>           ),
>         snap_stats AS 
>           (SELECT a.instance_number, a.snap_id, a.metric_name, a.value,  
>                   s.begin_time_utc, s.end_time_utc
>              FROM agg_stats a, snaps s
>             WHERE a.instance_number = s.instance_number
>               AND a.snap_id = s.snap_id
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400) as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         db_stats AS
>           (SELECT bucket_id, metric_name, 
>                   SUM(value * bucket_ratio) as value
>              FROM (
>                    SELECT b.bucket_id, s.metric_name, s.value,
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM snap_stats s, buckets b
>                     WHERE b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, metric_name
>           ),
>         base_data AS 
>           (SELECT bucket_id, metric_name, value
>              FROM db_stats
>            ORDER BY 1, 2)
>       select xmlelement("stattype",
>                xmlattributes('sysmetric' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     SYSMETRIC_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
> 
>       L_QRY := SYSMETRIC_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := SYSMETRIC_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#', 
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('sysmetric', L_SQL);
> 
>       ELSE
> 
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>     
>     
>     ELSE
>      IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := SYSMETRIC_AWR;
> 
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := SYSMETRIC_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                      L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('sysmetric', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT),
>                 ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SYSMETRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_STORAGE_METRICS_XML(
>     SERVICE_TYPE IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL     IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     STORAGE_SERVERLESS CONSTANT VARCHAR2(32767) := q'[
>       select xmlelement("stattype",
>                xmlattributes(
>                  'storage'         as "name",
>                  max(c.max_size)   as "total",
>                  max(c.total_size) as "used",
>                  decode(max(c.max_size), 0, 0,
>                         (max(c.total_size)/max(c.max_size))*100) 
>                                    as "utilization"))
>         from sys.v_$containers c
>        where c.con_id > 2
>          and c.name <> 'PAASSEED']';
> 
>     
>     STORAGE_DEDICATED CONSTANT VARCHAR2(32767) := q'[
>       select xmlelement("stattype",
>                xmlattributes(
>                  'storage'         as "name",
>                  max(c.max_size)   as "total",
>                  max(c.total_size) as "used",
>                  decode(max(c.max_size), 0, 0,
>                         (max(c.total_size)/max(c.max_size))*100) 
>                                    as "utilization"),
>                xmlelement("tablespaces",
>                  xmlagg(
>                    xmlelement("tbs",
>                      xmlattributes(
>                        m.tablespace_name as "name",
>                        t.contents        as "type",
>                        ROUND((m.tablespace_size)*t.block_size, 3) total_space,
>                        ROUND((m.used_space)*t.block_size, 3) used_space,
>                        ROUND(m.used_percent, 2) used_pct)))))
>         from cdb_tablespace_usage_metrics m, 
>              cdb_tablespaces t,
>              sys.v_$containers c
>        where t.tablespace_name = m.tablespace_name
>          and c.con_id > 2
>          and c.name <> 'PAASSEED'
>          and m.con_id = c.con_id
>          and t.con_id = m.con_id]';
> 
>   BEGIN
> 
>     IF (SERVICE_TYPE IN (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D, 
>                          DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D)) THEN
>       L_QRY := STORAGE_DEDICATED;
>     ELSIF (SERVICE_TYPE IN (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S, 
>                             DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S)) THEN
>       L_QRY := STORAGE_SERVERLESS;
>     ELSE
>       L_QRY := STORAGE_DEDICATED;
>     END IF;
>    
>     
>     IF (SHOW_SQL = 1) THEN
> 
>       
>       L_SQL := L_QRY;
> 
>       
>       L_RESULT_XML := I_SHOW_SQL_XML('storage', L_SQL);
> 
>     ELSE
> 
>       
>       EXECUTE IMMEDIATE L_QRY
>                    INTO L_RESULT_XML;
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_STORAGE_METRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SESSION_METRICS_XML(
>     SHOW_SQL        IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
>   
>     
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML        XMLTYPE := NULL;
>     L_FAILED_LOGONS_XML XMLTYPE := NULL;
> 
>     
>     NUM_CONNECTIONS_RT CONSTANT VARCHAR2(32767) := q'[
>       SELECT xmlelement("stattype",
>                xmlattributes('session' as "name"),
>                xmlelement("num_connections", count(*)))
>         FROM sys.gv_$session s
>        WHERE UPPER(s.service_name) not in 
>              (SELECT p.name FROM sys.v_$pdbs p WHERE p.con_id=s.con_id) 
>          AND UPPER(s.service_name) not in ('SYS$BACKGROUND','SYS$USERS') 
>          AND s.type='USER'
>          AND s.sid not in 
>              (SELECT ps.sid FROM sys.gv_$px_session ps)]';
> 
>     
>     NUM_FAILED_LOGONS_RT CONSTANT VARCHAR2(32767) := q'[
>       SELECT xmlelement("failed_logons", count(*))
>         FROM cdb_unified_audit_trail
>        WHERE action_name = 'LOGON'
>          AND return_code != 0]';
> 
>   BEGIN
>      
>     
>     IF (SHOW_SQL = 1) THEN
> 
>       L_SQL := NUM_CONNECTIONS_RT || NUM_FAILED_LOGONS_RT;
> 
>       
>       L_RESULT_XML := I_SHOW_SQL_XML('session', L_SQL);
> 
>     ELSE
> 
>       
>       EXECUTE IMMEDIATE NUM_CONNECTIONS_RT
>                    INTO L_RESULT_XML;
> 
>       EXECUTE IMMEDIATE NUM_FAILED_LOGONS_RT
>                    INTO L_FAILED_LOGONS_XML;
> 
>       IF (L_FAILED_LOGONS_XML IS NOT NULL) THEN
>         L_RESULT_XML := L_RESULT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                     L_FAILED_LOGONS_XML);
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SESSION_METRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION REPORT_WORKLOAD(
>     SERVICE_TYPE   IN VARCHAR2 DEFAULT NULL,
>     IS_REALTIME    IN NUMBER   DEFAULT 1,
>     DBID           IN NUMBER   DEFAULT NULL,
>     START_TIME     IN DATE     DEFAULT NULL,
>     END_TIME       IN DATE     DEFAULT NULL,
>     REPORT_LEVEL   IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL       IN NUMBER   DEFAULT 0)
>   RETURN XMLTYPE
>   IS
>     
>     L_ELAPSED NUMBER;
>     L_CPU     NUMBER;
> 
>     
>     L_REF_PARAMS DBMS_REPORT.REF_STRING_IDSPEC;
> 
>     
>     L_ORIG_ENV DBMS_REPORT.FORMAT_PARAM_VALUES;
>     L_SET_ENV  BOOLEAN;
> 
>     
>     L_REPORT_XML          XMLTYPE := NULL;
>     L_RM_METRICS_XML      XMLTYPE := NULL;
>     L_SYS_METRICS_XML     XMLTYPE := NULL;
>     L_SQL_TIME_XML        XMLTYPE := NULL;
>     L_WAIT_TIME_XML       XMLTYPE := NULL;
>     L_STORAGE_METRICS_XML XMLTYPE := NULL;
>     L_SESSION_METRICS_XML XMLTYPE := NULL;
> 
>     
>     L_SERVICE_TYPE   VARCHAR2(32767) := SERVICE_TYPE;
>     L_IS_REALTIME    NUMBER          := IS_REALTIME;
>     L_DBID           NUMBER          := DBID;
>     L_START_TIME     DATE            := START_TIME;
>     L_END_TIME       DATE            := END_TIME;
>     L_REPORT_LEVEL   VARCHAR2(32767) := REPORT_LEVEL;
>     L_TZ             VARCHAR2(10)    := NULL;
>     L_START_TIME_UTC DATE            := NULL;
>     L_END_TIME_UTC   DATE            := NULL;
>     L_BEGIN_SNAP_ID  NUMBER          := NULL;
>     L_END_SNAP_ID    NUMBER          := NULL;
> 
>     
>     L_BUCKET_COUNT    NUMBER;
>     L_BUCKET_INTERVAL NUMBER;
> 
>     
>     L_AWR_PERIOD PRVT_AWRV_METADATA;
> 
>     L_SNAP_QRY        VARCHAR2(32767) := NULL;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)    := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_ERRMSG    VARCHAR2(32767);
>     L_ERROR_XML XMLTYPE := NULL;
> 
>     
>     L_RSRCMGR_DETAIL   NUMBER;
>     L_SYSMETRIC_DETAIL NUMBER;
>     L_SQL_TIME_DETAIL  NUMBER;
>     L_WAIT_TIME_DETAIL NUMBER;
>     L_STORAGE_DETAIL   NUMBER;
>     L_SESSION_DETAIL   NUMBER;
> 
>     
>     
>     
>     FUNCTION I_PARSE_REPORT_LEVEL(
>       P_REPORT_LEVEL     IN  VARCHAR2,
>       P_RSRCMGR_DETAIL   OUT NUMBER,
>       P_SYSMETRIC_DETAIL OUT NUMBER,
>       P_SQL_TIME_DETAIL  OUT NUMBER,
>       P_WAIT_TIME_DETAIL OUT NUMBER,
>       P_STORAGE_DETAIL   OUT NUMBER,
>       P_SESSION_DETAIL   OUT NUMBER)
>     RETURN BOOLEAN
>     IS
>       L_REPORT_LEVEL VARCHAR2(32767) := 
>         REPLACE(LOWER(P_REPORT_LEVEL), ' ', NULL);
>       L_POS          NUMBER := 1;
>       L_SETVAL       NUMBER;
>     BEGIN
>       
>       P_RSRCMGR_DETAIL   := 1; 
>       P_SYSMETRIC_DETAIL := 1; 
>       P_SQL_TIME_DETAIL  := 1; 
>       P_WAIT_TIME_DETAIL := 1; 
>       P_STORAGE_DETAIL   := 1; 
>       P_SESSION_DETAIL   := 1; 
> 
>        
>       IF (L_REPORT_LEVEL IS NULL) THEN
>         RETURN TRUE;
>       END IF;
> 
>       
>       L_POS := 1;
> 
>       
>       IF (SUBSTR(L_REPORT_LEVEL, L_POS, 3) = 'all') THEN
>         
>         
>         L_POS := L_POS + 3;
>       
>       ELSIF (SUBSTR(L_REPORT_LEVEL, L_POS, 4) = 'none') THEN
>         P_RSRCMGR_DETAIL := 0;
>         P_SYSMETRIC_DETAIL := 0;
>         P_SQL_TIME_DETAIL := 0;
>         P_WAIT_TIME_DETAIL := 0;
>         P_STORAGE_DETAIL := 0;
>         P_SESSION_DETAIL := 0;
>         L_POS := L_POS + 4;
>       END IF;
> 
>       
>       WHILE (L_POS < LENGTH(L_REPORT_LEVEL))
>       LOOP
>         IF (SUBSTR(L_REPORT_LEVEL, L_POS, 1) = '-') THEN
>           L_SETVAL   := 0;
>           L_POS      := L_POS + 1;
>         ELSE
>           L_SETVAL   := 1;
>           IF (SUBSTR(L_REPORT_LEVEL, L_POS, 1) = '+') THEN
>             L_POS := L_POS + 1;
>           END IF;
>         END IF;
> 
>         CASE
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'rsrcmgr') THEN
>             P_RSRCMGR_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 9) = 'sysmetric') THEN
>             P_SYSMETRIC_DETAIL := L_SETVAL;
>             L_POS := L_POS + 9;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 3) = 'sql') THEN
>             P_SQL_TIME_DETAIL := L_SETVAL;
>             L_POS := L_POS + 3;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 4) = 'wait') THEN
>             P_WAIT_TIME_DETAIL := L_SETVAL;
>             L_POS := L_POS + 4;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'storage') THEN
>             P_STORAGE_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'session') THEN
>             P_SESSION_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
>             
>           ELSE
>             
>             RETURN FALSE;
>         END CASE;
>       END LOOP;
> 
>       
>       RETURN TRUE;
>       
>     END I_PARSE_REPORT_LEVEL;
> 
>   BEGIN
>     
>     
>     L_ORIG_ENV := DBMS_REPORT.FORMAT_PARAM_VALUES();
>     L_SET_ENV  := DBMS_REPORT.SETUP_REPORT_ENV(L_ORIG_ENV);
> 
>     
>     DBMS_REPORT.GET_TIMING_INFO(0, L_ELAPSED, L_CPU);
> 
>     
> 
>     
>     IF (SERVICE_TYPE IS NOT NULL) THEN
>       L_REF_PARAMS('service_type') := SERVICE_TYPE;
>     END IF;
> 
>     IF (IS_REALTIME IS NOT NULL) THEN
>       L_REF_PARAMS('is_realtime') := IS_REALTIME;
>     END IF;
> 
>     IF (DBID IS NOT NULL) THEN
>       L_REF_PARAMS('dbid') := DBID;
>     END IF;
> 
>     IF (START_TIME IS NOT NULL) THEN
>       L_REF_PARAMS('start_time') :=
>         TO_CHAR(START_TIME,DBMS_REPORT.DATE_FMT_MOD);
>     END IF;
> 
>     IF (END_TIME IS NOT NULL) THEN
>       L_REF_PARAMS('end_time') :=
>         TO_CHAR(END_TIME,DBMS_REPORT.DATE_FMT_MOD);
>     END IF;
> 
>     IF (REPORT_LEVEL IS NOT NULL) THEN
>       L_REF_PARAMS('report_level') := REPORT_LEVEL;
>     END IF;
> 
>     IF (SHOW_SQL IS NOT NULL) THEN
>       L_REF_PARAMS('show_sql') := SHOW_SQL; 
>     END IF;
>    
>     
>     
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     IF (DBID IS NULL) THEN
>       L_DBID := SYS_CONTEXT('USERENV','CON_DBID');
>     END IF;
> 
>     
>     IF (REPORT_LEVEL IS NULL) THEN
>       L_REPORT_LEVEL := 'all';
>     END IF;
> 
>     
>     IF (END_TIME IS NULL) THEN
>       L_END_TIME := SYSDATE;
>     END IF;
> 
>     
>     IF (START_TIME IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME := L_END_TIME - 1/24;
>       
>       ELSE
>         L_START_TIME := L_END_TIME - 1;
>       END IF;
>     END IF;
> 
>     
>     L_TZ := DBMS_SQLTUNE_UTIL2.GET_TZ_OFFSET();
>     L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(
>                             TO_TIMESTAMP_TZ(
>                               TO_CHAR(L_END_TIME, 'yyyy-mm-dd hh24:mi:ss') 
>                               || L_TZ,
>                               'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE);
> 
> 
>     
>     L_START_TIME_UTC := CAST(SYS_EXTRACT_UTC(
>                               TO_TIMESTAMP_TZ(
>                                 TO_CHAR(L_START_TIME, 'yyyy-mm-dd hh24:mi:ss') 
>                                 || L_TZ,
>                                 'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE);
> 
>     
>     IF (L_IS_REALTIME = 1) THEN
>       CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
>                         (L_END_TIME - L_START_TIME)*DTOS,
>                         G_METRIC_SOURCE_HISTORY);
>     ELSE
>       
>       CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
>                         (L_END_TIME - L_START_TIME)*DTOS,
>                         NULL);
> 
>       
>       L_SNAP_QRY := q'[
>         SELECT MIN(snap_id)-1, MAX(snap_id)
>           FROM awr_root_snapshot
>          WHERE dbid = :l_dbid
>            AND cast((end_interval_time_tz at time zone 'UTC') as DATE)
>                 > to_date(:l_start_time_utc, :date_fmt)
>            AND cast((begin_interval_time_tz at time zone 'UTC') as DATE)
>                 < to_date(:l_end_time_utc, :date_fmt)]';
> 
>       IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>         L_AWR_VIEW_PREFIX := 
>           DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_START_TIME);
> 
>         DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_SNAP_QRY, 
>                                                    L_AWR_VIEW_PREFIX);
>       END IF;
> 
>       IF (L_AWR_VIEW_PREFIX = DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT) THEN
>         L_DBID := SYS_CONTEXT('USERENV','DBID');
>       END IF;
> 
>       BEGIN
>         EXECUTE IMMEDIATE L_SNAP_QRY
>         INTO L_BEGIN_SNAP_ID, L_END_SNAP_ID
>         USING L_DBID, 
>               TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>               TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT;
>       EXCEPTION
>         WHEN NO_DATA_FOUND THEN
>           L_BEGIN_SNAP_ID := NULL;
>           L_END_SNAP_ID := NULL;
>       END;
> 
>       
>       
>       L_AWR_PERIOD := PRVT_AWRV_METADATA(P_START_TIME => L_START_TIME, 
>                                          P_END_TIME => L_END_TIME,
>                                          P_DBID => L_DBID);
> 
>       L_AWR_PERIOD.M_BEGIN_SNAP := L_BEGIN_SNAP_ID;
>       L_AWR_PERIOD.M_END_SNAP := L_END_SNAP_ID;
>       L_AWR_PERIOD.M_MIN_TIME := L_START_TIME;
>       L_AWR_PERIOD.M_MAX_TIME := L_END_TIME;
> 
>       
>       IF (L_AWR_PERIOD.M_BEGIN_SNAP IS NULL OR
>           L_AWR_PERIOD.M_BEGIN_SNAP = L_AWR_PERIOD.M_END_SNAP)
>       THEN
> 
>         L_ERRMSG := '[' || L_AWR_PERIOD.M_DBID || ']' ||
>                     '[' || L_AWR_PERIOD.M_INST_ID_LOW || '.' ||
>                            L_AWR_PERIOD.M_INST_ID_HIGH || ']' ||
>                     '[' || L_AWR_PERIOD.M_BEGIN_SNAP || '.' || 
>                            L_AWR_PERIOD.M_END_SNAP || ']' ||
>                     '[' || TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, 
>                                    DBMS_REPORT.DATE_FMT) || '-' ||
>                            TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, 
>                                    DBMS_REPORT.DATE_FMT) || ']';
>         
>         L_AWR_PERIOD := NULL;
> 
>         
>         L_ERROR_XML := ERROR_XML('report_workload',
>                                  -20800,
>                                  'Insufficient awr data', 
>                                  L_ERRMSG);
>       ELSE
> 
>         L_ERRMSG := NULL;
>         L_ERROR_XML := NULL;
> 
>       END IF;
> 
>     END IF;
> 
>     
>     IF (NOT I_PARSE_REPORT_LEVEL(L_REPORT_LEVEL, L_RSRCMGR_DETAIL, 
>                                  L_SYSMETRIC_DETAIL, L_SQL_TIME_DETAIL,
>                                  L_WAIT_TIME_DETAIL, L_STORAGE_DETAIL,
>                                  L_SESSION_DETAIL)) THEN
>       SYS.DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(SYS_ERR_PARAM, 'report_level');
>     END IF;
> 
>     
>     IF (L_RSRCMGR_DETAIL = 1) THEN
>       L_RM_METRICS_XML := GET_RMMETRICS_XML(L_IS_REALTIME, 
>                                             L_DBID,
>                                             L_START_TIME,
>                                             L_END_TIME,
>                                             L_BUCKET_COUNT,
>                                             L_BUCKET_INTERVAL,
>                                             L_AWR_PERIOD,
>                                             SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_SYSMETRIC_DETAIL = 1) THEN        
>         L_SYS_METRICS_XML := GET_SYSMETRICS_XML(L_IS_REALTIME,
>                                                 L_DBID,
>                                                 L_START_TIME_UTC,
>                                                 L_END_TIME_UTC,
>                                                 L_BUCKET_COUNT,
>                                                 L_BUCKET_INTERVAL,
>                                                 L_AWR_PERIOD,
>                                                 SHOW_SQL);
>     END IF;
> 
>     
>     
>     
>     
>     
>     IF (L_SQL_TIME_DETAIL = 1) THEN
>       L_SQL_TIME_XML := GET_SQL_N_PARSE_TIME_XML(L_IS_REALTIME,
>                                                  L_DBID,
>                                                  L_START_TIME_UTC,
>                                                  L_END_TIME_UTC,
>                                                  L_BUCKET_COUNT,
>                                                  L_BUCKET_INTERVAL,
>                                                  L_AWR_PERIOD,
>                                                  SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_WAIT_TIME_DETAIL = 1) THEN
>       L_WAIT_TIME_XML := GET_WAIT_TIME_XML(L_IS_REALTIME,
>                                            L_DBID,
>                                            L_START_TIME_UTC,
>                                            L_END_TIME_UTC,
>                                            L_BUCKET_COUNT,
>                                            L_BUCKET_INTERVAL,
>                                            L_AWR_PERIOD,
>                                            SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_STORAGE_DETAIL = 1) THEN
>       L_STORAGE_METRICS_XML := GET_STORAGE_METRICS_XML(L_SERVICE_TYPE,
>                                                        SHOW_SQL);
>     END IF;
> 
>     
>     
>     
>     IF (L_SESSION_DETAIL = 1) THEN
>       L_SESSION_METRICS_XML := GET_SESSION_METRICS_XML(SHOW_SQL);
>     END IF;
> 
>     
>     DBMS_REPORT.GET_TIMING_INFO(1, L_ELAPSED, L_CPU);
> 
>     
>     
>     L_REPORT_XML :=
>       PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
>                          DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
>                            'awrv','topsql', L_REF_PARAMS),
>                          L_ELAPSED, L_CPU);
> 
>     
>     
>     IF (L_RM_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_RM_METRICS_XML);
>     END IF;
> 
>     IF (L_SYS_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_SYS_METRICS_XML);
>     END IF;
> 
>     IF (L_SQL_TIME_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_SQL_TIME_XML);
>     END IF;
> 
>     IF (L_WAIT_TIME_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_WAIT_TIME_XML);
>     END IF;
> 
>     IF (L_STORAGE_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_STORAGE_METRICS_XML);
>     END IF;
>     
>     IF (L_SESSION_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_SESSION_METRICS_XML);
>     END IF;
> 
>     IF (L_ERROR_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_ERROR_XML);
>     END IF;
> 
>     <<DONE>>
>     
>     
>     IF (L_REPORT_XML IS NULL) THEN
>       
>       L_REPORT_XML :=
>         PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
>           DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
>             'awrv','topsql',L_REF_PARAMS),
>           NULL, NULL);
>     END IF;
> 
>     IF (L_SET_ENV) THEN
>       
>       DBMS_REPORT.RESTORE_REPORT_ENV(L_ORIG_ENV);
>     END IF;
>  
>     
>     RETURN L_REPORT_XML;
> 
>   END REPORT_WORKLOAD;
> 
> 
SYS.PRVT_AWRV_METADATA - TYPE BODY (RU):
288,290c288,294
<         IF (M_RESOLVED_DB_TYPE 
<           IN (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, 
<                 DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP))
---
> 
>         IF (M_RESOLVED_DB_TYPE IN
>               (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, 
>                DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP)
>             AND
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(P_START_TIME) = 
>               DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB)
432c436,438
<     IF (SYS.DBMS_SQLTUNE_UTIL0.CDB_IS_PDB(L_CON_NAME, L_CON_ID)) THEN  
---
>     IF (SYS.DBMS_SQLTUNE_UTIL0.CDB_IS_PDB(L_CON_NAME, L_CON_ID) AND
>         DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(P_START_TIME) = 
>           DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB) THEN  
SYS.WRI$_REPT_AWRV - TYPE BODY (RU):
62a63,65
>     P_INCLUDE_SQLS     NUMBER := 1;
>     P_JET              NUMBER := 0;
>     L_SERVICE_TYPE     VARCHAR2(32);
532,537d534
<       P_LAST_REFRESH_TIME := TO_DATE(
<                                DBMS_REPORT.GET_PARAM(PARAMS,
<                                                       'last_refresh_time',
<                                                       NULLABLE=>TRUE),
<                                DBMS_REPORT.DATE_FMT_MOD);
< 
539,540c536
<       P_INST_ID := TO_NUMBER(
<                      DBMS_REPORT.GET_PARAM(PARAMS,'inst_id',NULLABLE=>TRUE));
---
>       P_DBID := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'dbid',NULLABLE=>TRUE));
543c539,540
<       P_DBID := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'dbid',NULLABLE=>TRUE));
---
>       P_INST_ID := TO_NUMBER(
>                        DBMS_REPORT.GET_PARAM(PARAMS,'inst_id',NULLABLE=>TRUE));
553a551
>       L_SERVICE_TYPE := DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE();
556,557c554
<       P_TOP_N_DETAIL := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'top_n_detail',
<                                                    NULLABLE=>TRUE));
---
>       P_JET := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'is_jet', NULLABLE=>TRUE));
560,564d556
<       P_OUTER_START_TIME := TO_DATE(
<                               DBMS_REPORT.GET_PARAM(PARAMS,'outer_start_time',
<                                                     NULLABLE=>TRUE),
<                               DBMS_REPORT.DATE_FMT_MOD);
< 
566,569c558,577
<       P_OUTER_END_TIME := TO_DATE(
<                       DBMS_REPORT.GET_PARAM(PARAMS,'outer_end_time',
<                                                     NULLABLE=>TRUE),
<                             DBMS_REPORT.DATE_FMT_MOD);
---
>       IF (P_JET = 1 OR
>           (L_SERVICE_TYPE IN 
>             (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D)
>            AND SYS_CONTEXT('USERENV', 'CON_ID') > 2)) THEN
> 
>         
>         P_REPORT_LEVEL := DBMS_REPORT.GET_PARAM(PARAMS,'report_level',
>                                                 NULLABLE=>TRUE);
> 
>         REPORT_XML := PRVT_AWR_VIEWER.REPORT_WORKLOAD(
>                         SERVICE_TYPE => L_SERVICE_TYPE,
>                         IS_REALTIME  => P_IS_REALTIME,
>                         START_TIME   => P_START_TIME,
>                         END_TIME     => P_END_TIME,
>                         DBID         => P_DBID,
>                         REPORT_LEVEL => P_REPORT_LEVEL,
>                         SHOW_SQL     => P_SHOW_SQL);
572,573c580
<       P_DIM_NAME := DBMS_REPORT.GET_PARAM(PARAMS,'dim_name',NULLABLE=>TRUE);
<       P_DIM_STAT := DBMS_REPORT.GET_PARAM(PARAMS,'dim_stat',NULLABLE=>TRUE);
---
>       ELSE
575,587c582,601
<       REPORT_XML := PRVT_AWR_VIEWER.REPORT_TOPSQL_XML(
<                       START_TIME        => P_START_TIME,
<                       END_TIME          => P_END_TIME,
<                       LAST_REFRESH_TIME => P_LAST_REFRESH_TIME,
<                       INST_ID           => P_INST_ID,
<                       DBID              => P_DBID,
<                       IS_REALTIME       => P_IS_REALTIME,
<                       TOP_N_DETAIL      => P_TOP_N_DETAIL,
<                       OUTER_START_TIME  => P_OUTER_START_TIME,
<                       OUTER_END_TIME    => P_OUTER_END_TIME,
<                       DIM_NAME          => P_DIM_NAME,
<                       DIM_STAT          => P_DIM_STAT,
<                       SHOW_SQL          => P_SHOW_SQL);
---
>         
>         P_INCLUDE_SQLS := TO_NUMBER(
>                             DBMS_REPORT.GET_PARAM(PARAMS,'include_sqls', 
>                                                   NULLABLE=>TRUE));
> 
>         P_LAST_REFRESH_TIME := TO_DATE(
>                                  DBMS_REPORT.GET_PARAM(PARAMS,
>                                                         'last_refresh_time',
>                                                         NULLABLE=>TRUE),
>                                  DBMS_REPORT.DATE_FMT_MOD);
> 
>         
>         P_TOP_N_DETAIL := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'top_n_detail',
>                                                      NULLABLE=>TRUE));
> 
>         
>         P_OUTER_START_TIME := TO_DATE(
>                                 DBMS_REPORT.GET_PARAM(PARAMS,'outer_start_time',
>                                                       NULLABLE=>TRUE),
>                                 DBMS_REPORT.DATE_FMT_MOD);
588a603,627
>         
>         P_OUTER_END_TIME := TO_DATE(
>                               DBMS_REPORT.GET_PARAM(PARAMS,'outer_end_time',
>                                                     NULLABLE=>TRUE),
>                               DBMS_REPORT.DATE_FMT_MOD);
> 
>         
>         P_DIM_NAME := DBMS_REPORT.GET_PARAM(PARAMS,'dim_name',NULLABLE=>TRUE);
>         P_DIM_STAT := DBMS_REPORT.GET_PARAM(PARAMS,'dim_stat',NULLABLE=>TRUE);
> 
>         REPORT_XML := PRVT_AWR_VIEWER.REPORT_TOPSQL_XML(
>                         START_TIME        => P_START_TIME,
>                         END_TIME          => P_END_TIME,
>                         LAST_REFRESH_TIME => P_LAST_REFRESH_TIME,
>                         INST_ID           => P_INST_ID,
>                         DBID              => P_DBID,
>                         IS_REALTIME       => P_IS_REALTIME,
>                         TOP_N_DETAIL      => P_TOP_N_DETAIL,
>                         OUTER_START_TIME  => P_OUTER_START_TIME,
>                         OUTER_END_TIME    => P_OUTER_END_TIME,
>                         DIM_NAME          => P_DIM_NAME,
>                         DIM_STAT          => P_DIM_STAT,
>                         INCLUDE_SQLS      => P_INCLUDE_SQLS,
>                         SHOW_SQL          => P_SHOW_SQL);
>       END IF;
CTXSYS.DRVDDL - PACKAGE BODY (RU):
1179a1180
>     L_IDX := DRIXMD.GETINDEXRECBYID(IDXID);
1203a1205,1209
>     
>     IF (L_IDXTYPE = 'CONTEXT_V2' AND IS_PART) THEN
>       DRVXTAB.CREATE_INDEX_INDEXES(L_IDX, PARDEG=>PARA, SYSPART=>TRUE);
>     END IF;
> 
1285a1292,1305
>     
>     
>     
>     IF (L_IDXT = DRIXMD.IDX_TYPE_CONTEXT2) THEN
>       DRVXTAB.CREATE_INDEX_TABLES(L_IDX, SYS_PART=>IS_SYS_PART);
> 
>       
>       
>       IF (NOT IS_SYS_PART) THEN
>         DRVXTAB.CREATE_INDEX_INDEXES(L_IDX, PARDEG=>PARA,
>                                      SYSPART=>IS_SYS_PART);
>       END IF;
>     END IF;
> 
1371c1391,1397
<   DRVXTAB.CREATE_INDEX_INDEXES(L_IDX, PARDEG=> PARA, SYSPART=>IS_SYS_PART);
---
> 
>   
>   
>   
>   IF (NOT IS_SYS_PART) THEN
>     DRVXTAB.CREATE_INDEX_INDEXES(L_IDX, PARDEG=> PARA, SYSPART=>IS_SYS_PART);
>   END IF;
DVSYS.DBMS_MACADM - PACKAGE BODY (RU):
2615a2616,2621
>     
>     
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PATCH%' THEN
>       RETURN 'Y';
>     ELSIF (TMP2) LIKE '%_LOG_SEGMENT_DUMP_PARAMETER%' THEN
>       RETURN 'Y';
MDSYS.SDO_JOIN - FUNCTION (RU):
9a10,17
>     G_TABNAM1    VARCHAR2(130);
>     G_TABNAM1_NQ VARCHAR2(130);
>     G_TABNAM2    VARCHAR2(130);
>     G_TABNAM2_NQ VARCHAR2(130);
>     G_COLNAM1    VARCHAR2(1024);
>     G_COLNAM1_NQ VARCHAR2(1024);
>     G_COLNAM2    VARCHAR2(1024);
>     G_COLNAM2_NQ VARCHAR2(1024);
24d31
<     PART1       VARCHAR2(130);
27,29d33
<     PART2       VARCHAR2(130);
<     COLS        SYS.ODCICOLINFOLIST;
<     COLS2       SYS.ODCICOLINFOLIST;
70a75,76
>     TPTN1_NQ    VARCHAR2(130) := NULL;
>     TPTN2_NQ    VARCHAR2(130) := NULL;
74a81,84
>     TPTN1_IDEN  NUMBER;
>     TPTN2_IDEN  NUMBER;
>     TPTN1_IDEN_STR VARCHAR2(100);
>     TPTN2_IDEN_STR VARCHAR2(100);
79,80d88
<     TABLE1_IDX_PARTITION_STR VARCHAR2(128) := 'null';
<     TABLE2_IDX_PARTITION_STR VARCHAR2(128) := 'null';
126a135
>     TSTSTR := SYS.DBMS_ASSERT.ENQUOTE_LITERAL(PARAMS);
127a137,138
>     BEGIN
> 
129,132c140,148
<     TABLE_NAME11 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABLE_NAME1);
<     TABLE_NAME22 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABLE_NAME2);
<     TNAME1 := TABLE_NAME11;
<     TNAME2 := TABLE_NAME22;
---
>     SELECT INSTR(TABLE_NAME1, '.') INTO LEN FROM SYS.DUAL;
>     IF (LEN > 0) THEN
>       TNAME1 := SUBSTR(TABLE_NAME1, LEN+1);
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TNAME1) ) THEN
>         G_TABNAM1 := TNAME1;
>       ELSE
>         G_TABNAM1 := REPLACE(NLS_UPPER(TNAME1), '"');
>       END IF;
>       G_TABNAM1_NQ := REPLACE(G_TABNAM1, '"');
134,136c150,164
<     TSTSTR := SYS.DBMS_ASSERT.ENQUOTE_LITERAL(PARAMS);
<     BEGIN 
<     SELECT INSTR(TABLE_NAME11, '.') INTO LEN FROM SYS.DUAL;
---
>       SELECT SDO_UTIL.GET_QUOTED_NAME(RPAD(TABLE_NAME1, LEN-1)) INTO SCHEMA1
>       FROM SYS.DUAL;
>     ELSE
>       SELECT SYS_CONTEXT('USERENV', 'CURRENT_USER') INTO SCHEMA1
>       FROM SYS.DUAL;
>       TNAME1 := TABLE_NAME1;
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TNAME1) ) THEN
>         G_TABNAM1 := TNAME1;
>       ELSE
>         G_TABNAM1 := REPLACE(NLS_UPPER(TNAME1), '"');
>       END IF;
>       G_TABNAM1_NQ := REPLACE(G_TABNAM1, '"');
>     END IF;
> 
>     SELECT INSTR(TABLE_NAME2, '.') INTO LEN FROM SYS.DUAL;
138,139c166,175
<       TNAME1 :=  NLS_UPPER(SUBSTR(TABLE_NAME11, LEN+1)) ;
<       SELECT SDO_UTIL.GET_QUOTED_NAME(RPAD(TABLE_NAME11, LEN-1)) INTO SCHEMA1 FROM SYS.DUAL;
---
>       TNAME2 := SUBSTR(TABLE_NAME2, LEN+1);
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TNAME2) ) THEN
>         G_TABNAM2 := TNAME2;
>       ELSE
>         G_TABNAM2 := REPLACE(NLS_UPPER(TNAME2), '"');
>       END IF;
>       G_TABNAM2_NQ := REPLACE(G_TABNAM2, '"');
> 
>       SELECT SDO_UTIL.GET_QUOTED_NAME(RPAD(TABLE_NAME2, LEN-1)) INTO SCHEMA2
>       FROM SYS.DUAL;
141,142c177,185
<       SELECT SYS_CONTEXT('USERENV', 'CURRENT_USER') INTO SCHEMA1 FROM SYS.DUAL;
<       TNAME1 := NLS_UPPER(TABLE_NAME11);
---
>       SELECT SYS_CONTEXT('USERENV', 'CURRENT_USER') INTO SCHEMA2
>       FROM SYS.DUAL;
>       TNAME2 := TABLE_NAME2;
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TNAME2) ) THEN
>         G_TABNAM2 := TNAME2;
>       ELSE
>         G_TABNAM2 := REPLACE(NLS_UPPER(TNAME2), '"');
>       END IF;
>       G_TABNAM2_NQ := REPLACE(G_TABNAM2, '"');
143a187,192
> 
>     TABLE_NAME11 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM1);
>     TABLE_NAME22 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM2);
>     TNAME1 := TABLE_NAME11;
>     TNAME2 := TABLE_NAME22;
> 
148,155d196
<     SELECT INSTR(TABLE_NAME22, '.') INTO LEN FROM SYS.DUAL;
<     IF (LEN > 0) THEN
<       TNAME2 :=  NLS_UPPER(SUBSTR(TABLE_NAME22, LEN+1)) ;
<       SELECT SDO_UTIL.GET_QUOTED_NAME(RPAD(TABLE_NAME22, LEN-1)) INTO SCHEMA2 FROM SYS.DUAL;
<     ELSE
<       SELECT SYS_CONTEXT('USERENV', 'CURRENT_USER') INTO SCHEMA2 FROM SYS.DUAL;
<       TNAME2 := NLS_UPPER(TABLE_NAME22);
<     END IF;
161c202,208
<       TPTN1 := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NLS_UPPER(TABLE1_PARTITION));
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE1_PARTITION) ) THEN
>         TPTN1 := TABLE1_PARTITION;
>       ELSE
>         TPTN1 := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(REPLACE(NLS_UPPER(TABLE1_PARTITION), '"'));
>       END IF;
>       TPTN1_NQ := REPLACE(TPTN1, '"');
> 
163a211
> 
165c213,219
<       TPTN2 := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NLS_UPPER(TABLE2_PARTITION));
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE2_PARTITION) ) THEN
>         TPTN2 := TABLE2_PARTITION;
>       ELSE
>         TPTN2 := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(REPLACE(NLS_UPPER(TABLE2_PARTITION), '"'));
>       END IF;
>       TPTN2_NQ := REPLACE(TPTN2, '"');
> 
170c224,238
<     FNAME_LEN := INSTR(COLUMN_NAME1, '(');
---
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME1) ) THEN
>       G_COLNAM1 := COLUMN_NAME1;
>     ELSE
>       G_COLNAM1 := REPLACE(NLS_UPPER(COLUMN_NAME1), '"');
>     END IF;
>     G_COLNAM1_NQ := REPLACE(G_COLNAM1, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME2) ) THEN
>       G_COLNAM2 := COLUMN_NAME2;
>     ELSE
>       G_COLNAM2 := REPLACE(NLS_UPPER(COLUMN_NAME2), '"');
>     END IF;
>     G_COLNAM2_NQ := REPLACE(G_COLNAM2, '"');
> 
>     FNAME_LEN := INSTR(G_COLNAM1, '(');
174,175c242
<       INP_COL_NAME1 := 
<         NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME1));
---
>       INP_COL_NAME1 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM1);
179c246
<       INP_COL_NAME1 := MDSYS.PRVT_IDX.ASSERT_FNCOL(NLS_UPPER(COLUMN_NAME1));
---
>       INP_COL_NAME1 := MDSYS.PRVT_IDX.ASSERT_FNCOL(NLS_UPPER(G_COLNAM1));
193c260
<     FNAME_LEN := INSTR(COLUMN_NAME2, '(');
---
>     FNAME_LEN := INSTR(G_COLNAM2, '(');
197,198c264
<       INP_COL_NAME2 := 
<         NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME2));
---
>       INP_COL_NAME2 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM2);
202c268
<       INP_COL_NAME2 := MDSYS.PRVT_IDX.ASSERT_FNCOL(NLS_UPPER(COLUMN_NAME2));
---
>       INP_COL_NAME2 := MDSYS.PRVT_IDX.ASSERT_FNCOL(G_COLNAM2);
224,228c290,296
<       SELECT DISTINCT SDO_INDEX_OWNER, INDEX_NAME INTO IOWN1, INAME1
<         FROM MDSYS.ALL_SDO_INDEX_INFO 
<              WHERE TABLE_NAME = TNAME1 
<              AND COLUMN_NAME = INP_COL_NAME1 
<              AND TABLE_OWNER = SCHEMA1 ;
---
>       STMT := 'SELECT distinct sdo_index_owner, index_name ' ||
>               'FROM mdsys.all_sdo_index_info ' ||
>               'WHERE table_name = :tab ' ||
>               'and column_name = :col ' ||
>               'and table_owner = :sch';
>       EXECUTE IMMEDIATE STMT INTO IOWN1, INAME1
>         USING G_TABNAM1_NQ, G_COLNAM1_NQ, SCHEMA1;
241,245c309,315
<       SELECT DISTINCT SDO_INDEX_OWNER, INDEX_NAME INTO IOWN2, INAME2
<         FROM MDSYS.ALL_SDO_INDEX_INFO 
<              WHERE TABLE_NAME = TNAME2 
<              AND COLUMN_NAME = INP_COL_NAME2
<              AND TABLE_OWNER = SCHEMA2 ;
---
>       STMT := 'SELECT distinct sdo_index_owner, index_name ' ||
>               'FROM mdsys.all_sdo_index_info ' ||
>               'WHERE table_name = :tab ' ||
>               'and column_name = :col ' ||
>               'and table_owner = :sch';
>       EXECUTE IMMEDIATE STMT INTO IOWN2, INAME2
>         USING G_TABNAM2_NQ, G_COLNAM2_NQ, SCHEMA2;
250,252c320,324
<                                        TNAME1,
<                                        INP_COL_NAME1, 
<                                        NDIM1, SRID1);
---
>                                        G_TABNAM1,
>                                        G_COLNAM1, 
>                                        NDIM1,
>                                        SRID1);
> 
254,256c326,330
<                                        TNAME2,
<                                        INP_COL_NAME2, 
<                                        NDIM2, SRID2);    
---
>                                        G_TABNAM2,
>                                        G_COLNAM2, 
>                                        NDIM2,
>                                        SRID2);    
> 
268,270c342,348
<       SELECT COLUMN_NAME INTO COL_NAME11 FROM SYS.ALL_IND_COLUMNS 
<         WHERE INDEX_OWNER = IOWN1 AND INDEX_NAME = INAME1 ;
<        COL_NAME1 := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(COL_NAME11);
---
>       STMT := 'SELECT column_name ' ||
>               'FROM sys.all_ind_columns ' ||
>               'WHERE index_owner = :own ' ||
>               'AND index_name = :idx';
>       EXECUTE IMMEDIATE STMT INTO COL_NAME11
>         USING IOWN1, INAME1;
>       COL_NAME1 := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(COL_NAME11);
274,275c352,357
<       SELECT COLUMN_NAME INTO COL_NAME22 FROM SYS.ALL_IND_COLUMNS 
<         WHERE INDEX_OWNER = IOWN2 AND INDEX_NAME = INAME2;
---
>       STMT := 'SELECT column_name ' ||
>               'FROM sys.all_ind_columns ' ||
>               'WHERE index_owner = :own ' ||
>               'AND index_name = :idx';
>       EXECUTE IMMEDIATE STMT INTO COL_NAME22
>         USING IOWN2, INAME2;
284,290c366,375
<       STMT := 'SELECT /*+ RESULT_CACHE */ partition_name FROM sys.all_ind_partitions ' ||
<               ' WHERE index_owner = :1  and  ' ||
<               ' index_name = :2 and  partition_position = ' ||
<               ' (SELECT partition_position FROM ' ||
<               ' sys.all_tab_partitions ' ||
<               ' WHERE table_name = :3  and partition_name = :4 '  || 
<                  ' and table_owner = :5 ) ';
---
>       STMT := 'SELECT /*+ RESULT_CACHE */ partition_name ' ||
>               'FROM sys.all_ind_partitions ' ||
>               'WHERE index_owner = :1 ' ||
>               'AND index_name = :2 ' ||
>               'AND partition_position = ' ||
>               ' (SELECT partition_position ' ||
>               '  FROM sys.all_tab_partitions ' ||
>               '  WHERE table_name = :3 ' ||
>               '  AND partition_name = :4 '  || 
>               '  AND table_owner = :5) ';
292c377
<         USING IOWN1, INAME1, TNAME1, TPTN1, SCHEMA1;
---
>         USING IOWN1, INAME1, G_TABNAM1_NQ, TPTN1_NQ, SCHEMA1;
293a379
>       TPTN1_IDEN := SDO_UTIL.GET_TABLE_PTN_OBJ_ID(IOWN1, G_TABNAM1_NQ, TPTN1_NQ);
296a383
>       TPTN1_IDEN_STR := SDO_UTIL.NUMBER_TO_CHAR(TPTN1_IDEN);
301c388
<                 ',' || TNAME11 || ', ''"' || COL_NAME1 || 
---
>                 ',' || TNAME11 || ', ''"' || REPLACE(COL_NAME1, '"') || 
303c390
<                 TPTN11 || ', 0,0,1,1)), ' || 
---
>                 TPTN11 || ', 0,0,' || TPTN1_IDEN_STR || ',1)), ' || 
307a395
> 
314,317d401
< 
< 
<       TABLE1_IDX_PARTITION_STR := SYS.DBMS_ASSERT.ENQUOTE_LITERAL(
<         REPLACE(SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), '''',''''''));
323c407
<                 ',' || TNAME11 || ', ''"' || COL_NAME1 || 
---
>                 ',' || TNAME11 || ', ''"' || REPLACE(COL_NAME1, '"') || 
333d416
< 
350c433
<         USING IOWN2, INAME2, TNAME2, TPTN2, SCHEMA2;
---
>         USING IOWN2, INAME2, G_TABNAM2_NQ, TPTN2_NQ, SCHEMA2;
351a435
>       TPTN2_IDEN := SDO_UTIL.GET_TABLE_PTN_OBJ_ID(IOWN2, G_TABNAM2_NQ, TPTN2_NQ);
354a439
>       TPTN2_IDEN_STR := SDO_UTIL.NUMBER_TO_CHAR(TPTN2_IDEN);
359c444
<                 ',' || TNAME22 || ', ''"' || COL_NAME2 ||
---
>                 ',' || TNAME22 || ', ''"' || REPLACE(COL_NAME2, '"') ||
361c446
<                 TPTN22 || ', 0, 0,1,1)), ' || 
---
>                 TPTN22 || ', 0, 0,' || TPTN2_IDEN_STR || ',1)), ' || 
373,376d457
< 
< 
<      TABLE2_IDX_PARTITION_STR := SYS.DBMS_ASSERT.ENQUOTE_LITERAL(
<         REPLACE(SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), '''',''''''));
382c463
<                 ',' || TNAME22 || ', ''"' || COL_NAME2 || 
---
>                 ',' || TNAME22 || ', ''"' || REPLACE(COL_NAME2, '"') || 
393d473
< 
485,488c565,573
<         FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
---
>         IF ( IPTN1 IS NULL ) THEN
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE);
>         ELSE
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME1), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
>         END IF;
496,499c581,589
<         FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
---
>         IF ( IPTN2 IS NULL ) THEN
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE);
>         ELSE
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NITABNAME2), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
>         END IF;
507,510c597,605
<         FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
---
>         IF ( IPTN1 IS NULL ) THEN
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE);
>         ELSE
>           FULLTABNM1 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME1), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN1), FALSE) || ' ) ';
>         END IF;
518,521c613,621
<         FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE) ||
<           ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
---
>         IF ( IPTN2 IS NULL ) THEN
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE);
>         ELSE
>           FULLTABNM2 := SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(ITABNAME2), FALSE) ||
>             ' PARTITION ( ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IPTN2), FALSE) || ' ) ';
>         END IF;
MDSYS.MDPRVT_IDX - PACKAGE (RU):
106a107
>     SDO_RTREE_READ_ONLY       IN NUMBER,
MDSYS.PRVT_IDX - PACKAGE (RU):
119a120
> 
MDSYS.SDO_IDX - PACKAGE (RU):
134a135
>     SDO_RTREE_READ_ONLY       IN NUMBER,
MDSYS.SDO_UTIL - PACKAGE (RU):
23a24,29
>   -- Get the object ID of the specified table partition (as table owner)
>   FUNCTION get_table_ptn_obj_id(table_owner IN VARCHAR2,
>                                 table_name IN VARCHAR2,
>                                 table_ptn IN VARCHAR2 DEFAULT NULL)
>   return NUMBER;
> 
54a61,66
> 
>   -- Is object name double-quoted and bumpy-case?
>   -- FALSE=NO, TRUE=YES
>   FUNCTION is_bumpy_case(name IN VARCHAR2,
>                          skip_quotes IN boolean default FALSE)
>   RETURN boolean DETERMINISTIC;
MDSYS.MDPRVT_GMD - PACKAGE BODY (RU):
29c29
<     IF(OWNER_IN = CURR_USER)  THEN
---
>     IF(OWNER_IN = CURR_USER) THEN
136,139c136
<     GET_GEOM_METADATA_INT(ISNAME,
<                           NLS_UPPER(ITAB),
<                           NLS_UPPER(ICOL),
<                           NDIM, SRID);
---
>     GET_GEOM_METADATA_INT(ISNAME, ITAB, ICOL, NDIM, SRID);
152,155c149
<     GET_GEOM_METADATA(ISNAME,
<                       NLS_UPPER(ITAB),
<                       NLS_UPPER(ICOL),
<                       NDIM, SRID);
---
>     GET_GEOM_METADATA(ISNAME, ITAB, ICOL, NDIM, SRID);
177,180c171,173
<     GET_GEOM_METADATA_INT(ISNAME,
<                           NLS_UPPER(ITAB),
<                           NLS_UPPER(ICOL),
<                           NDIM, SRID);
---
>     GET_GEOM_METADATA_INT(ISNAME, ITAB, ICOL, NDIM, SRID);
> 
>     
194,197c187
<       GET_GEOM_DIMINFO_INT(ISNAME,
<                            NLS_UPPER(ITAB),
<                            NLS_UPPER(ICOL),
<                            DIMINFO);
---
>       GET_GEOM_DIMINFO_INT(ISNAME, ITAB, ICOL, DIMINFO);
213,216c203
<     GET_GEOM_METADATA(ISNAME,
<                       NLS_UPPER(ITAB),
<                       NLS_UPPER(ICOL),
<                       NDIM, SRID, DIMINFO);
---
>     GET_GEOM_METADATA(ISNAME, ITAB, ICOL, NDIM, SRID, DIMINFO);
231,232c218,219
<                                     ITAB IN VARCHAR2,
<                                     ICOL IN VARCHAR2)
---
>                                     ITAB IN VARCHAR2, 
>                                     ICOL IN VARCHAR2) 
237,240c224,226
<     GET_GEOM_METADATA_INT(ISNAME,
<                           NLS_UPPER(ITAB),
<                           NLS_UPPER(ICOL),
<                           NDIM, SRID);
---
>     GET_GEOM_METADATA_INT(ISNAME, ITAB, ICOL, NDIM, SRID);
> 
>     
MDSYS.MDPRVT_IDX - PACKAGE BODY (RU):
70a71
>     SDO_RTREE_READ_ONLY,
152a154
>     SDO_RTREE_READ_ONLY      CONSTANT NUMBER := 0;
219a222
>       SDO_RTREE_READ_ONLY,
260a264
>       ',' || SDO_RTREE_READ_ONLY ||
542c546
<         TMP_NAME := 'TMP_' || SYS.DBMS_ASSERT.NOOP(ITAB1);
---
>         TMP_NAME := 'TMP_' || ITAB1;
568,573c572,577
<         SET SDO_INDEX_NAME = SYS.DBMS_ASSERT.NOOP(TMP_NAME),
<             SDO_INDEX_OWNER = SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA), 
<             SDO_TSNAME = SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA), 
<             SDO_INDEX_TABLE = SYS.DBMS_ASSERT.NOOP(ITAB2),
<             SDO_NL_INDEX_TABLE = SYS.DBMS_ASSERT.NOOP(NITAB2),
<             SDO_RTREE_SEQ_NAME = SYS.DBMS_ASSERT.NOOP(ISEQ2),
---
>         SET SDO_INDEX_NAME = TMP_NAME,
>             SDO_INDEX_OWNER = IA1.INDEXSCHEMA, 
>             SDO_TSNAME = IA1.INDEXSCHEMA, 
>             SDO_INDEX_TABLE = ITAB2,
>             SDO_NL_INDEX_TABLE = NITAB2,
>             SDO_RTREE_SEQ_NAME = ISEQ2,
576,579c580,583
<         WHERE SDO_INDEX_TABLE = SYS.DBMS_ASSERT.NOOP(ITAB1)
<         AND SDO_INDEX_NAME = SYS.DBMS_ASSERT.NOOP(IA.INDEXNAME)
<         AND SDO_INDEX_OWNER = SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA)
<         AND SDO_INDEX_PARTITION = SYS.DBMS_ASSERT.NOOP(IA.INDEXPARTITION);
---
>         WHERE SDO_INDEX_TABLE = ITAB1
>         AND SDO_INDEX_NAME = IA.INDEXNAME
>         AND SDO_INDEX_OWNER = IA.INDEXSCHEMA
>         AND SDO_INDEX_PARTITION = IA.INDEXPARTITION;
583,586c587,590
<         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA),
<                                           SYS.DBMS_ASSERT.NOOP(IA.INDEXNAME),
<                                           SYS.DBMS_ASSERT.NOOP(IA.INDEXPARTITION),
<                                           SYS.DBMS_ASSERT.NOOP(ITAB1));
---
>         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(IA.INDEXSCHEMA,
>                                           IA.INDEXNAME,
>                                           IA.INDEXPARTITION,
>                                           ITAB1);
598,604c602,608
<         SET SDO_INDEX_NAME = SYS.DBMS_ASSERT.NOOP(IA.INDEXNAME),
<             SDO_INDEX_OWNER = SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA), 
<             SDO_TSNAME = SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA), 
<             SDO_INDEX_TABLE = SYS.DBMS_ASSERT.NOOP(ITAB1),
<             SDO_NL_INDEX_TABLE = SYS.DBMS_ASSERT.NOOP(NITAB1),
<             SDO_RTREE_SEQ_NAME = SYS.DBMS_ASSERT.NOOP(ISEQ1),
<             SDO_INDEX_PARTITION = SYS.DBMS_ASSERT.NOOP(IA.INDEXPARTITION),
---
>         SET SDO_INDEX_NAME = IA.INDEXNAME,
>             SDO_INDEX_OWNER = IA.INDEXSCHEMA, 
>             SDO_TSNAME = IA.INDEXSCHEMA, 
>             SDO_INDEX_TABLE = ITAB1,
>             SDO_NL_INDEX_TABLE = NITAB1,
>             SDO_RTREE_SEQ_NAME = ISEQ1,
>             SDO_INDEX_PARTITION = IA.INDEXPARTITION,
606,608c610,612
<          WHERE SDO_INDEX_TABLE = SYS.DBMS_ASSERT.NOOP(ITAB2)
<          AND SDO_INDEX_NAME = SYS.DBMS_ASSERT.NOOP(IA1.INDEXNAME)
<          AND SDO_INDEX_OWNER = SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA)
---
>          WHERE SDO_INDEX_TABLE = ITAB2
>          AND SDO_INDEX_NAME = IA1.INDEXNAME
>          AND SDO_INDEX_OWNER = IA1.INDEXSCHEMA
613,616c617,620
<         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA),
<                                           SYS.DBMS_ASSERT.NOOP(IA1.INDEXNAME),
<                                           SYS.DBMS_ASSERT.NOOP(IA1.INDEXPARTITION),
<                                           SYS.DBMS_ASSERT.NOOP(ITAB2));
---
>         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(IA1.INDEXSCHEMA,
>                                           IA1.INDEXNAME,
>                                           IA1.INDEXPARTITION,
>                                           ITAB2);
627,628c631,632
<         SET SDO_INDEX_NAME = SYS.DBMS_ASSERT.NOOP(IA1.INDEXNAME)
<         WHERE SDO_INDEX_NAME = SYS.DBMS_ASSERT.NOOP(TMP_NAME);
---
>         SET SDO_INDEX_NAME = IA1.INDEXNAME
>         WHERE SDO_INDEX_NAME = TMP_NAME;
642,644c646,648
<         SET SDO_INDEX_NAME= SYS.DBMS_ASSERT.NOOP(IA1.INDEXNAME),  
<             SDO_INDEX_OWNER= SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA), 
<             SDO_TSNAME=SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA), 
---
>         SET SDO_INDEX_NAME= IA1.INDEXNAME,  
>             SDO_INDEX_OWNER= IA1.INDEXSCHEMA, 
>             SDO_TSNAME=IA1.INDEXSCHEMA, 
647,649c651,653
<         WHERE SDO_INDEX_TABLE= SYS.DBMS_ASSERT.NOOP(ITAB1)
<         AND SDO_INDEX_NAME= SYS.DBMS_ASSERT.NOOP(IA.INDEXNAME)
<         AND SDO_INDEX_OWNER= SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA);
---
>         WHERE SDO_INDEX_TABLE= ITAB1
>         AND SDO_INDEX_NAME= IA.INDEXNAME
>         AND SDO_INDEX_OWNER= IA.INDEXSCHEMA;
653,656c657,660
<         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA),
<                                           SYS.DBMS_ASSERT.NOOP(IA.INDEXNAME),
<                                           SYS.DBMS_ASSERT.NOOP(IA.INDEXPARTITION),
<                                           SYS.DBMS_ASSERT.NOOP(ITAB1));
---
>         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(IA.INDEXSCHEMA,
>                                           IA.INDEXNAME,
>                                           IA.INDEXPARTITION,
>                                           ITAB1);
668c672
<         SET SDO_INDEX_NAME= SYS.DBMS_ASSERT.NOOP(IA.INDEXNAME),
---
>         SET SDO_INDEX_NAME= IA.INDEXNAME,
670,675c674,679
<             SDO_INDEX_OWNER= SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA), 
<             SDO_TSNAME= SYS.DBMS_ASSERT.NOOP(IA.INDEXSCHEMA), 
<             SDO_INDEX_PARTITION= SYS.DBMS_ASSERT.NOOP(IA.INDEXPARTITION) 
<          WHERE SDO_INDEX_TABLE= SYS.DBMS_ASSERT.NOOP(ITAB2)
<          AND SDO_INDEX_NAME=SYS.DBMS_ASSERT.NOOP(IA1.INDEXNAME)
<          AND SDO_INDEX_OWNER=SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA);
---
>             SDO_INDEX_OWNER= IA.INDEXSCHEMA, 
>             SDO_TSNAME= IA.INDEXSCHEMA, 
>             SDO_INDEX_PARTITION= IA.INDEXPARTITION 
>          WHERE SDO_INDEX_TABLE= ITAB2
>          AND SDO_INDEX_NAME=IA1.INDEXNAME
>          AND SDO_INDEX_OWNER=IA1.INDEXSCHEMA;
679,682c683,686
<         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(SYS.DBMS_ASSERT.NOOP(IA1.INDEXSCHEMA),
<                                           SYS.DBMS_ASSERT.NOOP(IA1.INDEXNAME),
<                                           SYS.DBMS_ASSERT.NOOP(IA1.INDEXPARTITION),
<                                           SYS.DBMS_ASSERT.NOOP(ITAB2));
---
>         MDSYS.MDPRVT_IDX.INVALIDATE_CACHE(IA1.INDEXSCHEMA,
>                                           IA1.INDEXNAME,
>                                           IA1.INDEXPARTITION,
>                                           ITAB2);
748a753
>     SDO_RTREE_READ_ONLY       NUMBER;
788,789d792
<     COLNAME := REPLACE(COLNAME, '"');
<      
795a799,802
>     ELSIF ( SDO_UTIL.IS_BUMPY_CASE(COLNAME, TRUE) ) THEN
>       COLNAME := '"' || COLNAME || '"';
>     ELSE
>       COLNAME := REPLACE(NLS_UPPER(COLNAME), '"');
803,804c810,817
<       AND SDO_INDEX_NAME = SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(IA.INDEXNAME)
<       AND SDO_TSNAME = SYS.DBMS_ASSERT.SCHEMA_NAME(TSNAME);
---
>       AND SDO_INDEX_NAME = IA.INDEXNAME
>       AND SDO_TSNAME = TSNAME;
> 
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABNAME, TRUE) ) THEN
>         TABNAME := '"' || TABNAME || '"';
>       ELSE
>         TABNAME := REPLACE(NLS_UPPER(TABNAME), '"');
>       END IF;
833c846
<       FROM  MDSYS.SDO_GEOM_METADATA_TABLE
---
>       FROM MDSYS.SDO_GEOM_METADATA_TABLE
835c848
<       AND SDO_TABLE_NAME = SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(TABNAME)
---
>       AND SDO_TABLE_NAME = TABNAME
964a978
>        SDO_RTREE_READ_ONLY,
1159a1174,1176
>                SDO_UTIL.NUMBER_TO_CHAR(SDO_RTREE_READ_ONLY)) || COMMA;
>  
>       STMT1 := STMT1 || SYS.DBMS_ASSERT.ENQUOTE_LITERAL(
1243a1261
>     SDO_RTREE_READ_ONLY       IN NUMBER,
1295a1314
>           SDO_RTREE_READ_ONLY,
1333a1353
>           SDO_RTREE_READ_ONLY,
1373a1394
>           SDO_RTREE_READ_ONLY,
1413a1435
>           SDO_RTREE_READ_ONLY,
MDSYS.PRVT_PC - PACKAGE BODY (RU):
59a60,78
>     
>     IF ( SDO_UTIL.IS_BUMPY_CASE(BASETABLE) ) THEN
>       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>         'Bumpy-case "basetable" name is not supported');
>       RETURN;
>     END IF;
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(BASECOL) ) THEN
>       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>         'Bumpy-case "basecol" name is not supported');
>       RETURN;
>     END IF;
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(BLKTABLE) ) THEN
>       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>         'Bumpy-case "blktable" name is not supported');
>       RETURN;
>     END IF;
> 
MDSYS.PRVT_SAM - PACKAGE BODY (RU):
42a43,46
>     G_TABNAM           VARCHAR2(130);
>     G_TABNAM_NQ        VARCHAR2(130);
>     G_COLNAM           VARCHAR2(1024);
>     G_COLNAM_NQ        VARCHAR2(1024);
44a49,62
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLENAME) ) THEN
>       G_TABNAM := TABLENAME;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(TABLENAME), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLNAME) ) THEN
>       G_COLNAM := COLNAME;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(COLNAME), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
86,88c104,108
<       SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(TABLENAME),
<       SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME),
<       NDIM, SRID, DIM);
---
>       SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM),
>       SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
>       NDIM,
>       SRID,
>       DIM);
103c123
<       USING NLS_UPPER(TABLENAME), NLS_UPPER(AGGR_COL_STRING); 
---
>       USING TABLENAME, NLS_UPPER(AGGR_COL_STRING); 
118c138
<         INTO OWNR USING NLS_UPPER(TABLENAME);
---
>         INTO OWNR USING TABLENAME;
131c151
<       USING NLS_UPPER(TABLENAME), NLS_UPPER(AGGR_COL_STRING), OWNR;
---
>       USING TABLENAME, NLS_UPPER(AGGR_COL_STRING), OWNR;
148c168
<             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME) ||
---
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM) ||
155c175
<             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME) ||
---
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM) ||
MDSYS.SDOTNPC - PACKAGE BODY (RU):
77,78c77,78
<       UPPER(OWNER) = UPPER(BTSCHEMA) AND
<       UPPER(TRIGGER_NAME) = UPPER(DMLT);
---
>       NLS_UPPER(OWNER) = NLS_UPPER(BTSCHEMA) AND
>       NLS_UPPER(TRIGGER_NAME) = NLS_UPPER(DMLT);
MDSYS.SDO_3GL - PACKAGE BODY (RU):
1059,1060c1059,1063
<   FUNCTION RELATE(GEOM1 IN MDSYS.SDO_GEOMETRY, GEOM2 IN MDSYS.SDO_GEOMETRY,
<                   MASK IN VARCHAR2, TAB1 IN VARCHAR2, COL1 IN VARCHAR2)
---
>   FUNCTION RELATE(GEOM1 IN MDSYS.SDO_GEOMETRY,
>                   GEOM2 IN MDSYS.SDO_GEOMETRY,
>                   MASK IN VARCHAR2,
>                   TAB1 IN VARCHAR2,
>                   COL1 IN VARCHAR2)
1062,1064c1065,1069
<  DIM MDSYS.SDO_DIM_ARRAY;
<  STMT VARCHAR2(500);
<  RETMASK VARCHAR2(32);
---
>   DIM MDSYS.SDO_DIM_ARRAY;
>   STMT VARCHAR2(500);
>   RETMASK VARCHAR2(32);
>   G_TABNAM VARCHAR2(130);
>   G_COLNAM VARCHAR2(1024);
1067c1072
<  IF GEOM1 IS NULL THEN
---
>   IF GEOM1 IS NULL THEN
1069,1070c1074,1075
<  END IF;
<  IF GEOM2 IS NULL THEN
---
>   END IF;
>   IF GEOM2 IS NULL THEN
1072c1077,1089
<  END IF;
---
>   END IF;
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(TAB1) ) THEN
>     G_TABNAM := TAB1;
>   ELSE
>     G_TABNAM := REPLACE(NLS_UPPER(TAB1), '"');
>   END IF;
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(COL1) ) THEN
>     G_COLNAM := COL1;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(COL1), '"');
>   END IF;
1077,1078c1094,1097
<   STMT := 'SELECT diminfo FROM ' || ' MDSYS.USER_SDO_GEOM_METADATA WHERE ' ||
<           'TABLE_NAME =  :tab1  AND ''"''||COLUMN_NAME||''"'' =  :col ';
---
>   STMT := 'SELECT diminfo ' ||
>           'FROM USER_SDO_GEOM_METADATA ' ||
>           'WHERE TABLE_NAME =  :tab1 ' ||
>           'AND COLUMN_NAME = :col ';
1082,1085c1101,1103
<     EXECUTE IMMEDIATE STMT
<     INTO DIM
<     USING NLS_UPPER(SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(TAB1)),
<        NLS_UPPER(SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(COL1));
---
>     EXECUTE IMMEDIATE STMT INTO DIM
>     USING SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM),
>           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_COLNAM);
1100c1118,1120
<   PROCEDURE RELATE_PROCESS(MASK VARCHAR2, RESULT VARCHAR2, LOOKUP VARCHAR2,
---
>   PROCEDURE RELATE_PROCESS(MASK VARCHAR2,
>                            RESULT VARCHAR2,
>                            LOOKUP VARCHAR2,
1348c1368,1369
< FUNCTION FILTER(GEOM1 IN MDSYS.SDO_GEOMETRY, GEOM2 IN MDSYS.SDO_GEOMETRY,
---
> FUNCTION FILTER(GEOM1 IN MDSYS.SDO_GEOMETRY,
>                 GEOM2 IN MDSYS.SDO_GEOMETRY,
1351c1372,1373
<                 SCTX IN OUT MDSYS.SDO_INDEX_METHOD_10I, SCNFLAG NUMBER,
---
>                 SCTX IN OUT MDSYS.SDO_INDEX_METHOD_10I,
>                 SCNFLAG NUMBER,
1850,1851c1872,1873
<          IF (IDX = 1) THEN 
<            TGEOM := GENERATE_BUFFER(SDO_UTIL.EXTRACT(GEOM, IDX),
---
>         IF (IDX = 1) THEN 
>           TGEOM := GENERATE_BUFFER(SDO_UTIL.EXTRACT(GEOM, IDX),
1853,1860c1875,1886
<          ELSE
<             TMPG := GENERATE_BUFFER(SDO_UTIL.EXTRACT(GEOM, IDX),
<                                     UNITDIST, SMA, IFLAT, ARCT);
<             TMPG2 := SDO_GEOM.SDO_UNION(TMPG, TGEOM, TOL);
<             TGEOM := TMPG2;
<           END IF;
<        END LOOP;  
<        RETJBUF := TGEOM;
---
>           
>           TGEOM := SDO_UTIL.RECTIFY_GEOMETRY(TGEOM, TOL);
>         ELSE
>           TMPG := GENERATE_BUFFER(SDO_UTIL.EXTRACT(GEOM, IDX),
>                                   UNITDIST, SMA, IFLAT, ARCT);
>           
>           TMPG := SDO_UTIL.RECTIFY_GEOMETRY(TMPG, TOL);
>           TMPG2 := SDO_GEOM.SDO_UNION(TMPG, TGEOM, TOL);
>           TGEOM := TMPG2;
>         END IF;
>       END LOOP;  
>       RETJBUF := TGEOM;
MDSYS.SDO_CS - PACKAGE BODY (RU):
429a430,436
>       G_TABNAM VARCHAR2(130);
>       G_TABNAM_NQ VARCHAR2(130);
>       G_OUTNAM VARCHAR2(130);
>       G_OUTNAM_NQ VARCHAR2(130);
>       G_COLNAM VARCHAR2(1024);
>       G_COLNAM_NQ VARCHAR2(1024);
>       STMT VARCHAR2(4000);
432a440,460
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_IN) ) THEN
>       G_TABNAM := TABLE_IN;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(TABLE_IN), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_OUT) ) THEN
>       G_OUTNAM := TABLE_OUT;
>     ELSE
>       G_OUTNAM := REPLACE(NLS_UPPER(TABLE_OUT), '"');
>     END IF;
>     G_OUTNAM_NQ := REPLACE(G_OUTNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_IN) ) THEN
>       G_COLNAM := COLUMN_IN;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(COLUMN_IN), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
436,438c464,467
<       TABLE_IN,
<       COLUMN_IN,
<       NDIM, SOURCE_SRID);
---
>       G_TABNAM,
>       G_COLNAM,
>       NDIM,
>       SOURCE_SRID);
441c470,480
<       EXECUTE IMMEDIATE 'create table ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(TABLE_OUT) || ' as select rowid mdsys.sdo_rowid, sdo_cs.reassign_srid(' || SYS.DBMS_ASSERT.ENQUOTE_NAME(COLUMN_IN) || ', ' || TO_SRID || ') geometry from ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(TABLE_IN);
---
>       
>       STMT := 'create table ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(G_OUTNAM_NQ) ||
>               ' as select rowid sdo_rowid, sdo_cs.reassign_srid(' ||
>               SYS.DBMS_ASSERT.ENQUOTE_NAME(G_COLNAM_NQ) || ', ' ||
>               TO_SRID || ') geometry ' ||
>               'from ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(G_TABNAM_NQ);
>       BEGIN
>         EXECUTE IMMEDIATE STMT;
>         EXCEPTION WHEN OTHERS THEN
>           RAISE;
>       END;
466,468c505,507
<         TABLE_IN,
<         COLUMN_IN,
<         TABLE_OUT,
---
>         G_TABNAM,
>         G_COLNAM,
>         G_OUTNAM,
473a513
> 
484a525,528
>       G_TABNAM VARCHAR2(130);
>       G_TABNAM_NQ VARCHAR2(130);
>       G_COLNAM VARCHAR2(1024);
>       G_COLNAM_NQ VARCHAR2(1024);
487a532,545
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_IN) ) THEN
>       G_TABNAM := TABLE_IN;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(TABLE_IN), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_IN) ) THEN
>       G_COLNAM := COLUMN_IN;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(COLUMN_IN), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
491,493c549,552
<       TABLE_IN,
<       COLUMN_IN,
<       NDIM, SOURCE_SRID);
---
>       G_TABNAM,
>       G_COLNAM,
>       NDIM,
>       SOURCE_SRID);
847,850c906,916
<     COMMIT_INTERVAL IN NUMBER DEFAULT -1) IS
<       NDIM NUMBER;
<       SOURCE_SRID NUMBER;
<       POS NUMBER;
---
>     COMMIT_INTERVAL IN NUMBER DEFAULT -1)
>   IS
>     NDIM NUMBER;
>     SOURCE_SRID NUMBER;
>     POS NUMBER;
>     G_TABNAM VARCHAR2(130);
>     G_TABNAM_NQ VARCHAR2(130);
>     G_COLNAM VARCHAR2(1024);
>     G_COLNAM_NQ VARCHAR2(1024);
>     G_TABOUT VARCHAR2(130);
>     G_TABOUT_NQ VARCHAR2(130);
853a920,940
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_IN) ) THEN
>       G_TABNAM := TABLE_IN;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(TABLE_IN), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_IN) ) THEN
>       G_COLNAM := COLUMN_IN;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(COLUMN_IN), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_OUT) ) THEN
>       G_TABOUT := TABLE_OUT;
>     ELSE
>       G_TABOUT := REPLACE(NLS_UPPER(TABLE_OUT), '"');
>     END IF;
>     G_TABOUT_NQ := REPLACE(G_TABOUT, '"');
> 
857,859c944,947
<       TABLE_IN,
<       COLUMN_IN,
<       NDIM, SOURCE_SRID);
---
>       G_TABNAM,
>       G_COLNAM,
>       NDIM,
>       SOURCE_SRID);
896,898c984,986
<       TABLE_IN,
<       COLUMN_IN,
<       TABLE_OUT,
---
>       G_TABNAM_NQ,
>       G_COLNAM_NQ,
>       G_TABOUT_NQ,
911,913c999,1008
<     COMMIT_INTERVAL IN NUMBER DEFAULT -1) IS
<       NDIM NUMBER;
<       SOURCE_SRID NUMBER;
---
>     COMMIT_INTERVAL IN NUMBER DEFAULT -1)
>   IS
>     NDIM NUMBER;
>     SOURCE_SRID NUMBER;
>     G_TABNAM VARCHAR2(130);
>     G_TABNAM_NQ VARCHAR2(130);
>     G_COLNAM VARCHAR2(1024);
>     G_COLNAM_NQ VARCHAR2(1024);
>     G_TABOUT VARCHAR2(130);
>     G_TABOUT_NQ VARCHAR2(130);
916a1012,1032
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_IN) ) THEN
>       G_TABNAM := TABLE_IN;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(TABLE_IN), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_IN) ) THEN
>       G_COLNAM := COLUMN_IN;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(COLUMN_IN), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_OUT) ) THEN
>       G_TABOUT := TABLE_OUT;
>     ELSE
>       G_TABOUT := REPLACE(NLS_UPPER(TABLE_OUT), '"');
>     END IF;
>     G_TABOUT_NQ := REPLACE(G_TABOUT, '"');
> 
920,922c1036,1039
<       TABLE_IN,
<       COLUMN_IN,
<       NDIM, SOURCE_SRID);
---
>       G_TABNAM,
>       G_COLNAM,
>       NDIM,
>         SOURCE_SRID);
944,946c1061,1063
<         TABLE_IN,
<         COLUMN_IN,
<         TABLE_OUT,
---
>         G_TABNAM_NQ,
>         G_COLNAM_NQ,
>         G_TABOUT_NQ,
3453c3570
< <epsg:GridFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epsg="http://www.oracle.com/2004/spatial/epsg/gridfile/schema" creation="2004-08-05T15:45:00" update="2004-08-05T15:45:00">
---
>  <epsg:GridFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epsg="http://www.oracle.com/2004/spatial/epsg/gridfile/schema" creation="2004-08-05T15:45:00" update="2004-08-05T15:45:00">
3521c3638
< </epsg:GridFile>';
---
>  </epsg:GridFile>';
6462a6580,6583
>     G_TABNAM         VARCHAR2(130);
>     G_TABNAM_NQ      VARCHAR2(130);
>     G_COLNAM        VARCHAR2(1024);
>     G_COLNAM_NQ     VARCHAR2(1024);
6471a6593,6606
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_IN) ) THEN
>       G_TABNAM := TABLE_IN;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(TABLE_IN), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_IN) ) THEN
>       G_COLNAM := COLUMN_IN;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(COLUMN_IN), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
6475,6477c6610,6613
<       TABLE_IN,
<       COLUMN_IN,
<       NDIM, FROM_SRID);
---
>       G_TABNAM,
>       G_COLNAM,
>       NDIM,
>       FROM_SRID);
MDSYS.SDO_GEOM - PACKAGE BODY (RU):
279c279
<    RTN_LIST  := '(';
---
>    RTN_LIST := '(';
436,437c436,437
<       RETURN 'NULL' ;
<    END IF ;
---
>      RETURN 'NULL';
>    END IF;
489c489,491
<      IF ( KIND <> 'ENGINEERING' ) THEN
---
>      
>      
>      IF ( KIND <> 'ENGINEERING' ) AND ( KIND <> 'PROJECTED' ) THEN
520,521c522,523
<       RETURN 'NULL' ;
<    END IF ;
---
>      RETURN 'NULL';
>    END IF;
568,569c570,571
<       RETURN 'NULL' ;
<    END IF ;
---
>      RETURN 'NULL';
>    END IF;
665c667,669
<      IF ( KIND <> 'ENGINEERING' ) THEN
---
>      
>      
>      IF ( KIND <> 'ENGINEERING' ) AND ( KIND <> 'PROJECTED' ) THEN
743,744c747,748
<     RETURN 'NULL' ;
<   END IF ;
---
>     RETURN 'NULL';
>   END IF;
1142,1147c1146,1151
<        FOR  CNT IN 1 .. DIM_1.COUNT LOOP
<          DIM_1(CNT).SDO_TOLERANCE := DIM_1(CNT).SDO_TOLERANCE/10.0;
<        END LOOP;
<        FOR  CNT IN 1 .. DIM_2.COUNT LOOP
<          DIM_2(CNT).SDO_TOLERANCE := DIM_2(CNT).SDO_TOLERANCE/10.0;
<        END LOOP;
---
>       FOR  CNT IN 1 .. DIM_1.COUNT LOOP
>         DIM_1(CNT).SDO_TOLERANCE := DIM_1(CNT).SDO_TOLERANCE/10.0;
>       END LOOP;
>       FOR  CNT IN 1 .. DIM_2.COUNT LOOP
>         DIM_2(CNT).SDO_TOLERANCE := DIM_2(CNT).SDO_TOLERANCE/10.0;
>       END LOOP;
1149c1153
<        EXIT;
---
>       EXIT;
3462c3466
<        RAISE;
---
>       RAISE;
3510c3514
<        RAISE;
---
>       RAISE;
3556c3560
<        RAISE;
---
>       RAISE;
3605c3609
<        RAISE;
---
>       RAISE;
3652c3656
<        RAISE;
---
>       RAISE;
3690c3694
<        RAISE;
---
>       RAISE;
3842c3846
<        RAISE;
---
>       RAISE;
3891c3895
<        RAISE;
---
>       RAISE;
3993c3997,3998
< PROCEDURE VALIDATE_LAYER(LAYER IN VARCHAR2, RESULT_TABLE IN VARCHAR2) 
---
> PROCEDURE VALIDATE_LAYER(LAYER IN VARCHAR2,
>                          RESULT_TABLE IN VARCHAR2) 
3997,3998c4002,4008
<   QUERY_STR   VARCHAR2(4000) ;
<   UPDATE_STR  VARCHAR2(256) ;
---
>   QUERY_STR   VARCHAR2(4000);
>   UPDATE_STR  VARCHAR2(256);
>   TABNAM VARCHAR2(130);
>   G_TABNAM VARCHAR2(130);
>   G_TABNAM_NQ VARCHAR2(130);
>   G_RESNAM VARCHAR2(130);
>   G_RESNAM_NQ VARCHAR2(130);
4001,4002c4011,4012
<   QUERY_CRS   CURSOR_TYPE ;
<  
---
>   QUERY_CRS   CURSOR_TYPE;
> 
4011a4022,4028
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(RESULT_TABLE) ) THEN
>     G_RESNAM := RESULT_TABLE;
>   ELSE
>     G_RESNAM := REPLACE(NLS_UPPER(RESULT_TABLE), '"');
>   END IF;
>   G_RESNAM_NQ := REPLACE(G_RESNAM, '"');
4014,4018c4031,4034
<             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(LAYER)  || '_SDOGEOM' ;
<   UPDATE_STR := 'INSERT INTO ' || 
<        SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) 
<        || ' VALUES(:gid, :gid_result)' ;
<  
---
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(LAYER)  || '_SDOGEOM';
>   UPDATE_STR := 'INSERT INTO ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>                 ' VALUES(:gid, :gid_result)';
> 
4020c4036
<    OPEN QUERY_CRS FOR QUERY_STR ;
---
>    OPEN QUERY_CRS FOR QUERY_STR;
4023c4039
<        CLOSE QUERY_CRS ;
---
>        CLOSE QUERY_CRS;
4027a4044,4051
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(LAYER) ) THEN
>     G_TABNAM := LAYER;
>   ELSE
>     
>     G_TABNAM := REPLACE(NLS_UPPER(LAYER), '"');
>   END IF;
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
4031,4033c4055,4056
<     FETCH QUERY_CRS INTO GID ;
<  
<     EXIT WHEN QUERY_CRS%NOTFOUND ;
---
>     FETCH QUERY_CRS INTO GID;
>     EXIT WHEN QUERY_CRS%NOTFOUND;
4035,4036c4058,4059
<     GID_RESULT := MDSYS.MD2.VALIDATE_GEOM(NLS_UPPER(
<             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(LAYER) ), GID, NULL);
---
>     GID_RESULT :=
>       MDSYS.MD2.VALIDATE_GEOM(SDO_UTIL.SET_QUOTED_NAME(G_TABNAM_NQ), GID, NULL);
4038c4061
<     EXECUTE IMMEDIATE UPDATE_STR USING GID, GID_RESULT ;
---
>     EXECUTE IMMEDIATE UPDATE_STR USING GID, GID_RESULT;
4045,4046c4068,4069
<   END LOOP ;
<   CLOSE QUERY_CRS ;
---
>   END LOOP;
>   CLOSE QUERY_CRS;
4058,4059c4081,4084
< PROCEDURE VALIDATE_LAYER(GEOM_TABLE IN VARCHAR2, GEOM_COLUMN IN VARCHAR2,
<                          PKEY_COLUMN IN VARCHAR2, RESULT_TABLE IN VARCHAR2,
---
> PROCEDURE VALIDATE_LAYER(GEOM_TABLE IN VARCHAR2,
>                          GEOM_COLUMN IN VARCHAR2,
>                          PKEY_COLUMN IN VARCHAR2,
>                          RESULT_TABLE IN VARCHAR2,
4065,4070c4090,4095
<   THEDIMINFO  MDSYS.SDO_DIM_ARRAY ;
<   QUERY_STR   VARCHAR2(4000) ;
<   QUERY_STR2  VARCHAR2(4000) ;
<   UPDATE_STR  VARCHAR2(256) ;
<   UPDATE_COMMIT  VARCHAR2(256) ;
<   INSERT_COMMIT  VARCHAR2(256) ;
---
>   THEDIMINFO  MDSYS.SDO_DIM_ARRAY;
>   QUERY_STR   VARCHAR2(4000);
>   QUERY_STR2  VARCHAR2(4000);
>   UPDATE_STR  VARCHAR2(256);
>   UPDATE_COMMIT  VARCHAR2(256);
>   INSERT_COMMIT  VARCHAR2(256);
4081c4106
<   QUERY_CRS   CURSOR_TYPE ;
---
>   QUERY_CRS   CURSOR_TYPE;
4083a4109,4114
>   G_RESNAM     VARCHAR2(130);
>   G_RESNAM_NQ  VARCHAR2(130);
>   G_TABNAM     VARCHAR2(130);
>   G_TABNAM_NQ  VARCHAR2(130);
>   G_COLNAM    VARCHAR2(1024);
>   G_COLNAM_NQ VARCHAR2(1024);
4097a4129,4149
>   IF ( SDO_UTIL.IS_BUMPY_CASE(RESULT_TABLE) ) THEN
>     G_RESNAM := RESULT_TABLE;
>   ELSE
>     G_RESNAM := REPLACE(NLS_UPPER(RESULT_TABLE), '"');
>   END IF;
>   G_RESNAM_NQ := REPLACE(G_RESNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(GEOM_TABLE) ) THEN
>     G_TABNAM := GEOM_TABLE;
>   ELSE
>     G_TABNAM := REPLACE(NLS_UPPER(GEOM_TABLE), '"');
>   END IF;
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(GEOM_COLUMN) ) THEN
>     G_COLNAM := GEOM_COLUMN;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(GEOM_COLUMN), '"');
>   END IF;
>   G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
4100,4101c4152,4156
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_COLUMN) || ' FROM ' || 
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_TABLE) || ' T '; 
---
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM) || ' FROM ' || 
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM) || ' T '; 
> 
>   UPDATE_STR := 'INSERT INTO ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>                 ' VALUES (:gid, :gid_result)'; 
4103,4121c4158,4172
<   UPDATE_STR := 'INSERT INTO ' || 
<  SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<                  ' VALUES (:gid, :gid_result)'; 
< 
<   INSERT_COMMIT := 'INSERT INTO ' || 
<  SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<                  ' VALUES (NULL, ''DONE'')'; 
<   
<   QUERY_STR2 := 'SELECT COLUMN_NAME FROM SYS.USER_TAB_COLUMNS' ||
<                 ' WHERE TABLE_NAME =  :tab ' ||
<                 ' AND DATA_TYPE=''VARCHAR2'' ';
<   EXECUTE IMMEDIATE QUERY_STR2 INTO COL_NAME
<      USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE);
< 
<   UPDATE_COMMIT := 'UPDATE ' || 
<            SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<                  ' SET ' || 
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(PKEY_COLUMN) || ' =  :gid ' ||
<                  ' WHERE  '||
---
>   INSERT_COMMIT := 'INSERT INTO ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>                    ' VALUES (NULL, ''DONE'')'; 
>   
>   QUERY_STR2 := 'SELECT COLUMN_NAME ' ||
>                 'FROM SYS.USER_TAB_COLUMNS ' ||
>                 'WHERE TABLE_NAME = :tab ' ||
>                 'AND DATA_TYPE = ''VARCHAR2'' ';
>   EXECUTE IMMEDIATE QUERY_STR2
>     INTO COL_NAME
>     USING SYS.DBMS_ASSERT.NOOP(G_RESNAM_NQ);
> 
>   UPDATE_COMMIT := 'UPDATE ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>                    ' SET ' || 
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(PKEY_COLUMN) || ' = :gid ' ||
>                    ' WHERE  '||
4138,4139c4189,4190
<                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_TABLE),
<                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_COLUMN),
---
>                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM),
>                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
4159c4210
<  MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13223, GEOM_TABLE||'.'||GEOM_COLUMN);
---
>         MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13223, GEOM_TABLE||'.'||GEOM_COLUMN);
4162,4164c4213,4215
<         MDSYS.SDO_MEMORY.END_MEMORY_CHECK;
<         RAISE;
<   END ; 
---
>        MDSYS.SDO_MEMORY.END_MEMORY_CHECK;
>        RAISE;
>   END; 
4170c4221
<   OPEN QUERY_CRS FOR QUERY_STR ;
---
>   OPEN QUERY_CRS FOR QUERY_STR;
4180,4181c4231
<   STMT := 'truncate table ' || 
<            SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE));
---
>   STMT := 'truncate table ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ);
4182a4233
> 
4186,4191c4237,4241
<      FETCH QUERY_CRS INTO GID, THEGEOMETRY ;
<      EXCEPTION
<  
<       WHEN INVALID_NUMBER THEN
<       CLOSE QUERY_CRS ;
<       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13265, GEOM_COLUMN, GEOM_TABLE);
---
>        FETCH QUERY_CRS INTO GID, THEGEOMETRY;
>        EXCEPTION
>          WHEN INVALID_NUMBER THEN
>          CLOSE QUERY_CRS;
>          MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13265, GEOM_COLUMN, GEOM_TABLE);
4193,4195c4243,4245
<       WHEN INVALID_DATATYPE THEN
<       CLOSE QUERY_CRS ;
<       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13263, GEOM_COLUMN, GEOM_TABLE);
---
>          WHEN INVALID_DATATYPE THEN
>          CLOSE QUERY_CRS;
>          MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13263, GEOM_COLUMN, GEOM_TABLE);
4197,4201c4247,4251
<       WHEN OTHERS THEN
<         CLOSE QUERY_CRS;
<         MDSYS.SDO_MEMORY.END_MEMORY_CHECK;
<         RAISE;
<      END ; 
---
>          WHEN OTHERS THEN
>            CLOSE QUERY_CRS;
>            MDSYS.SDO_MEMORY.END_MEMORY_CHECK;
>            RAISE;
>      END; 
4203c4253
<      EXIT WHEN QUERY_CRS%NOTFOUND ;
---
>      EXIT WHEN QUERY_CRS%NOTFOUND;
4207c4257
<     
---
> 
4249c4299
<        EXECUTE IMMEDIATE UPDATE_STR USING GID, GID_RESULT ;
---
>        EXECUTE IMMEDIATE UPDATE_STR USING GID, GID_RESULT;
4251,4252c4301,4302
<   END LOOP ;
<   CLOSE QUERY_CRS ;
---
>   END LOOP;
>   CLOSE QUERY_CRS;
4274c4324,4330
<   G_TABLE VARCHAR2(130);
---
>   G_RESNAM VARCHAR2(130);
>   G_RESNAM_NQ VARCHAR2(130);
>   G_TABNAM VARCHAR2(130);
>   G_TABNAM_NQ VARCHAR2(130);
>   G_COLNAM VARCHAR2(1024);
>   G_COLNAM_NQ VARCHAR2(1024);
>   STMT VARCHAR2(4000);
4303,4304c4359,4363
<     USER_NAME := SDO_UTIL.GET_QUOTED_NAME(SUBSTR(GEOM_TABLE, 1, INSTR(GEOM_TABLE, '.')-1));
<     G_TABLE := NLS_UPPER(SUBSTR(GEOM_TABLE, INSTR(GEOM_TABLE, '.')+1));
---
>     USER_NAME := NLS_UPPER(SUBSTR(GEOM_TABLE, 1, INSTR(GEOM_TABLE, '.')-1));
>     G_TABNAM := SUBSTR(GEOM_TABLE, INSTR(GEOM_TABLE, '.')+1);
>     IF ( NOT SDO_UTIL.IS_BUMPY_CASE(G_TABNAM) ) THEN
>       G_TABNAM := REPLACE(NLS_UPPER(G_TABNAM), '"');
>     END IF;
4313c4372,4376
<     G_TABLE := GEOM_TABLE;
---
>     IF ( SDO_UTIL.IS_BUMPY_CASE(GEOM_TABLE) ) THEN
>       G_TABNAM := GEOM_TABLE;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(GEOM_TABLE), '"');
>     END IF;
4315c4378,4393
<     
---
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(GEOM_COLUMN) ) THEN
>     G_COLNAM := GEOM_COLUMN;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(GEOM_COLUMN), '"');
>   END IF;
>   G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(RESULT_TABLE) ) THEN
>     G_RESNAM := RESULT_TABLE;
>   ELSE
>     G_RESNAM := REPLACE(NLS_UPPER(RESULT_TABLE), '"');
>   END IF;
>   G_RESNAM_NQ := REPLACE(G_RESNAM, '"');
> 
4317,4319c4395,4400
<   SELECT COUNT(*) INTO CNT
<   FROM SYS.USER_TAB_COLUMNS
<   WHERE TABLE_NAME = NLS_UPPER(RESULT_TABLE) AND DATA_TYPE='VARCHAR2';
---
>   STMT := 'SELECT count(*) ' ||
>           'FROM SYS.USER_TAB_COLUMNS ' ||
>           'WHERE TABLE_NAME = :tab ' ||
>           'AND DATA_TYPE = ''VARCHAR2'' ';
>   EXECUTE IMMEDIATE STMT INTO CNT
>     USING G_RESNAM_NQ;
4327,4329c4408,4413
<   SELECT COUNT(*) INTO CNT
<   FROM SYS.ALL_TAB_COLS
<   WHERE TABLE_NAME = NLS_UPPER(G_TABLE) AND OWNER = USER_NAME ;
---
>   STMT := 'SELECT count(*) ' ||
>           'FROM SYS.ALL_TAB_COLS ' ||
>           'WHERE OWNER = :own ' ||
>           'AND TABLE_NAME = :tab';
>   EXECUTE IMMEDIATE STMT INTO CNT
>     USING USER_NAME, G_TABNAM_NQ;
4337,4343c4421,4430
<   SELECT COLUMN_NAME INTO COLUMN_NAME 
<   FROM SYS.USER_TAB_COLUMNS 
<   WHERE TABLE_NAME = NLS_UPPER(RESULT_TABLE) AND DATA_TYPE='VARCHAR2';
< 
<   EXECUTE IMMEDIATE 'truncate table ' || 
<              SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE));
<             
---
>   STMT := 'SELECT COLUMN_NAME ' ||
>           'FROM SYS.USER_TAB_COLUMNS ' ||
>           'WHERE TABLE_NAME = :tab ' ||
>           'AND DATA_TYPE = ''VARCHAR2'' ';
>   EXECUTE IMMEDIATE STMT INTO COLUMN_NAME
>     USING G_RESNAM_NQ;
> 
>   STMT := 'truncate table ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ);
>   EXECUTE IMMEDIATE STMT;
> 
4347,4348c4434,4435
<                        G_TABLE,
<                        GEOM_COLUMN,
---
>                        G_TABNAM,
>                        G_COLNAM,
4368c4455,4456
<   FULL_TABLE := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER_NAME) || '.' || NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABLE));
---
>   FULL_TABLE := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER_NAME) || '.' ||
>                 SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM);
4371,4375c4459,4465
<     EXECUTE IMMEDIATE
<       'select '|| 
<       NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_COLUMN)) ||' from '|| 
<       FULL_TABLE || ' where :1 is not null and rownum < 2 '
<       INTO SAMPLE_GEOMETRY USING NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_COLUMN));
---
>     STMT := 'select ' || 
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM) ||
>             ' from ' || FULL_TABLE ||
>             ' where ' ||
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM) ||
>             ' is not null and rownum < 2';
>     EXECUTE IMMEDIATE STMT INTO SAMPLE_GEOMETRY;
4416,4419c4506,4510
<                 FULL_TABLE,
<                 NLS_UPPER(GEOM_COLUMN),NLS_UPPER(RESULT_TABLE), COMMIT_INTERVAL,
<                 CONDITIONAL, CHCK3DSRID, 
<                 SM_MJR_AXIS, 1.0/INV_FLTN, G3D_GEOG_CRS_UOM_FACTOR, IS_UNIT_RADIANS, DIMINFO(1).SDO_TOLERANCE);
---
>                  FULL_TABLE,
>                  G_COLNAM, G_RESNAM_NQ, COMMIT_INTERVAL,
>                  CONDITIONAL, CHCK3DSRID, 
>                  SM_MJR_AXIS, 1.0/INV_FLTN, G3D_GEOG_CRS_UOM_FACTOR,
>                  IS_UNIT_RADIANS, DIMINFO(1).SDO_TOLERANCE);
4424,4426c4515,4517
<   EXECUTE IMMEDIATE 'insert into ' ||
<              SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<           ' values(NULL, ''0'') ';
---
>   STMT := 'INSERT INTO ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>           ' VALUES(NULL, ''0'')';
>   EXECUTE IMMEDIATE STMT;
4428,4431c4519,4521
<   EXECUTE IMMEDIATE ' select rowid from ' ||
<              SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE))
<   INTO TAB_ROWID;
<   
---
>   STMT := 'select rowid from ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ);
>   EXECUTE IMMEDIATE STMT
>     INTO TAB_ROWID;
4433c4523
<   SDO_3GL.VALIDATE_LAYER_WITH_CONTEXT(NLS_UPPER(G_TABLE),NLS_UPPER(GEOM_COLUMN),
---
>   SDO_3GL.VALIDATE_LAYER_WITH_CONTEXT(G_TABNAM, G_COLNAM,
4435c4525
<              NLS_UPPER(RESULT_TABLE), COMMIT_INTERVAL,
---
>              G_RESNAM, COMMIT_INTERVAL,
4437,4438c4527,4528
<              SYS.ODCICOLINFOLIST(SYS.ODCICOLINFO(USER_NAME,NLS_UPPER(G_TABLE),
<              NLS_UPPER(GEOM_COLUMN),
---
>              SYS.ODCICOLINFOLIST(SYS.ODCICOLINFO(USER_NAME, G_TABNAM,
>              G_COLNAM,
4444,4445c4534,4535
<     VALLAYER_WITH_CONTEXT_LRS(NLS_UPPER(GEOM_TABLE),
<                               NLS_UPPER(GEOM_COLUMN),
---
>     VALLAYER_WITH_CONTEXT_LRS(G_TABNAM,
>                               G_COLNAM,
4447c4537
<                               NLS_UPPER(RESULT_TABLE), 
---
>                               G_RESNAM,
4452,4460c4542,4546
<     SELECT
<       COUNT(*)
<     INTO
<       HAS_WKT
<     FROM
<       CS_SRS CRS
<     WHERE
<       CRS.SRID = VALIDATE_LAYER_WITH_CONTEXT.SRID AND
<       NOT(WKTEXT IS NULL);
---
>     SELECT COUNT(*)
>     INTO HAS_WKT
>     FROM CS_SRS CRS
>     WHERE CRS.SRID = VALIDATE_LAYER_WITH_CONTEXT.SRID
>     AND NOT(WKTEXT IS NULL);
4482,4487c4568,4571
<   THEDIMINFO  MDSYS.SDO_DIM_ARRAY ;
<   QUERY_STR   VARCHAR2(4000) ;
<   QUERY_STR2  VARCHAR2(4000) ;
<   UPDATE_STR  VARCHAR2(4000) ;
<   UPDATE_COMMIT  VARCHAR2(256) ;
<   INSERT_COMMIT  VARCHAR2(256) ;
---
>   THEDIMINFO  MDSYS.SDO_DIM_ARRAY;
>   QUERY_STR   VARCHAR2(4000);
>   QUERY_STR2  VARCHAR2(4000);
>   UPDATE_STR  VARCHAR2(4000);
4497c4581
<   QUERY_CRS   CURSOR_TYPE ;
---
>   QUERY_CRS   CURSOR_TYPE;
4503a4588,4593
>   G_RESNAM VARCHAR2(130);
>   G_RESNAM_NQ VARCHAR2(130);
>   G_TABNAM VARCHAR2(130);
>   G_TABNAM_NQ VARCHAR2(130);
>   G_COLNAM VARCHAR2(1024);
>   G_COLNAM_NQ VARCHAR2(1024);
4515a4606,4626
>   IF ( SDO_UTIL.IS_BUMPY_CASE(RESULT_TABLE) ) THEN
>     G_RESNAM := RESULT_TABLE;
>   ELSE
>     G_RESNAM := REPLACE(NLS_UPPER(RESULT_TABLE), '"');
>   END IF;
>   G_RESNAM_NQ := REPLACE(G_RESNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(GEOM_TABLE) ) THEN
>     G_TABNAM := GEOM_TABLE;
>   ELSE
>     G_TABNAM := REPLACE(NLS_UPPER(GEOM_TABLE), '"');
>   END IF;
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(GEOM_COLUMN) ) THEN
>     G_COLNAM := GEOM_COLUMN;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(GEOM_COLUMN), '"');
>   END IF;
>   G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
4518,4519c4629,4633
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_COLUMN) || ' FROM ' || 
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_TABLE) || ' T '; 
---
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM) || ' FROM ' || 
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM) || ' T '; 
> 
>   UPDATE_STR := 'INSERT INTO ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>                 ' VALUES (:gid, :gid_result)';
4521,4528d4634
<   UPDATE_STR := 'INSERT INTO ' || 
<  SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<                  ' VALUES (:gid, :gid_result)'; 
< 
<   INSERT_COMMIT := 'INSERT INTO ' || 
<  SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<                  ' VALUES (NULL, ''DONE'')'; 
<   
4533,4534c4639,4640
<                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_TABLE),
<                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOM_COLUMN),
---
>                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM),
>                        SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
4551,4552c4657,4658
<          RAISE ;
<   END ; 
---
>        RAISE;
>   END; 
4558c4664
<   OPEN QUERY_CRS FOR QUERY_STR ;
---
>   OPEN QUERY_CRS FOR QUERY_STR;
4560,4562c4666,4668
<   WHEN TABLE_DOES_NOT_EXIST THEN
<   CLOSE QUERY_CRS;
<   MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13261, GEOM_TABLE);
---
>     WHEN TABLE_DOES_NOT_EXIST THEN
>       CLOSE QUERY_CRS;
>       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13261, GEOM_TABLE);
4568c4674
<      FETCH QUERY_CRS INTO GID, THEGEOMETRY ;
---
>      FETCH QUERY_CRS INTO GID, THEGEOMETRY;
4572,4573c4678,4679
<       CLOSE QUERY_CRS ;
<       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13265, GEOM_COLUMN, GEOM_TABLE);
---
>         CLOSE QUERY_CRS;
>         MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13265, GEOM_COLUMN, GEOM_TABLE);
4576,4577c4682,4683
<       CLOSE QUERY_CRS ;
<       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13263, GEOM_COLUMN, GEOM_TABLE);
---
>         CLOSE QUERY_CRS;
>         MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', 13263, GEOM_COLUMN, GEOM_TABLE);
4580,4582c4686,4688
<         CLOSE QUERY_CRS ;
<         RAISE ;
<      END ; 
---
>         CLOSE QUERY_CRS;
>         RAISE;
>      END; 
4584c4690
<      EXIT WHEN QUERY_CRS%NOTFOUND ;
---
>      EXIT WHEN QUERY_CRS%NOTFOUND;
4634c4740
<        EXECUTE IMMEDIATE UPDATE_STR USING GID, GID_RESULT ;
---
>        EXECUTE IMMEDIATE UPDATE_STR USING GID, GID_RESULT;
4643,4644c4749,4750
<   END LOOP ;
<   CLOSE QUERY_CRS ;
---
>   END LOOP;
>   CLOSE QUERY_CRS;
4648,4650c4754,4755
<   ROW_COUNT_INSERT := 'INSERT INTO ' || 
<            SYS.DBMS_ASSERT.ENQUOTE_NAME(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(RESULT_TABLE)) ||
<            ' VALUES (NULL, :str1) ';
---
>   ROW_COUNT_INSERT := 'INSERT INTO ' || SDO_UTIL.SET_QUOTED_NAME(G_RESNAM_NQ) ||
>                       ' VALUES (NULL, :str1) ';
4656c4761
<        RAISE ;
---
>      RAISE;
4683d4787
< 
4687d4790
<                 
MDSYS.SDO_GEOR - PACKAGE BODY (RU):
4281c4281
<   IF ISNODATAMASK IS NOT NULL AND UPPER(ISNODATAMASK) = 'TRUE' THEN
---
>   IF ISNODATAMASK IS NOT NULL AND NLS_UPPER(ISNODATAMASK) = 'TRUE' THEN
6855c6855
<   IF((NODATA IS NOT NULL)AND(UPPER(NODATA)='TRUE'))
---
>   IF((NODATA IS NOT NULL)AND(NLS_UPPER(NODATA)='TRUE'))
6918c6918
<           IF((MLOCATION IS NOT NULL)AND(UPPER(MLOCATION)='UPPERLEFT'))
---
>           IF((MLOCATION IS NOT NULL)AND(NLS_UPPER(MLOCATION)='UPPERLEFT'))
6995c6995
<             IF((MLOCATION IS NOT NULL)AND(UPPER(MLOCATION)='UPPERLEFT'))
---
>             IF((MLOCATION IS NOT NULL)AND(NLS_UPPER(MLOCATION)='UPPERLEFT'))
MDSYS.SDO_GEOR_AGGR - PACKAGE BODY (RU):
48c48
<     PARAM := UPPER(SUBSTR(MOSAICPARAM, 1, 1000));
---
>     PARAM := NLS_UPPER(SUBSTR(MOSAICPARAM, 1, 1000));
972c972
<         IDX := INSTR(UPPER(RESUNIT), 'UNIT');
---
>         IDX := INSTR(NLS_UPPER(RESUNIT), 'UNIT');
998c998
<             WHERE UPPER(UNIT_OF_MEAS_NAME) = UPPER(RESUNIT)
---
>             WHERE NLS_UPPER(UNIT_OF_MEAS_NAME) = NLS_UPPER(RESUNIT)
MDSYS.SDO_IDX - PACKAGE BODY (RU):
115a116
>       0, 
204a206
>       0, 
256a259,350
>     ENDIAN_FLAG               IN VARCHAR2) IS
>   BEGIN
>     TTS_INDEX_INITIALIZE(
>       SCHEMA_NAME,
>       SDO_INDEX_TYPE,
>       SDO_LEVEL,
>       SDO_NUMTILES,
>       SDO_MAXLEVEL,
>       SDO_COMMIT_INTERVAL,
>       SDO_INDEX_TABLE,
>       SDO_INDEX_NAME,
>       SDO_INDEX_PRIMARY,
>       SDO_TSNAME,
>       SDO_COLUMN_NAME,
>       SDO_RTREE_HEIGHT,
>       SDO_RTREE_NUM_NODES,
>       SDO_RTREE_DIMENSIONALITY,
>       SDO_RTREE_FANOUT,
>       SDO_RTREE_ROOT,
>       SDO_RTREE_SEQ_NAME,
>       SDO_FIXED_META,
>       SDO_TABLESPACE,
>       SDO_INITIAL_EXTENT,
>       SDO_NEXT_EXTENT,
>       SDO_PCTINCREASE,
>       SDO_MIN_EXTENTS,
>       SDO_MAX_EXTENTS,
>       SDO_INDEX_DIMS,
>       SDO_LAYER_GTYPE,
>       SDO_RTREE_PCTFREE,
>       SDO_INDEX_PARTITION,
>       SDO_PARTITIONED,
>       SDO_RTREE_QUALITY,
>       SDO_INDEX_VERSION,
>       SDO_INDEX_GEODETIC,
>       SDO_INDEX_STATUS,
>       SDO_NL_INDEX_TABLE,
>       SDO_DML_BATCH_SIZE,
>       0, 
>       SDO_RTREE_ENT_XPND,
>       NULL,
>       0,
>       0,
>       NULL,
>       SDO_ROOT_MBR,
>       ENDIAN_FLAG);
>   END;
> 
> 
>   PROCEDURE TTS_INDEX_INITIALIZE(
>     SCHEMA_NAME               IN VARCHAR2,
>     SDO_INDEX_TYPE            IN VARCHAR2,
>     SDO_LEVEL                 IN NUMBER,
>     SDO_NUMTILES              IN NUMBER,
>     SDO_MAXLEVEL              IN NUMBER,
>     SDO_COMMIT_INTERVAL       IN NUMBER,
>     SDO_INDEX_TABLE           IN VARCHAR2,
>     SDO_INDEX_NAME            IN VARCHAR2,
>     SDO_INDEX_PRIMARY         IN NUMBER,
>     SDO_TSNAME                IN VARCHAR2,
>     SDO_COLUMN_NAME           IN VARCHAR2,
>     SDO_RTREE_HEIGHT          IN NUMBER,
>     SDO_RTREE_NUM_NODES       IN NUMBER,
>     SDO_RTREE_DIMENSIONALITY  IN NUMBER,
>     SDO_RTREE_FANOUT          IN NUMBER, 
>     SDO_RTREE_ROOT            IN VARCHAR2,
>     SDO_RTREE_SEQ_NAME        IN VARCHAR2,
>     SDO_FIXED_META            IN RAW,
>     SDO_TABLESPACE            IN VARCHAR2,
>     SDO_INITIAL_EXTENT        IN VARCHAR2,
>     SDO_NEXT_EXTENT           IN VARCHAR2,
>     SDO_PCTINCREASE           IN NUMBER,
>     SDO_MIN_EXTENTS           IN NUMBER,
>     SDO_MAX_EXTENTS           IN NUMBER,
>     SDO_INDEX_DIMS            IN NUMBER,
>     SDO_LAYER_GTYPE           IN VARCHAR2,
>     SDO_RTREE_PCTFREE         IN NUMBER,
>     SDO_INDEX_PARTITION       IN VARCHAR2,
>     SDO_PARTITIONED           IN NUMBER,
>     SDO_RTREE_QUALITY         IN NUMBER,
>     SDO_INDEX_VERSION         IN NUMBER,
>     SDO_INDEX_GEODETIC        IN VARCHAR2,
>     SDO_INDEX_STATUS          IN VARCHAR2,
>     SDO_NL_INDEX_TABLE        IN VARCHAR2,
>     SDO_DML_BATCH_SIZE        IN NUMBER,
>     SDO_RTREE_READ_ONLY       IN NUMBER,
>     SDO_RTREE_ENT_XPND        IN NUMBER,
>     SDO_INDEX_OID             IN VARCHAR2,
>     SDO_NUM_ROWS              IN NUMBER,
>     SDO_NUM_BLKS              IN NUMBER,
>     SDO_TABLE_NAME            IN VARCHAR2,
>     SDO_ROOT_MBR              IN MDSYS.SDO_GEOMETRY,
301c395
<       EXECUTE IMMEDIATE 'SELECT sdo_util.check_endian(:sch, :tab, :root) from dual'
---
>       EXECUTE IMMEDIATE 'SELECT sdo_util.check_endian(:sch, :tab, :root) from sys.dual'
351a446
>       SDO_RTREE_READ_ONLY,
MDSYS.SDO_META - PACKAGE BODY (RU):
2a3
> 
9,10c10,18
<   TABLE_NAME VARCHAR2(130) := NLS_UPPER(NEW_TABLE_NAME);
<   COLUMN_NAME VARCHAR2(1024) := NLS_UPPER(NEW_COLUMN_NAME);
---
>   STMT VARCHAR2(4000);
>   
>   
>   
>   
>   
>   
>   TABLE_NAME VARCHAR2(130);
>   COLUMN_NAME VARCHAR2(1024);
12,16c20,65
<   SELECT COUNT(*) INTO DATA_EXISTS
<   FROM MDSYS.SDO_GEOM_METADATA_TABLE
<   WHERE SDO_OWNER = OWNER
<   AND SDO_TABLE_NAME = TABLE_NAME
<   AND SDO_COLUMN_NAME = COLUMN_NAME;
---
>   
>   IF ( OWNER IS NULL ) THEN
>     MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>                                'Owner cannot be NULL');
>   END IF;
>   
>   
> 
>   
>   IF ( NEW_TABLE_NAME IS NULL ) THEN
>     MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>                                'Table name cannot be NULL');
>   END IF;
> 
>   
>   
>   
>   IF ( SDO_UTIL.IS_BUMPY_CASE(NEW_TABLE_NAME) ) THEN
>     TABLE_NAME := NEW_TABLE_NAME;
>   ELSE
>     
>     TABLE_NAME := REPLACE(NLS_UPPER(NEW_TABLE_NAME), '"');
>   END IF;
> 
>   
>   IF ( NEW_COLUMN_NAME IS NULL ) THEN
>     MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>                                'Column name cannot be NULL');
>   END IF;
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(NEW_COLUMN_NAME) ) THEN
>     COLUMN_NAME := NEW_COLUMN_NAME;
>   ELSIF (INSTRB(NEW_COLUMN_NAME, 'JSON_VALUE(') > 0) THEN
>     COLUMN_NAME := NEW_COLUMN_NAME;
>   ELSE
>     
>     COLUMN_NAME := REPLACE(NLS_UPPER(NEW_COLUMN_NAME), '"');
>   END IF;
> 
>   STMT := 'SELECT count(*) ' ||
>           'FROM MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>           'WHERE sdo_owner = :own ' ||
>           'AND sdo_table_name = :tab ' ||
>           'AND sdo_column_name = :col';
>   EXECUTE IMMEDIATE STMT INTO DATA_EXISTS
>     USING OWNER, TABLE_NAME, COLUMN_NAME;
19,20c68,71
<     INSERT INTO MDSYS.SDO_GEOM_METADATA_TABLE 
<     VALUES (OWNER, TABLE_NAME, COLUMN_NAME, DIMINFO, SRID);
---
>     STMT := 'INSERT INTO MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>             'VALUES(:own, :tab, :col, :dim, :srid)';
>     EXECUTE IMMEDIATE STMT
>       USING OWNER, TABLE_NAME, COLUMN_NAME, DIMINFO, SRID;
23a75
> 
31a84
> 
37a91
> 
47a102
> 
53a109
> 
62a119
> 
68a126
> 
75a134
>   STMT VARCHAR2(4000);
85,92c144,154
<   DELETE FROM MDSYS.SDO_GEOM_METADATA_TABLE
<   WHERE SDO_OWNER = OWNER
<     AND SDO_TABLE_NAME = NLS_UPPER(OLD_TABLE_NAME)
<     AND SDO_COLUMN_NAME = NLS_UPPER(OLD_COLUMN_NAME);
< 
<   INSERT INTO MDSYS.SDO_GEOM_METADATA_TABLE 
<     VALUES (OWNER, NLS_UPPER(NEW_TABLE_NAME), NLS_UPPER(NEW_COLUMN_NAME),
<             DIMINFO, SRID);
---
>   STMT := 'DELETE FROM MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>           'WHERE SDO_OWNER = :own ' ||
>           'AND SDO_TABLE_NAME = :tab ' ||
>           'AND SDO_COLUMN_NAME = :col';
>   EXECUTE IMMEDIATE STMT
>     USING OWNER, OLD_TABLE_NAME, OLD_COLUMN_NAME;
> 
>   STMT := 'INSERT INTO MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>           'VALUES(:own, :tab, :col, :dim, :srid)';
>   EXECUTE IMMEDIATE STMT
>     USING OWNER, NEW_TABLE_NAME, NEW_COLUMN_NAME, DIMINFO, SRID;
123a186
>   STMT VARCHAR2(4000);
129,132c192,197
<   DELETE FROM MDSYS.SDO_GEOM_METADATA_TABLE
<   WHERE SDO_OWNER = OWNER
<     AND SDO_TABLE_NAME = OLD_TABLE_NAME
<     AND SDO_COLUMN_NAME = OLD_COLUMN_NAME;
---
>   STMT := 'DELETE FROM MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>           'WHERE SDO_OWNER = :own ' ||
>           'AND SDO_TABLE_NAME = :tab ' ||
>           'AND SDO_COLUMN_NAME = :col';
>   EXECUTE IMMEDIATE STMT
>     USING OWNER, OLD_TABLE_NAME, OLD_COLUMN_NAME;
136a202
>   STMT VARCHAR2(4000);
143,145c209,213
<   DELETE FROM MDSYS.SDO_GEOM_METADATA_TABLE
<   WHERE SDO_OWNER = OWNER
<     AND SDO_TABLE_NAME = OLD_TABLE_NAME;
---
>   STMT := 'DELETE FROM MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>           'WHERE SDO_OWNER = :own ' ||
>           'AND SDO_TABLE_NAME = :tab';
>   EXECUTE IMMEDIATE STMT
>     USING OWNER, OLD_TABLE_NAME;
MDSYS.SDO_MIGRATE - PACKAGE BODY (RU):
165,185c165,207
< PROCEDURE MDMIG(LAYER IN VARCHAR2, NEWTABNAME IN VARCHAR2,
<                 GIDCOLUMN IN VARCHAR2, GEOCOLNAME IN VARCHAR2, 
<                 LAYER_GTYPE IN VARCHAR2, UPDATE_FLAG IN VARCHAR2) IS
<    EXTERNAL
<    NAME "mdmig"
<    LIBRARY ORDMD_MIG_LIBS
<    WITH CONTEXT
<    PARAMETERS(CONTEXT, LAYER OCISTRING, NEWTABNAME OCISTRING,
<               GIDCOLUMN OCISTRING, GEOCOLNAME OCISTRING, 
<               LAYER_GTYPE OCISTRING, UPDATE_FLAG OCISTRING);
< 
< 
< PROCEDURE TO_81X(LAYER IN VARCHAR2, NEWTABNAME IN VARCHAR2,
<                  GIDCOLUMN IN VARCHAR2, GEOCOLNAME IN VARCHAR2, 
<                  LAYER_GTYPE IN VARCHAR2, UPDATE_FLAG IN VARCHAR2) IS
< CNT NUMBER;
< USER1 VARCHAR2(130);
< TAB1 VARCHAR2(130);
< USER2 VARCHAR2(130);
< TAB2 VARCHAR2(130);
< RES VARCHAR2(10);
---
> 
> 
> 
> 
> 
> 
> 
> 
> PROCEDURE MDMIG(LAYER IN VARCHAR2,
>                 NEWTABNAME IN VARCHAR2,
>                 GIDCOLUMN IN VARCHAR2,
>                 GEOCOLNAME IN VARCHAR2,
>                 LAYER_GTYPE IN VARCHAR2,
>                 UPDATE_FLAG IN VARCHAR2)
> IS
>   EXTERNAL
>   NAME "mdmig"
>   LIBRARY ORDMD_MIG_LIBS
>   WITH CONTEXT
>   PARAMETERS(CONTEXT, LAYER OCISTRING, NEWTABNAME OCISTRING,
>              GIDCOLUMN OCISTRING, GEOCOLNAME OCISTRING,
>              LAYER_GTYPE OCISTRING, UPDATE_FLAG OCISTRING);
> 
> 
> PROCEDURE TO_81X(LAYER IN VARCHAR2,
>                  NEWTABNAME IN VARCHAR2,
>                  GIDCOLUMN IN VARCHAR2,
>                  GEOCOLNAME IN VARCHAR2,
>                  LAYER_GTYPE IN VARCHAR2,
>                  UPDATE_FLAG IN VARCHAR2)
> IS
>   CNT NUMBER;
>   USER1 VARCHAR2(130);
>   TAB1 VARCHAR2(130);
>   USER2 VARCHAR2(130);
>   TAB2 VARCHAR2(130);
>   RES VARCHAR2(10);
>   STMT VARCHAR2(4000);
>   U1 VARCHAR2(200);
>   U2 VARCHAR2(200);
>   D1 VARCHAR2(200);
>   G1 VARCHAR2(200);
>   T2 VARCHAR2(200);
191c213,217
<       TAB1 := NLS_UPPER(LAYER);
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(LAYER) ) THEN
>         TAB1 := LAYER;
>       ELSE
>         TAB1 := REPLACE(NLS_UPPER(LAYER), '"');
>       END IF;
194c220,223
<       TAB1 := NLS_UPPER(SUBSTR(LAYER, CNT+1));
---
>       TAB1 := SUBSTR(LAYER, CNT+1);
>       IF ( NOT SDO_UTIL.IS_BUMPY_CASE(TAB1) ) THEN
>         TAB1 := REPLACE(NLS_UPPER(TAB1), '"');
>       END IF;
208c237,241
<       TAB2 := NLS_UPPER(NEWTABNAME);
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(NEWTABNAME) ) THEN
>         TAB2 := NEWTABNAME;
>       ELSE
>         TAB2 := REPLACE(NLS_UPPER(NEWTABNAME), '"');
>       END IF;
211c244,247
<       TAB2 := NLS_UPPER(SUBSTR(NEWTABNAME, CNT+1));
---
>       TAB2 := SUBSTR(NEWTABNAME, CNT+1);
>       IF ( NOT SDO_UTIL.IS_BUMPY_CASE(TAB2) ) THEN
>         TAB2 := REPLACE(NLS_UPPER(TAB2), '"');
>       END IF;
213a250,255
>    T2 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2);
>    U2 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER2);
>    D1 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(REPLACE(TAB1, '"')) || '_SDODIM';
>    G1 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(REPLACE(TAB1, '"')) || '_SDOGEOM';
>    U1 := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1);
> 
215,223c257,267
<    EXECUTE IMMEDIATE
<    'SELECT COUNT(TABLE_NAME) FROM SYS.ALL_TABLES WHERE '||
<    '(TABLE_NAME=  :tab2 AND OWNER= :user2) OR  ' ||
<      ' (TABLE_NAME= :tab1 AND OWNER= :user1) '
<    INTO CNT
<      USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2),
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER2),
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB1)||'_SDOGEOM',
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1);
---
>    STMT := 'SELECT COUNT(TABLE_NAME) ' ||
>            'FROM SYS.ALL_TABLES ' ||
>            'WHERE (TABLE_NAME = :tab2 AND OWNER = :user2) ' ||
>            'OR    (TABLE_NAME = :tab1 AND OWNER = :user1)';
>    BEGIN
>      EXECUTE IMMEDIATE STMT INTO CNT
>        USING T2, U2, G1, U1;
> 
>      EXCEPTION WHEN OTHERS THEN
>        RAISE;
>    END;
226c270
<       MDERR.RAISE_MD_ERROR('MD','SDO',-13108, NEWTABNAME||'_OR_'||LAYER||'_SDOGEOM');
---
>       MDERR.RAISE_MD_ERROR('MD','SDO',-13108, T2 || ' _OR_ ' || G1);
234,245c278,291
<        EXECUTE IMMEDIATE
<          'UPDATE '|| 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER2) ||'.'|| 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2) || ' a ' ||
<          'SET ' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOCOLNAME) || ' = (SELECT ' ||
<          'MDSYS.SDO_GEOMETRY(1,NULL,MDSYS.SDO_POINT_TYPE(sdo_x1,sdo_y1,NULL),NULL,NULL)'||
<          'FROM ' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1) || '.' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB1) || '_SDOGEOM b ' ||
<          'WHERE a.' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GIDCOLUMN) ||' = b.sdo_gid)'; 
---
>         STMT := 'UPDATE "' || U2 || '"."' || T2 || '" a ' ||
>                 'SET "' ||
>                 SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOCOLNAME) ||
>                 '" = (SELECT ' ||
>                 'MDSYS.SDO_GEOMETRY(1,NULL,MDSYS.SDO_POINT_TYPE(sdo_x1,sdo_y1,NULL),NULL,NULL)' ||
>                 'FROM "' || U1 || '"."' || G1 || '" b ' ||
>                 'WHERE a.' ||
>                 SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GIDCOLUMN) ||' = b.sdo_gid)';
>        BEGIN
>          EXECUTE IMMEDIATE STMT;
> 
>          EXCEPTION WHEN OTHERS THEN
>            RAISE;
>        END;
247,257c293,304
<        EXECUTE IMMEDIATE
<          'INSERT INTO '|| 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER2) ||'.'|| 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2) ||
<          '(' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GIDCOLUMN) || ',' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOCOLNAME) || ') SELECT SDO_GID,'||
<          'MDSYS.SDO_GEOMETRY(1,NULL,MDSYS.SDO_POINT_TYPE(sdo_x1,sdo_y1,NULL),NULL,NULL)'||
<          'FROM ' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1) || '.' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB1) || '_SDOGEOM';
---
>         STMT := 'INSERT INTO ' || U2 || '.' || T2 || '(' ||
>                 SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GIDCOLUMN) || ',' ||
>                 SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOCOLNAME) || ') ' ||
>                 'SELECT SDO_GID,' ||
>                  'MDSYS.SDO_GEOMETRY(1,NULL,MDSYS.SDO_POINT_TYPE(sdo_x1,sdo_y1,NULL),NULL,NULL)' ||
>                  'FROM ' || U1 || '.' || G1;
>        BEGIN
>          EXECUTE IMMEDIATE STMT;
> 
>          EXCEPTION WHEN OTHERS THEN
>            RAISE;
>        END;
261,262c308
<        MDMIG(NLS_UPPER(LAYER), NLS_UPPER(NEWTABNAME), NLS_UPPER(GIDCOLUMN), 
<              NLS_UPPER(GEOCOLNAME), 'NOTPOINT', 'UPDATE');
---
>        MDMIG(LAYER, NEWTABNAME, GIDCOLUMN, GEOCOLNAME, 'NOTPOINT', 'UPDATE');
264,265c310
<        MDMIG(NLS_UPPER(LAYER), NLS_UPPER(NEWTABNAME), NLS_UPPER(GIDCOLUMN), 
<              NLS_UPPER(GEOCOLNAME), 'NOTPOINT', 'INSERT');
---
>        MDMIG(LAYER, NEWTABNAME, GIDCOLUMN, GEOCOLNAME, 'NOTPOINT', 'INSERT');
270,274c315,325
<    EXECUTE IMMEDIATE
<    'SELECT COUNT(TABLE_NAME) FROM MDSYS.ALL_SDO_GEOM_METADATA '||
<    '  WHERE OWNER = :user2  AND  TABLE_NAME= :tab2 '
<    INTO CNT USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER2),
<                   SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2);
---
>    STMT := 'SELECT COUNT(TABLE_NAME) ' ||
>            'FROM MDSYS.ALL_SDO_GEOM_METADATA '||
>            'WHERE OWNER = :user2 ' ||
>            'AND TABLE_NAME = :tab2';
>    BEGIN
>      EXECUTE IMMEDIATE STMT INTO CNT
>        USING U2, T2;
> 
>          EXCEPTION WHEN OTHERS THEN
>            RAISE;
>    END;
277,293c328,352
<       EXECUTE IMMEDIATE 
<      'INSERT INTO MDSYS.USER_SDO_GEOM_METADATA VALUES (:tab2, :col,  '||
<       '  MDSYS.SDO_DIM_ARRAY(),NULL)' 
<        USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2), 
<               NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOCOLNAME));
<    
<      BEGIN 
<        EXECUTE IMMEDIATE
<        'UPDATE MDSYS.USER_SDO_GEOM_METADATA SET DIMINFO = '||
<            '(SELECT CAST(MULTISET(SELECT MDSYS.SDO_DIM_ELEMENT(SDO_DIMNAME,'||
<            'SDO_LB, SDO_UB, SDO_TOLERANCE) FROM ' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1) || '.' || 
<         SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB1) || 
<               '_SDODIM' ||
<            ') AS MDSYS.SDO_DIM_ARRAY) FROM SYS.DUAL) WHERE ' ||
<              ' TABLE_NAME =  :tab '
<            USING  SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2);
---
>      STMT := 'INSERT INTO MDSYS.USER_SDO_GEOM_METADATA ' ||
>              'VALUES(:tab2, :col, MDSYS.SDO_DIM_ARRAY(), NULL)';
>      BEGIN
>        EXECUTE IMMEDIATE STMT
>          USING T2, SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(GEOCOLNAME);
> 
>        EXCEPTION WHEN OTHERS THEN
>          RAISE;
>       END;
>      BEGIN
>        STMT := 'UPDATE MDSYS.USER_SDO_GEOM_METADATA ' ||
>                'SET DIMINFO = '||
>                '(SELECT CAST(MULTISET(SELECT MDSYS.SDO_DIM_ELEMENT(SDO_DIMNAME,'||
>                ' SDO_LB, SDO_UB, SDO_TOLERANCE) ' ||
>                ' FROM ' || U1 || '.' || D1 ||
>                ') AS MDSYS.SDO_DIM_ARRAY) FROM SYS.DUAL) ' ||
>                'WHERE TABLE_NAME = :tab';
>        BEGIN
>          EXECUTE IMMEDIATE STMT
>            USING T2;
> 
>          EXCEPTION WHEN OTHERS THEN
>            RAISE;
>        END;
> 
297,306c356,366
<            EXECUTE IMMEDIATE
<            'UPDATE MDSYS.USER_SDO_GEOM_METADATA SET DIMINFO = '||
<                '(SELECT CAST(MULTISET(SELECT MDSYS.SDO_DIM_ELEMENT(NULL,'||
<                'SDO_LB, SDO_UB, SDO_TOLERANCE) FROM ' || 
<           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1) || '.' || 
<           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB1) ||
<                   '_SDODIM' ||
<                ') AS MDSYS.SDO_DIM_ARRAY) FROM SYS.DUAL) WHERE ' ||
<                  ' TABLE_NAME =  :tab '
<            USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2);
---
>            STMT := 'UPDATE MDSYS.USER_SDO_GEOM_METADATA ' ||
>                    'SET DIMINFO = '||
>                    '(SELECT CAST(MULTISET(SELECT MDSYS.SDO_DIM_ELEMENT(NULL,'||
>                    ' SDO_LB, SDO_UB, SDO_TOLERANCE) ' ||
>                    ' FROM ' ||
>                    SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(USER1) || '.' ||
>                    SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB1) || '_SDODIM' ||
>                    ') AS MDSYS.SDO_DIM_ARRAY) FROM SYS.DUAL) ' ||
>                    'WHERE TABLE_NAME = :tab';
>            EXECUTE IMMEDIATE STMT
>              USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TAB2);
320,322c380,386
< PROCEDURE TO_CURRENT(LAYER IN VARCHAR2, NEWTABNAME IN VARCHAR2,
<                  GIDCOLUMN IN VARCHAR2, GEOCOLNAME IN VARCHAR2, 
<                  LAYER_GTYPE IN VARCHAR2, UPDATE_FLAG IN VARCHAR2) IS
---
> PROCEDURE TO_CURRENT(LAYER IN VARCHAR2,
>                      NEWTABNAME IN VARCHAR2,
>                      GIDCOLUMN IN VARCHAR2,
>                      GEOCOLNAME IN VARCHAR2,
>                      LAYER_GTYPE IN VARCHAR2,
>                      UPDATE_FLAG IN VARCHAR2)
> IS
324,325c388,389
<  TO_81X(LAYER, NEWTABNAME, GIDCOLUMN, GEOCOLNAME, LAYER_GTYPE, UPDATE_FLAG);
< END;
---
>   TO_81X(LAYER, NEWTABNAME, GIDCOLUMN, GEOCOLNAME, LAYER_GTYPE, UPDATE_FLAG);
> END TO_CURRENT;
329,336c393,401
< RETURN  MDSYS.SDO_GEOMETRY DETERMINISTIC PARALLEL_ENABLE IS
<    EXTERNAL
<    NAME "mdmige"
<    LIBRARY ORDMD_MIG_LIBS
<    WITH CONTEXT
<    PARAMETERS(CONTEXT, DIMOBJ, DIMOBJ INDICATOR,
<              GEOMOBJ, GEOMOBJ INDICATOR STRUCT, 
<              RETURN  INDICATOR STRUCT, RETURN);
---
> RETURN  MDSYS.SDO_GEOMETRY DETERMINISTIC PARALLEL_ENABLE
> IS
>   EXTERNAL
>   NAME "mdmige"
>   LIBRARY ORDMD_MIG_LIBS
>   WITH CONTEXT
>   PARAMETERS(CONTEXT, DIMOBJ, DIMOBJ INDICATOR,
>              GEOMOBJ, GEOMOBJ INDICATOR STRUCT,
>              RETURN INDICATOR STRUCT, RETURN);
339,340c404,407
< PROCEDURE FROM_815_TO_81X(TABNAME IN VARCHAR2, COLNAME IN VARCHAR2,
<                           COMMIT_INT IN NUMBER) IS
---
> PROCEDURE FROM_815_TO_81X(TABNAME IN VARCHAR2,
>                           COLNAME IN VARCHAR2,
>                           COMMIT_INT IN NUMBER)
> IS
356a424,427
>   G_TABNAME VARCHAR2(130);
>   G_TABNAME_NQ VARCHAR2(130);
>   G_COLNAME VARCHAR2(1024);
>   G_COLNAME_NQ VARCHAR2(1024);
357a429,442
>   IF ( SDO_UTIL.IS_BUMPY_CASE(TABNAME) ) THEN
>     G_TABNAME := TABNAME;
>   ELSE
>     G_TABNAME := REPLACE(NLS_UPPER(TABNAME), '"');
>   END IF;
>   G_TABNAME_NQ := REPLACE(G_TABNAME, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(COLNAME) ) THEN
>     G_COLNAME := COLNAME;
>   ELSE
>     G_COLNAME := REPLACE(NLS_UPPER(COLNAME), '"');
>   END IF;
>   G_COLNAME_NQ := REPLACE(G_COLNAME, '"');
> 
361,362c446,447
<     SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABNAME),
<     SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME),
---
>     SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAME),
>     SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAME),
367,377c452,462
<  
<   STMT1 := 'SELECT rowid, ' || 
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME)
<               || ' FROM ' ||
<                SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABNAME) ||
<            ' WHERE ' ||
<              SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME) || ' is not null ';
<   STMT2 := 'UPDATE ' || 
<          SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABNAME) || ' SET ' || 
<            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME) || ' = :geom ' ||
<            'WHERE rowid = :rid';  
---
> 
>   STMT1 := 'SELECT rowid, "' ||
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAME_NQ) ||
>            '" FROM "' || SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAME_NQ) ||
>            '" WHERE "' || SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME) ||
>            '" is not null';
>   STMT2 := 'UPDATE "' ||
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAME_NQ) ||
>            '" SET "' ||
>            SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAME_NQ) ||
>            '" = :geom WHERE rowid = :rid';
420a506
> 
433c519,521
< PROCEDURE FROM_815_TO_81X(TABNAME IN VARCHAR2, COMMIT_INT IN NUMBER) IS
---
> PROCEDURE FROM_815_TO_81X(TABNAME IN VARCHAR2,
>                           COMMIT_INT IN NUMBER)
> IS
438c526,528
<   COLNAME  VARCHAR2(260);
---
>   G_TABNAME VARCHAR2(130);
>   G_TABNAME_NQ VARCHAR2(130);
>   COLNAME  VARCHAR2(1024);
441,442c531,540
<   STMT := 'SELECT count(*) FROM tab ' ||
<           'WHERE tname =  :tab ';
---
>   IF ( SDO_UTIL.IS_BUMPY_CASE(TABNAME) ) THEN
>     G_TABNAME := TABNAME;
>   ELSE
>     G_TABNAME := REPLACE(NLS_UPPER(TABNAME), '"');
>   END IF;
>   G_TABNAME_NQ := REPLACE(G_TABNAME, '"');
> 
>   STMT := 'SELECT count(*) ' ||
>           'FROM tab ' ||
>           'WHERE tname = :tab';
444c542
<               USING NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABNAME));
---
>     USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAME_NQ);
449,451c547,550
<   STMT := 'SELECT column_name FROM sys.user_tab_columns ' ||
<           'WHERE table_name =  :tab  AND ' ||
<                 'data_type = ''SDO_GEOMETRY'' ';
---
>   STMT := 'SELECT column_name ' ||
>           'FROM sys.user_tab_columns ' ||
>           'WHERE table_name = :tab ' ||
>           'AND data_type = ''SDO_GEOMETRY'' ';
454c553
<       USING NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABNAME));
---
>     USING SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAME_NQ);
457a557
> 
472,473c572,575
< PROCEDURE TO_CURRENT(TABNAME IN VARCHAR2, COLUMN_NAME IN VARCHAR2,
<        COMMIT_INT IN NUMBER) IS
---
> PROCEDURE TO_CURRENT(TABNAME IN VARCHAR2,
>                      COLUMN_NAME IN VARCHAR2,
>                      COMMIT_INT IN NUMBER)
> IS
475,479c577,581
<  IF (COLUMN_NAME IS NULL) THEN 
<    FROM_815_TO_81X(TABNAME, COMMIT_INT);
<  ELSE
<    FROM_815_TO_81X(TABNAME, COLUMN_NAME, COMMIT_INT);
<  END IF;
---
>   IF (COLUMN_NAME IS NULL) THEN
>     FROM_815_TO_81X(TABNAME, COMMIT_INT);
>   ELSE
>     FROM_815_TO_81X(TABNAME, COLUMN_NAME, COMMIT_INT);
>   END IF;
483c585,586
<    PROCEDURE OGIS_METADATA_FROM IS
---
>    PROCEDURE OGIS_METADATA_FROM
>    IS
567c670,671
<   FUNCTION TO_CURRENT(GEOM IN MDSYS.SDO_GEOMETRY,
---
> 
> FUNCTION TO_CURRENT(GEOM IN MDSYS.SDO_GEOMETRY,
569c673,674
<   RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC PARALLEL_ENABLE IS
---
> RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC PARALLEL_ENABLE
> IS
576c681
<  BEGIN
---
> BEGIN
594,602c699,707
<      GEOM2 := GEOM;
<      FOR  I IN 1 .. GEOM2.SDO_ELEM_INFO.COUNT LOOP
<        IF (MOD(I,3) = 2) THEN 
<            ETYPE := MOD(GEOM2.SDO_ELEM_INFO(I), 10);
<            GEOM2.SDO_ELEM_INFO(I) := ETYPE;
<         END IF;
<      END LOOP;
<      RETURN MDMIGE(DIM, GEOM2);   
<    END IF;
---
>     GEOM2 := GEOM;
>     FOR  I IN 1 .. GEOM2.SDO_ELEM_INFO.COUNT LOOP
>       IF (MOD(I,3) = 2) THEN 
>         ETYPE := MOD(GEOM2.SDO_ELEM_INFO(I), 10);
>         GEOM2.SDO_ELEM_INFO(I) := ETYPE;
>       END IF;
>     END LOOP;
>     RETURN MDMIGE(DIM, GEOM2);
>   END IF;
604,605c709,710
<    RETURN MDMIGE(DIM, GEOM);   
<  END TO_CURRENT;
---
>   RETURN MDMIGE(DIM, GEOM);
> END TO_CURRENT;
MDSYS.SDO_PC_PKG - PACKAGE BODY (RU):
292c292
<       BLOCK_TABLE VARCHAR2(270) := UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(PC.BLK_TABLE));
---
>       BLOCK_TABLE VARCHAR2(270) := NLS_UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(PC.BLK_TABLE));
302,303c302,303
<     WHERE  UPPER(TABLE_NAME) = UPPER(PC.BLK_TABLE) AND
<            UPPER(COLUMN_NAME) = 'BLK_EXTENT';
---
>     WHERE  NLS_UPPER(TABLE_NAME) = NLS_UPPER(PC.BLK_TABLE) AND
>            NLS_UPPER(COLUMN_NAME) = 'BLK_EXTENT';
308c308
<         UPPER(PC.BLK_TABLE),
---
>         NLS_UPPER(PC.BLK_TABLE),
331,332c331,332
<     WHERE  UPPER(TABLE_NAME) = UPPER(PC.BLK_TABLE) AND
<            UPPER(COLUMN_NAME) = 'BLK_EXTENT';
---
>     WHERE  NLS_UPPER(TABLE_NAME) = NLS_UPPER(PC.BLK_TABLE) AND
>            NLS_UPPER(COLUMN_NAME) = 'BLK_EXTENT';
347a348,354
>     
>     IF ( SDO_UTIL.IS_BUMPY_CASE(INPTABLE) ) THEN
>       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>         'Bumpy-case "inptable" name is not supported');
>       RETURN;
>     END IF;
> 
407c414
<                                     LOWER(INP.PTN_PARAMS),
---
>                                     NLS_LOWER(INP.PTN_PARAMS),
1085c1092
<       TABLE_NAME = UPPER(PC.BLK_TABLE) AND
---
>       TABLE_NAME = NLS_UPPER(PC.BLK_TABLE) AND
4202c4209
<       BLOCK_TABLE_NAME_FOR_MD    VARCHAR2(270) := UPPER(DATA_TABLE_NAME_BASE || '$blocks');
---
>       BLOCK_TABLE_NAME_FOR_MD    VARCHAR2(270) := NLS_UPPER(DATA_TABLE_NAME_BASE || '$blocks');
4212c4219
<       SOURCE_TABLE_NAME_UPPER    VARCHAR2(270) := UPPER(SOURCE_TABLE_NAME);
---
>       SOURCE_TABLE_NAME_UPPER    VARCHAR2(270) := NLS_UPPER(SOURCE_TABLE_NAME);
4445c4452
<       BASE_TABLE2 VARCHAR2(270) := UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(BASE_TABLE));
---
>       BASE_TABLE2 VARCHAR2(270) := NLS_UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(BASE_TABLE));
4488,4489c4495,4496
<       UPPER(INP_TABLE) IN (UPPER(TABLE_NAME), UPPER(OWNER || '.' || TABLE_NAME)) AND
<       REGEXP_LIKE(UPPER(COLUMN_NAME), 'VAL_D[123456789][0123456789]*');
---
>       NLS_UPPER(INP_TABLE) IN (NLS_UPPER(TABLE_NAME), NLS_UPPER(OWNER || '.' || TABLE_NAME)) AND
>       REGEXP_LIKE(NLS_UPPER(COLUMN_NAME), 'VAL_D[123456789][0123456789]*');
4588c4595
<          'create table ' || UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(DATA_TABLE)) || ' as
---
>          'create table ' || NLS_UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(DATA_TABLE)) || ' as
4596c4603
<               ' || UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(INP_TABLE)) || ' s';
---
>               ' || NLS_UPPER(SYS.DBMS_ASSERT.ENQUOTE_NAME(INP_TABLE)) || ' s';
4649c4656
<       USING (UPPER(DATA_TABLE_NAME_BASE) || '$BLOCKS');
---
>       USING (NLS_UPPER(DATA_TABLE_NAME_BASE) || '$BLOCKS');
4688c4695
<       TABLE_NAME = UPPER(SOURCE_TABLE_NAME);
---
>       TABLE_NAME = NLS_UPPER(SOURCE_TABLE_NAME);
4747c4754
<         TABLE_NAME = UPPER(DATA_TABLE_NAME_BASE || '$FINAL') AND
---
>         TABLE_NAME = NLS_UPPER(DATA_TABLE_NAME_BASE || '$FINAL') AND
5376a5384,5395
>         WHEN TOO_MANY_ROWS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[prvtpc.sql(' || $$PLSQL_LINE || ')16a2]: ' || SQLERRM);
>           MDERR.RAISE_MD_ERROR(
>             'MD',
>             'CLIP_PC_INTO_TABLE',
>             -13249,
>             'Query <' ||
>             'select ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(PC_COLUMN) ||
>             ' from '  || SYS.DBMS_ASSERT.ENQUOTE_NAME(PC_TABLE)  ||
>             ' where ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(ID_COLUMN) || ' = ' || ID || '> yielded more than one result. Consider using a primary key to avoid this.');
6086,6088c6105,6107
<         ' where upper(table_name) = :table_name and' ||
<         ' upper(column_name) = ''BLK_EXTENT'''
<         USING SRID, UPPER(PC.BLK_TABLE);
---
>         ' where nls_upper(table_name) = :table_name and' ||
>         ' nls_upper(column_name) = ''BLK_EXTENT'''
>         USING SRID, NLS_UPPER(PC.BLK_TABLE);
6101,6102c6120,6121
<             ' where upper(table_name) = :table_name and' ||
<             ' upper(column_name) = ''BLK_EXTENT''> failed. Consider committing any inserts.');
---
>             ' where nls_upper(table_name) = :table_name and' ||
>             ' nls_upper(column_name) = ''BLK_EXTENT''> failed. Consider committing any inserts.');
6283,6286c6302,6305
<         UPPER(TEMP_TABLE_NAME_BASE || '$1'),
<         UPPER(TEMP_TABLE_NAME_BASE || '$2'),
<         UPPER(TEMP_TABLE_NAME_BASE || '$3'),
<         UPPER(TEMP_TABLE_NAME_BASE || '$4');
---
>         NLS_UPPER(TEMP_TABLE_NAME_BASE || '$1'),
>         NLS_UPPER(TEMP_TABLE_NAME_BASE || '$2'),
>         NLS_UPPER(TEMP_TABLE_NAME_BASE || '$3'),
>         NLS_UPPER(TEMP_TABLE_NAME_BASE || '$4');
MDSYS.SDO_RDF_INTERNAL - PACKAGE BODY (RU):
25446c25446
<         PRIV := (CASE UPPER(TAB_LIST(I)) WHEN 'RDF_SESSION_EVENT$' THEN 'SELECT, INSERT, UPDATE, DELETE' ELSE 'READ' END); 
---
>         PRIV := (CASE NLS_UPPER(TAB_LIST(I)) WHEN 'RDF_SESSION_EVENT$' THEN 'SELECT, INSERT, UPDATE, DELETE' ELSE 'READ' END); 
MDSYS.SDO_SAM - PACKAGE BODY (RU):
72c72,75
<         SELECT NLS_UPPER(SUBSTR(TABLE_NAME1, LEN+1)) INTO TNAMET FROM SYS.DUAL;
---
>         SELECT SUBSTR(TABLE_NAME1, LEN+1) INTO TNAMET FROM SYS.DUAL;
>         IF ( NOT SDO_UTIL.IS_BUMPY_CASE(TNAMET) ) THEN
>           TNAMET := REPLACE(NLS_UPPER(TNAMET), '"');
>         END IF;
77c80,84
<       TNAMET := NLS_UPPER(TABLE_NAME1);
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_NAME1) ) THEN
>         TNAMET := TABLE_NAME1;
>       ELSE
>         TNAMET := REPLACE(NLS_UPPER(TABLE_NAME1), '"');
>       END IF;
95c102,105
<         SELECT NLS_UPPER(SUBSTR(TABLE_NAME2, LEN+1)) INTO TNAMET FROM SYS.DUAL;
---
>         SELECT SUBSTR(TABLE_NAME2, LEN+1) INTO TNAMET FROM SYS.DUAL;
>         IF ( NOT SDO_UTIL.IS_BUMPY_CASE(TNAMET) ) THEN
>           TNAMET := REPLACE(NLS_UPPER(TNAMET), '"');
>         END IF;
100c110,114
<       TNAMET := NLS_UPPER(TABLE_NAME2);
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_NAME2) ) THEN
>         TNAMET := TABLE_NAME2;
>       ELSE
>         TNAMET := REPLACE(NLS_UPPER(TABLE_NAME2), '"');
>       END IF;
117,118c131,141
<     CNAME1 := NLS_UPPER(COLUMN_NAME1);
<     CNAME2 := NLS_UPPER(COLUMN_NAME2);
---
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME1) ) THEN
>       CNAME1 := COLUMN_NAME1;
>     ELSE
>       CNAME1 := REPLACE(NLS_UPPER(COLUMN_NAME1), '"');
>     END IF;
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME2) ) THEN
>       CNAME2 := COLUMN_NAME2;
>     ELSE
>       CNAME2 := REPLACE(NLS_UPPER(COLUMN_NAME2), '"');
>     END IF;
310a334,337
>     G_TABNAM    VARCHAR2(130);
>     G_TABNAM_NQ VARCHAR2(130);
>     G_COLNAM    VARCHAR2(1024);
>     G_COLNAM_NQ VARCHAR2(1024);
325,326c352,367
<     STHEME_TABLENAME := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NLS_UPPER(THEME_TABLENAME));
<     STHEME_COLNAME := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NLS_UPPER(THEME_COLNAME));
---
>     IF ( SDO_UTIL.IS_BUMPY_CASE(THEME_TABLENAME) ) THEN
>       G_TABNAM := THEME_TABLENAME;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(THEME_TABLENAME), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(THEME_COLNAME) ) THEN
>       G_COLNAM := THEME_COLNAME;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(THEME_COLNAME), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
>     STHEME_TABLENAME := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM);
>     STHEME_COLNAME := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_COLNAM);
341,342c382,383
<       STHEME_TABLENAME,
<       STHEME_COLNAME,
---
>       SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM),
>       SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
540a582,592
>    IF ( SDO_UTIL.IS_BUMPY_CASE(BIN_COLNAME) ) THEN
>      SBIN_COLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(BIN_COLNAME);
>    ELSE
>      SBIN_COLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(REPLACE(NLS_UPPER(BIN_COLNAME), '"'));
>    END IF;
> 
>    IF ( SDO_UTIL.IS_BUMPY_CASE(BIN_TABLENAME) ) THEN
>      SBIN_TABLENAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(BIN_TABLENAME);
>    ELSE
>      SBIN_TABLENAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(REPLACE(NLS_UPPER(BIN_TABLENAME), '"'));
>    END IF;
542,543d593
<    SBIN_COLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(NLS_UPPER(BIN_COLNAME));
<    SBIN_TABLENAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(NLS_UPPER(BIN_TABLENAME));
613a664,667
>     G_TABNAM    VARCHAR2(130);
>     G_TABNAM_NQ VARCHAR2(130);
>     G_COLNAM    VARCHAR2(1024);
>     G_COLNAM_NQ VARCHAR2(1024);
637a692,702
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLNAME) ) THEN
>       SCOLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLNAME);
>     ELSE
>       SCOLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(REPLACE(NLS_UPPER(COLNAME), '"'));
>     END IF;
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(TABLENAME) ) THEN
>       STABLENAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TABLENAME);
>     ELSE
>       STABLENAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(REPLACE(NLS_UPPER(TABLENAME), '"'));
>     END IF;
639,640d703
<     SCOLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(NLS_UPPER(COLNAME));
<     STABLENAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(NLS_UPPER(TABLENAME));
759c822,825
<         SELECT NLS_UPPER(SUBSTR(TABLENAME, LEN+1)) INTO TNAME FROM SYS.DUAL;
---
>         SELECT SUBSTR(TABLENAME, LEN+1) INTO TNAME FROM SYS.DUAL;
>         IF ( NOT SDO_UTIL.IS_BUMPY_CASE(TNAME) ) THEN
>           TNAME := REPLACE(NLS_UPPER(TNAME), '"');
>         END IF;
764c830,834
<       TNAME := NLS_UPPER(TABLENAME);
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABLENAME) ) THEN
>         TNAME := TABLENAME;
>       ELSE
>         TNAME := REPLACE(NLS_UPPER(TABLENAME), '"');
>       END IF;
967a1038,1041
>     G_TABNAM    VARCHAR2(130);
>     G_TABNAM_NQ VARCHAR2(130);
>     G_COLNAM    VARCHAR2(1024);
>     G_COLNAM_NQ VARCHAR2(1024);
991a1066,1079
>     IF ( SDO_UTIL.IS_BUMPY_CASE(THEME_NAME) ) THEN
>       G_TABNAM := THEME_NAME;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(THEME_NAME), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(THEME_COLNAME) ) THEN
>       G_COLNAM := THEME_COLNAME;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(THEME_COLNAME), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
994,996c1082,1083
<     STHEME_COLNAME :=
<       SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(NLS_UPPER(THEME_COLNAME));
<     STHEME_NAME := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NLS_UPPER(THEME_NAME));
---
>     STHEME_COLNAME := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM);
>     STHEME_NAME := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(NLS_UPPER(G_TABNAM));
1035c1122
<       USING NLS_UPPER(STHEME_NAME), NLS_UPPER(AGGR_COL_STRING);
---
>       USING STHEME_NAME, NLS_UPPER(AGGR_COL_STRING);
1050c1137
<         INTO OWNR USING NLS_UPPER(STHEME_NAME);
---
>         INTO OWNR USING STHEME_NAME;
1063c1150
<       USING NLS_UPPER(STHEME_NAME), NLS_UPPER(AGGR_COL_STRING), OWNR;
---
>       USING STHEME_NAME, NLS_UPPER(AGGR_COL_STRING), OWNR;
1317c1404,1408
<     
---
>     G_TABNAM    VARCHAR2(130);
>     G_TABNAM_NQ VARCHAR2(130);
>     G_COLNAM    VARCHAR2(1024);
>     G_COLNAM_NQ VARCHAR2(1024);
> 
1334a1426,1439
>     IF ( SDO_UTIL.IS_BUMPY_CASE(THEME_NAME) ) THEN
>       G_TABNAM := THEME_NAME;
>     ELSE
>       G_TABNAM := REPLACE(NLS_UPPER(THEME_NAME), '"');
>     END IF;
>     G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(THEME_COLNAME) ) THEN
>       G_COLNAM := THEME_COLNAME;
>     ELSE
>       G_COLNAM := REPLACE(NLS_UPPER(THEME_COLNAME), '"');
>     END IF;
>     G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
1349,1350c1454,1455
<           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(THEME_NAME),
<           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(THEME_COLNAME),
---
>           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM),
>           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
1362,1363c1467,1468
<           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(THEME_NAME),
<           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(THEME_COLNAME),
---
>           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_TABNAM),
>           SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
MDSYS.SDO_TIN_PKG - PACKAGE BODY (RU):
133a134,140
>     
>     IF ( SDO_UTIL.IS_BUMPY_CASE(INPTABLE) ) THEN
>       MDSYS.MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>         'Bumpy-case "inptable" name is not supported');
>       RETURN;
>     END IF;
> 
MDSYS.SDO_TPIDX - PACKAGE BODY (RU):
1c1
< PACKAGE BODY       sdo_tpidx AS
---
> PACKAGE BODY sdo_tpidx AS
3,4c3,4
< INVALID_TG_LAYER_ID       exception;
< INVALID_TG_LAYER_GTYPE    exception;
---
> INVALID_TG_LAYER_ID       EXCEPTION;
> INVALID_TG_LAYER_GTYPE    EXCEPTION;
6,33c6,27
<  FUNCTION Index_Update (ia sys.odciindexinfo, rid varchar2,
<                         oldval mdsys.sdo_topo_geometry,
<                         newval mdsys.sdo_topo_geometry,
<                         env sys.ODCIEnv) return number is
<     retval number;
<     stmt varchar2(1000);
<     upd_stmt varchar2(1000);
<     cnt NUMBER;
<     topology varchar2(130);
<     topology_in varchar2(130);
<     type        cursor_type is REF CURSOR;
<     query_crs   cursor_type ;
<     p_tgl_id    number;
<     layer_level number;
<     stmt_n     varchar2(200);
<     stmt_e     varchar2(200);
<     stmt_f     varchar2(200);
<     id         number;
<     WS         varchar2(130);
<     isVersioned number;
<    begin
<      /* In the relation table, copy over the old values to the new
<         topo_geometry if there are records.
<         1. Delete for the old tg_id those records that are set with a 'D'
<            for the new tg_id.
<         2. Delete the records with a 'D' for the new tg_id.
<         2. Copy the rows from the old tg_id to the new tg_id.
<       */
---
>  FUNCTION INDEX_UPDATE (IA SYS.ODCIINDEXINFO, RID VARCHAR2,
>                         OLDVAL MDSYS.SDO_TOPO_GEOMETRY,
>                         NEWVAL MDSYS.SDO_TOPO_GEOMETRY,
>                         ENV SYS.ODCIENV) RETURN NUMBER IS
>     RETVAL NUMBER;
>     STMT VARCHAR2(1000);
>     UPD_STMT VARCHAR2(1000);
>     CNT NUMBER;
>     TOPOLOGY VARCHAR2(130);
>     TOPOLOGY_IN VARCHAR2(130);
>     TYPE        CURSOR_TYPE IS REF CURSOR;
>     QUERY_CRS   CURSOR_TYPE ;
>     P_TGL_ID    NUMBER;
>     LAYER_LEVEL NUMBER;
>     STMT_N     VARCHAR2(200);
>     STMT_E     VARCHAR2(200);
>     STMT_F     VARCHAR2(200);
>     ID         NUMBER;
>     WS         VARCHAR2(130);
>     ISVERSIONED NUMBER;
>    BEGIN
>      
35,36c29,36
<      IF ( (newval is NOT NULL) AND (oldval is not NULL) ) THEN
<       stmt := ' SELECT distinct topology from mdsys.user_sdo_topo_metadata ' ||
---
> 
> 
> 
> 
> 
> 
>      IF ( (NEWVAL IS NOT NULL) AND (OLDVAL IS NOT NULL) ) THEN
>       STMT := ' SELECT distinct topology from mdsys.user_sdo_topo_metadata ' ||
38c38,44
<        EXECUTE IMMEDIATE stmt into topology_in USING newval.topology_id;
---
>        EXECUTE IMMEDIATE STMT INTO TOPOLOGY_IN USING NEWVAL.TOPOLOGY_ID;
> 
>       TOPOLOGY := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TOPOLOGY_IN);
>       ISVERSIONED := SDO_TPIDX.ISVERSIONED(TOPOLOGY);
>      
>       
> 
40,41d45
<       topology := SYS.DBMS_ASSERT.qualified_sql_name(topology_in);
<       isVersioned := sdo_tpidx.isversioned(topology);
43,47d46
<       /* first cleanup the higher level layers so that they point to the
<          new tg_id in the relation$ table.
<           for each parent layer with current layer as the child layer
<             update the relation$
<        */
49c48,49
<        stmt := ' select TG_LAYER_ID from mdsys.user_sdo_topo_metadata '||
---
> 
>        STMT := ' select TG_LAYER_ID from mdsys.user_sdo_topo_metadata '||
51,52c51,52
<        OPEN query_crs FOR stmt using newval.topology_id,
<                                 abs(newval.tg_layer_id);
---
>        OPEN QUERY_CRS FOR STMT USING NEWVAL.TOPOLOGY_ID,
>                                 ABS(NEWVAL.TG_LAYER_ID);
55,57c55,57
<            FETCH query_crs INTO p_tgl_id;
<            EXIT when query_crs%NOTFOUND ;
<             upd_stmt := ' update '||topology||'_RELATION$ ' ||
---
>            FETCH QUERY_CRS INTO P_TGL_ID;
>            EXIT WHEN QUERY_CRS%NOTFOUND ;
>             UPD_STMT := ' update '||TOPOLOGY||'_RELATION$ ' ||
61,62c61,62
<             EXECUTE immediate upd_stmt
<                      USING newval.tg_id, p_tgl_id, oldval.tg_id;
---
>             EXECUTE IMMEDIATE UPD_STMT 
>                      USING NEWVAL.TG_ID, P_TGL_ID, OLDVAL.TG_ID;
65c65,66
<        CLOSE query_crs ;
---
>        CLOSE QUERY_CRS ;
> 
66a68
>        
68,70c70
<        /* lock the old rows from the primitive tables, if the tg_layer_id
<           is a leaf level layer */
<         EXECUTE IMMEDIATE
---
>         EXECUTE IMMEDIATE 
73c73
<          into layer_level using newval.topology_id,  newval.tg_layer_id;
---
>          INTO LAYER_LEVEL USING NEWVAL.TOPOLOGY_ID,  NEWVAL.TG_LAYER_ID;     
75,77c75,77
<         if ( newval.tg_layer_id < 0) then
<            layer_level := 0;
<         end if;
---
>         IF ( NEWVAL.TG_LAYER_ID < 0) THEN 
>            LAYER_LEVEL := 0;
>         END IF;
79c79
<         IF (layer_level = 0) then
---
>         IF (LAYER_LEVEL = 0) THEN
81c81
<           stmt_n := ' select topo_id from  '||topology||'_RELATION$ '||
---
>           STMT_N := ' select topo_id from  '||TOPOLOGY||'_RELATION$ '||
83,84c83,84
<                   ' and tg_layer_id = :lid ';
<           stmt_e := ' select topo_id from  '||topology||'_RELATION$ '||
---
>                   ' and tg_layer_id = :lid '; 
>           STMT_E := ' select topo_id from  '||TOPOLOGY||'_RELATION$ '||
86,87c86,87
<                   ' and tg_layer_id = :lid ';
<           stmt_f := ' select topo_id from  '||topology||'_RELATION$ '||
---
>                   ' and tg_layer_id = :lid '; 
>           STMT_F := ' select topo_id from  '||TOPOLOGY||'_RELATION$ '||
91,92c91,92
<          stmt := ' select node_id from  '||topology||'_NODE$'  ||
<                  ' where node_id in ( ' ||stmt_n|| ') for update ';
---
>          STMT := ' select node_id from  '||TOPOLOGY||'_NODE$'  ||
>                  ' where node_id in ( ' ||STMT_N|| ') for update ';
94c94
<          OPEN query_crs FOR stmt using newval.tg_id, newval.tg_layer_id;
---
>          OPEN QUERY_CRS FOR STMT USING NEWVAL.TG_ID, NEWVAL.TG_LAYER_ID; 
97,99c97,99
<               FETCH query_crs into id;
<                IF (id is not NULL AND isVersioned = 1) THEN
<                 EXECUTE IMMEDIATE 'SELECT DBMS_WM.GetWorkspace FROM SYS.DUAL ' into WS;
---
>               FETCH QUERY_CRS INTO ID;
>                IF (ID IS NOT NULL AND ISVERSIONED = 1) THEN
>                 EXECUTE IMMEDIATE 'SELECT DBMS_WM.GetWorkspace FROM SYS.DUAL ' INTO WS;
101c101
<                 EXECUTE IMMEDIATE
---
>                 EXECUTE IMMEDIATE 
103c103
<                   USING WS, topology||'_NODE$', 'node_id = '||sdo_util.number_to_char(id) ;
---
>                   USING WS, TOPOLOGY||'_NODE$', 'node_id = '||SDO_UTIL.NUMBER_TO_CHAR(ID) ; 
105,106c105,106
<                END IF;
<               EXIT when query_crs%NOTFOUND ;
---
>                END IF; 
>               EXIT WHEN QUERY_CRS%NOTFOUND ;
109c109
<          CLOSE query_crs;
---
>          CLOSE QUERY_CRS;
111,112c111,112
<          stmt := ' select edge_id from  '||topology||'_EDGE$'  ||
<                  ' where edge_id in ( ' ||stmt_e|| ') for update ';
---
>          STMT := ' select edge_id from  '||TOPOLOGY||'_EDGE$'  ||
>                  ' where edge_id in ( ' ||STMT_E|| ') for update ';
114c114
<          OPEN query_crs FOR stmt using newval.tg_id, newval.tg_layer_id;
---
>          OPEN QUERY_CRS FOR STMT USING NEWVAL.TG_ID, NEWVAL.TG_LAYER_ID; 
117,119c117,119
<               FETCH query_crs into id;
<                IF (id is not NULL AND isVersioned = 1) THEN
<                 EXECUTE IMMEDIATE 'SELECT DBMS_WM.GetWorkspace FROM SYS.DUAL ' into WS;
---
>               FETCH QUERY_CRS INTO ID;
>                IF (ID IS NOT NULL AND ISVERSIONED = 1) THEN
>                 EXECUTE IMMEDIATE 'SELECT DBMS_WM.GetWorkspace FROM SYS.DUAL ' INTO WS;
121c121
<                 EXECUTE IMMEDIATE
---
>                 EXECUTE IMMEDIATE 
123c123
<                   USING WS, topology||'_EDGE$', 'edge_id = '||sdo_util.number_to_char(id) ;
---
>                   USING WS, TOPOLOGY||'_EDGE$', 'edge_id = '||SDO_UTIL.NUMBER_TO_CHAR(ID) ; 
125,126c125,126
<                END IF;
<               EXIT when query_crs%NOTFOUND ;
---
>                END IF; 
>               EXIT WHEN QUERY_CRS%NOTFOUND ;
129c129
<          CLOSE query_crs;
---
>          CLOSE QUERY_CRS;
131,132c131,132
<          stmt := ' select face_id from  '||topology||'_FACE$'  ||
<                  ' where face_id in ( ' ||stmt_f|| ') for update ';
---
>          STMT := ' select face_id from  '||TOPOLOGY||'_FACE$'  ||
>                  ' where face_id in ( ' ||STMT_F|| ') for update ';
134c134
<          OPEN query_crs FOR stmt using newval.tg_id, newval.tg_layer_id;
---
>          OPEN QUERY_CRS FOR STMT USING NEWVAL.TG_ID, NEWVAL.TG_LAYER_ID; 
137,139c137,139
<               FETCH query_crs into id;
<                IF (id is not NULL AND isVersioned = 1) THEN
<                 EXECUTE IMMEDIATE 'SELECT DBMS_WM.GetWorkspace FROM SYS.DUAL ' into WS;
---
>               FETCH QUERY_CRS INTO ID;
>                IF (ID IS NOT NULL AND ISVERSIONED = 1) THEN
>                 EXECUTE IMMEDIATE 'SELECT DBMS_WM.GetWorkspace FROM SYS.DUAL ' INTO WS;
141c141
<                 EXECUTE IMMEDIATE
---
>                 EXECUTE IMMEDIATE 
143c143
<                  USING WS, topology||'_FACE$', 'face_id = '||sdo_util.number_to_char(id);
---
>                  USING WS, TOPOLOGY||'_FACE$', 'face_id = '||SDO_UTIL.NUMBER_TO_CHAR(ID); 
145,146c145,146
<                END IF;
<               EXIT when query_crs%NOTFOUND ;
---
>                END IF; 
>               EXIT WHEN QUERY_CRS%NOTFOUND ;
149c149,151
<          CLOSE query_crs;
---
>          CLOSE QUERY_CRS;
> 
>         END IF;
151c153
<         end if;
---
>       
153,155c155
<       /* delete rows from the old tg_id corresponding to rows set to 'D' for
<          new tg_id */
<       stmt := ' DELETE FROM '||topology||'_RELATION$ ' ||
---
>       STMT := ' DELETE FROM '||TOPOLOGY||'_RELATION$ ' ||
157c157
<               ' ( SELECT tg_layer_id, '||sdo_util.number_to_char(oldval.tg_id)||', '||
---
>               ' ( SELECT tg_layer_id, '||SDO_UTIL.NUMBER_TO_CHAR(OLDVAL.TG_ID)||', '||
161c161
<       EXECUTE IMMEDIATE stmt using newval.tg_layer_id, newval.tg_id;
---
>       EXECUTE IMMEDIATE STMT USING NEWVAL.TG_LAYER_ID, NEWVAL.TG_ID;
163,164c163,164
<       /* if there are rows to append from the old tg_id, do it here */
<       /* and do this only if the tg_id is different from the old value */
---
>       
>       
166,167c166,167
<       if (newval.tg_id <> oldval.tg_id) then
<         stmt := ' SELECT count(*) from MDSYS.SDO_TOPO_RELATION_DATA ' ||
---
>       IF (NEWVAL.TG_ID <> OLDVAL.TG_ID) THEN
>         STMT := ' SELECT count(*) from MDSYS.SDO_TOPO_RELATION_DATA ' ||
170c170
<          EXECUTE IMMEDIATE stmt into cnt using newval.TG_LAYER_ID, newval.TG_ID;
---
>          EXECUTE IMMEDIATE STMT INTO CNT USING NEWVAL.TG_LAYER_ID, NEWVAL.TG_ID;
172,174c172,174
<          IF (cnt = 1) THEN  /* we need to copy the rows from oldval to newval */
<           stmt := ' INSERT INTO '||topology||'_RELATION$ ' ||
<                   ' SELECT tg_layer_id, '||sdo_util.number_to_char(newval.tg_id)||', '||
---
>          IF (CNT = 1) THEN  
>           STMT := ' INSERT INTO '||TOPOLOGY||'_RELATION$ ' ||
>                   ' SELECT tg_layer_id, '||SDO_UTIL.NUMBER_TO_CHAR(NEWVAL.TG_ID)||', '||
176c176
<                   ' FROM '||topology||'_RELATION$ '||
---
>                   ' FROM '||TOPOLOGY||'_RELATION$ '||
178,179c178,179
<           EXECUTE IMMEDIATE stmt USING
<                      oldval.tg_layer_id, oldval.tg_id;
---
>           EXECUTE IMMEDIATE STMT USING 
>                      OLDVAL.TG_LAYER_ID, OLDVAL.TG_ID;       
181c181
<         stmt := ' SELECT count(*) from MDSYS.SDO_TOPO_RELATION_DATA ' ||
---
>         STMT := ' SELECT count(*) from MDSYS.SDO_TOPO_RELATION_DATA ' ||
183,185c183,185
<          EXECUTE IMMEDIATE stmt into cnt using newval.TG_LAYER_ID, newval.TG_ID;
<          IF (cnt = 0) THEN  /* Error: bug 4681927 */
<               mderr.raise_md_error('MD','SDO',-13122);
---
>          EXECUTE IMMEDIATE STMT INTO CNT USING NEWVAL.TG_LAYER_ID, NEWVAL.TG_ID;
>          IF (CNT = 0) THEN  
>               MDERR.RAISE_MD_ERROR('MD','SDO',-13122);
187c187
<        end if;
---
>        END IF;
189,190c189,190
<       /* now cleanup the rows with 'A' and 'D' values for the topo_attribute */
<        stmt := ' DELETE FROM MDSYS.SDO_TOPO_RELATION_DATA ' ||
---
>       
>        STMT := ' DELETE FROM MDSYS.SDO_TOPO_RELATION_DATA ' ||
193c193
<        EXECUTE IMMEDIATE stmt using newval.TG_LAYER_ID, newval.TG_ID;
---
>        EXECUTE IMMEDIATE STMT USING NEWVAL.TG_LAYER_ID, NEWVAL.TG_ID;
196,200c196,200
<      /* remove the dummy entries in MDSYS.SDO_TOPO_RELATION_DATA
<         for this special case */
<      if ( (oldval is NULL) AND (newval is not NULL) ) then
<       /* now cleanup the rows with 'A' and 'D' values for the topo_attribute */
<        stmt := ' DELETE FROM MDSYS.SDO_TOPO_RELATION_DATA ' ||
---
>      
> 
>      IF ( (OLDVAL IS NULL) AND (NEWVAL IS NOT NULL) ) THEN
>       
>        STMT := ' DELETE FROM MDSYS.SDO_TOPO_RELATION_DATA ' ||
203,204c203,215
<        EXECUTE IMMEDIATE stmt using newval.TG_LAYER_ID, newval.TG_ID;
<      end if;
---
>        EXECUTE IMMEDIATE STMT USING NEWVAL.TG_LAYER_ID, NEWVAL.TG_ID;
>      END IF;
>    
>      IF ( (NEWVAL IS NOT NULL) AND (OLDVAL IS NOT NULL) AND 
>                   (OLDVAL.TG_ID = NEWVAL.TG_ID) ) THEN
>         RETVAL := SDO_TPIDX.INDEX_DELETE(IA, NULL, OLDVAL, ENV);
>         RETVAL := SDO_TPIDX.INDEX_INSERT(IA, NULL, NEWVAL, ENV);
>      ELSE
>         RETVAL := SDO_TPIDX.INDEX_DELETE(IA, RID, OLDVAL, ENV);
>         RETVAL := SDO_TPIDX.INDEX_INSERT(IA, RID, NEWVAL, ENV);
>      END IF;
>      RETURN RETVAL;
>    END;
206,224c217,224
<      if ( (newval is not NULL) AND (oldval is not NULL) AND
<                   (oldval.tg_id = newval.tg_id) ) then
<         retval := sdo_tpidx.index_delete(ia, null, oldval, env);
<         retval := sdo_tpidx.index_insert(ia, null, newval, env);
<      else
<         retval := sdo_tpidx.index_delete(ia, rid, oldval, env);
<         retval := sdo_tpidx.index_insert(ia, rid, newval, env);
<      end if;
<      return retval;
<    end;
< 
<   -----------------------------index_insert------------------------------------
<   ---
<   --- BUGS:
<   ---   internal: 02/27/04, add the collection type dealing
<   ---
<   FUNCTION index_insert (ia sys.odciindexinfo, rid varchar2,
<                           newval mdsys.sdo_topo_geometry,
<                           env sys.ODCIEnv)
---
>   
>   
>   
>   
>   
>   FUNCTION INDEX_INSERT (IA SYS.ODCIINDEXINFO, RID VARCHAR2,
>                           NEWVAL MDSYS.SDO_TOPO_GEOMETRY,
>                           ENV SYS.ODCIENV)
226,239c226,239
<   stmt          varchar2(1000);
<   stmt1          varchar2(1000);
<   table_name    varchar2(260);
<   column_name   varchar2(130);
<   topology      varchar2(130);
<   topology_in   varchar2(130);
<   topology_id   number;
<   feature_L_id  number;
<   feature_type  number;
<   feature_id    number;
<   idx_columns   SYS.ODCIColInfoList;
<   cnt           number;
<   layer_gtype   varchar2(32);
<   idx_tab       varchar2(260);
---
>   STMT          VARCHAR2(1000);
>   STMT1          VARCHAR2(1000);
>   TABLE_NAME    VARCHAR2(260);
>   COLUMN_NAME   VARCHAR2(130);
>   TOPOLOGY      VARCHAR2(130);
>   TOPOLOGY_IN   VARCHAR2(130);
>   TOPOLOGY_ID   NUMBER;
>   FEATURE_L_ID  NUMBER;
>   FEATURE_TYPE  NUMBER;
>   FEATURE_ID    NUMBER;
>   IDX_COLUMNS   SYS.ODCICOLINFOLIST;
>   CNT           NUMBER;
>   LAYER_GTYPE   VARCHAR2(32);
>   IDX_TAB       VARCHAR2(260);
242,243c242,243
<     IF (newval is NULL) THEN
<       return SYS.ODCIConst.Success;
---
>     IF (NEWVAL IS NULL) THEN
>       RETURN SYS.ODCICONST.SUCCESS;
246,252c246,252
<     idx_columns := ia.IndexCols;
<     table_name := idx_columns(1).TableName;
<     column_name := idx_columns(1).ColName;
<     column_name := REPLACE(column_name, '"');
<     topology_id := newval.topology_id;
<     feature_L_id := newval.tg_layer_id;
<     feature_id := newval.tg_id;
---
>     IDX_COLUMNS := IA.INDEXCOLS;
>     TABLE_NAME := IDX_COLUMNS(1).TABLENAME;
>     COLUMN_NAME := IDX_COLUMNS(1).COLNAME;
>     COLUMN_NAME := REPLACE(COLUMN_NAME, '"');
>     TOPOLOGY_ID := NEWVAL.TOPOLOGY_ID;
>     FEATURE_L_ID := NEWVAL.TG_LAYER_ID;
>     FEATURE_ID := NEWVAL.TG_ID;
255,257c255,257
<       IF (feature_L_id IS NULL) THEN
<         mderr.raise_md_error('MD', 'SDO', -13113);
<         RETURN SYS.ODCIConst.Error;
---
>       IF (FEATURE_L_ID IS NULL) THEN
>         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13113);
>         RETURN SYS.ODCICONST.ERROR;
260,261c260,261
<       -- check the layer_id consistency
<       topology_in := NULL;
---
>       
>       TOPOLOGY_IN := NULL;
263c263
<       stmt := 'select topology from mdsys.user_sdo_topo_info where owner = :owner ' ||
---
>       STMT := 'select topology from mdsys.user_sdo_topo_info where owner = :owner ' ||
267,269c267,269
<         EXECUTE IMMEDIATE stmt INTO topology_in
<           USING ia.IndexSchema, topology_id,table_name,
<                 column_name, abs(feature_L_id);
---
>         EXECUTE IMMEDIATE STMT INTO TOPOLOGY_IN
>           USING IA.INDEXSCHEMA, TOPOLOGY_ID,TABLE_NAME,
>                 COLUMN_NAME, ABS(FEATURE_L_ID);
272,273c272,273
<         mderr.raise_md_error('MD', 'SDO', -13113);
<         RETURN SYS.ODCIConst.Error;
---
>         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13113);
>         RETURN SYS.ODCICONST.ERROR;
276,279c276,279
< 
<       IF (topology_in IS NULL) THEN
<         mderr.raise_md_error('MD', 'SDO', -13261, stmt);
<         raise INVALID_TG_LAYER_ID;
---
>  
>       IF (TOPOLOGY_IN IS NULL) THEN
>         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13261, STMT);
>         RAISE INVALID_TG_LAYER_ID;
281,285c281,285
< 
<       topology := SYS.DBMS_ASSERT.qualified_sql_name(topology_in);
< 
<       -- check the feature type consistency
<       stmt := ' select SDO_LAYER_GTYPE from mdsys.all_sdo_index_metadata ' ||
---
>    
>       TOPOLOGY := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TOPOLOGY_IN);
>  
>       
>       STMT := ' select SDO_LAYER_GTYPE from mdsys.all_sdo_index_metadata ' ||
287c287
<       EXECUTE IMMEDIATE stmt INTO layer_gtype USING ia.IndexSchema, ia.IndexName;
---
>       EXECUTE IMMEDIATE STMT INTO LAYER_GTYPE USING IA.INDEXSCHEMA, IA.INDEXNAME;
289,292c289,292
<       IF (layer_gtype = 'POLYGON' ) THEN
<         IF (newval.tg_type <> 3) THEN
<           -- rollback if there is an error
<           stmt := 'delete from '||topology||'_relation$ where  ' ||
---
>       IF (LAYER_GTYPE = 'POLYGON' ) THEN
>         IF (NEWVAL.TG_TYPE <> 3) THEN
>           
>           STMT := 'delete from '||TOPOLOGY||'_relation$ where  ' ||
294,295c294,295
<           EXECUTE IMMEDIATE stmt USING feature_L_id,  feature_id;
<           raise INVALID_TG_LAYER_GTYPE;
---
>           EXECUTE IMMEDIATE STMT USING FEATURE_L_ID,  FEATURE_ID;
>           RAISE INVALID_TG_LAYER_GTYPE;
297,300c297,300
<       ELSIF  (layer_gtype = 'LINE'  OR layer_gtype = 'CURVE' ) THEN
<         IF (newval.tg_type <> 2) THEN
<           -- rollback if there is an error
<           stmt := 'delete from '||topology||'_relation$ where  ' ||
---
>       ELSIF  (LAYER_GTYPE = 'LINE'  OR LAYER_GTYPE = 'CURVE' ) THEN
>         IF (NEWVAL.TG_TYPE <> 2) THEN
>           
>           STMT := 'delete from '||TOPOLOGY||'_relation$ where  ' ||
302,303c302,303
<           EXECUTE IMMEDIATE stmt USING feature_L_id,  feature_id;
<          raise INVALID_TG_LAYER_GTYPE;
---
>           EXECUTE IMMEDIATE STMT USING FEATURE_L_ID,  FEATURE_ID;
>          RAISE INVALID_TG_LAYER_GTYPE;
305,308c305,308
<       ELSIF (layer_gtype = 'POINT' ) THEN
<         IF (newval.tg_type <> 1) THEN
<           -- rollback if there is an error
<           stmt := 'delete from '||topology||'_relation$ where  ' ||
---
>       ELSIF (LAYER_GTYPE = 'POINT' ) THEN
>         IF (NEWVAL.TG_TYPE <> 1) THEN
>           
>           STMT := 'delete from '||TOPOLOGY||'_relation$ where  ' ||
310,311c310,311
<           EXECUTE IMMEDIATE stmt USING feature_L_id,  feature_id;
<           raise INVALID_TG_LAYER_GTYPE;
---
>           EXECUTE IMMEDIATE STMT USING FEATURE_L_ID,  FEATURE_ID;
>           RAISE INVALID_TG_LAYER_GTYPE;
313,316c313,316
<       ELSIF (layer_gtype = 'COLLECTION') THEN
<         IF ((newval.tg_type < 1) OR
<             (newval.tg_type > 4)) THEN
<           stmt := 'delete from '||topology||'_relation$ where  ' ||
---
>       ELSIF (LAYER_GTYPE = 'COLLECTION') THEN
>         IF ((NEWVAL.TG_TYPE < 1) OR
>             (NEWVAL.TG_TYPE > 4)) THEN
>           STMT := 'delete from '||TOPOLOGY||'_relation$ where  ' ||
318,320c318,320
<           EXECUTE IMMEDIATE stmt USING feature_L_id,  feature_id;
<           raise INVALID_TG_LAYER_GTYPE;
<         END IF;
---
>           EXECUTE IMMEDIATE STMT USING FEATURE_L_ID,  FEATURE_ID;
>           RAISE INVALID_TG_LAYER_GTYPE;
>         END IF; 
321a322,325
>    
>       
>       
> 
323,324c327
<       /* insert into the relation$ table */
<       stmt := ' INSERT INTO '||topology||'_RELATION$ '||
---
>       STMT := ' INSERT INTO '||TOPOLOGY||'_RELATION$ '||
326,327c329,330
<               ' WHERE A.tg_layer_id =  :flid and A.tg_id = :fid ';
<       EXECUTE immediate stmt USING feature_L_id, feature_id;
---
>               ' WHERE A.tg_layer_id =  :flid and A.tg_id = :fid and A.TOPO_TYPE>0 ';
>       EXECUTE IMMEDIATE STMT USING FEATURE_L_ID, FEATURE_ID;
329,332c332,335
<        -- PARTITION OR NON PARTITION CASE
<        IF (ia.IndexPartition IS NULL ) THEN
<          -- insert the rowid, feature id into the index table
<          stmt := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
---
>        
>        IF (IA.INDEXPARTITION IS NULL ) THEN
>          
>          STMT := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
334c337
<          EXECUTE IMMEDIATE stmt into idx_tab using ia.IndexSchema, ia.IndexName;
---
>          EXECUTE IMMEDIATE STMT INTO IDX_TAB USING IA.INDEXSCHEMA, IA.INDEXNAME;
336,337c339,340
<          -- insert the rowid, feature id into the index table
<          stmt := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
---
>          
>          STMT := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
341,342c344,345
<          EXECUTE IMMEDIATE stmt INTO idx_tab USING
<            ia.IndexSchema, ia.IndexName, ia.IndexPartition;
---
>          EXECUTE IMMEDIATE STMT INTO IDX_TAB USING
>            IA.INDEXSCHEMA, IA.INDEXNAME, IA.INDEXPARTITION;
346,351c349,354
<        -- insert into the index table
<        /* do this only if rid is not NULL */
<        IF (rid is not NULL) THEN
<          idx_tab := ia.IndexSchema||'.'||idx_tab;
<          stmt := ' INSERT INTO ' ||
<                  SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(idx_tab) ||
---
>        
>        
>        IF (RID IS NOT NULL) THEN
>          IDX_TAB := IA.INDEXSCHEMA||'.'||IDX_TAB;
>          STMT := ' INSERT INTO ' ||
>                  SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(IDX_TAB) || 
353c356
<          EXECUTE IMMEDIATE stmt USING feature_id, rid;
---
>          EXECUTE IMMEDIATE STMT USING FEATURE_ID, RID;
356c359
<        stmt := ' DELETE  from MDSYS.SDO_TOPO_RELATION_DATA A ' ||
---
>        STMT := ' DELETE  from MDSYS.SDO_TOPO_RELATION_DATA A ' ||
358c361
<        EXECUTE immediate stmt USING feature_L_id, feature_id;
---
>        EXECUTE IMMEDIATE STMT USING FEATURE_L_ID, FEATURE_ID;
362,364c365,367
<       dbms_output.put_line(sdo_util.number_to_char(feature_L_id));
<       mderr.raise_md_error('MD', 'SDO', -13121, SYS.DBMS_ASSERT.noop(stmt));
<       RETURN SYS.ODCIConst.Error;
---
>       DBMS_OUTPUT.PUT_LINE(SDO_UTIL.NUMBER_TO_CHAR(FEATURE_L_ID));
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13121, STMT);
>       RETURN SYS.ODCICONST.ERROR;
368,371c371,374
<       stmt1 := sdo_util.number_to_char(cnt) || '::'||ia.IndexSchema||'::'||topology||
<               '::'||table_name||'::'||column_name;
<       mderr.raise_md_error('MD', 'SDO', -13113, SYS.DBMS_ASSERT.noop(stmt1));
<       RETURN SYS.ODCIConst.Error;
---
>       STMT1 := SDO_UTIL.NUMBER_TO_CHAR(CNT) || '::'||IA.INDEXSCHEMA||'::'||TOPOLOGY||
>               '::'||TABLE_NAME||'::'||COLUMN_NAME;
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13113, STMT1);
>       RETURN SYS.ODCICONST.ERROR;
374c377
<     RETURN SYS.ODCIConst.Success;
---
>     RETURN SYS.ODCICONST.SUCCESS;
377,379c380,382
<   FUNCTION index_delete (ia sys.odciindexinfo, rid varchar2,
<                          oldval mdsys.sdo_topo_geometry,
<                          env sys.ODCIEnv)
---
>   FUNCTION INDEX_DELETE (IA SYS.ODCIINDEXINFO, RID VARCHAR2,
>                          OLDVAL MDSYS.SDO_TOPO_GEOMETRY,
>                          ENV SYS.ODCIENV)
381,406c384,409
<   stmt          varchar2(1000);
<   q_stmt        varchar2(1000);
<   topology      varchar2(21);
<   topology_in   varchar2(21);
<   topology_id   number;
<   feature_L_id  number;
<   feature_id    number;
<   idx_tab       varchar2(260);
<   type        cursor_type is REF CURSOR;
<   query_crs   cursor_type ;
<   p_tgl_id    number;
<   cnt         number;
<   layer_level number;
<   id          number;
<   stmt_n      varchar2(200);
<   stmt_e      varchar2(200);
<   stmt_f      varchar2(200);
<   WS          varchar2(130);
<   old_sp    varchar2(128);
<   old_ws     varchar2(128);
<   parent_sp varchar2(128) ;
<   parent_ws varchar2(128) ;
<   isVersioned number;
<   idx_columns   SYS.ODCIColInfoList;
<   table_name varchar2(130);
<   ver_status  varchar2(10);
---
>   STMT          VARCHAR2(1000);
>   Q_STMT        VARCHAR2(1000);
>   TOPOLOGY      VARCHAR2(21);
>   TOPOLOGY_IN   VARCHAR2(21);
>   TOPOLOGY_ID   NUMBER;
>   FEATURE_L_ID  NUMBER;
>   FEATURE_ID    NUMBER;
>   IDX_TAB       VARCHAR2(260);
>   TYPE        CURSOR_TYPE IS REF CURSOR;
>   QUERY_CRS   CURSOR_TYPE ;
>   P_TGL_ID    NUMBER;
>   CNT         NUMBER;
>   LAYER_LEVEL NUMBER;
>   ID          NUMBER;
>   STMT_N      VARCHAR2(200);
>   STMT_E      VARCHAR2(200);
>   STMT_F      VARCHAR2(200);
>   WS          VARCHAR2(130);
>   OLD_SP    VARCHAR2(128);
>   OLD_WS     VARCHAR2(128);
>   PARENT_SP VARCHAR2(128) ;
>   PARENT_WS VARCHAR2(128) ;
>   ISVERSIONED NUMBER;
>   IDX_COLUMNS   SYS.ODCICOLINFOLIST;
>   TABLE_NAME VARCHAR2(130);
>   VER_STATUS  VARCHAR2(10);
410,411c413,414
<     IF (oldval IS NULL) THEN
<         RETURN SYS.ODCIConst.Success;
---
>     IF (OLDVAL IS NULL) THEN
>         RETURN SYS.ODCICONST.SUCCESS;
414,416c417,419
<     topology_id := oldval.topology_id;
<     feature_L_id := oldval.tg_layer_id;
<     feature_id := oldval.tg_id;
---
>     TOPOLOGY_ID := OLDVAL.TOPOLOGY_ID;
>     FEATURE_L_ID := OLDVAL.TG_LAYER_ID;
>     FEATURE_ID := OLDVAL.TG_ID;
418c421
<     stmt := ' select topology from mdsys.user_sdo_topo_info where ' ||
---
>     STMT := ' select topology from mdsys.user_sdo_topo_info where ' ||
420c423,424
<     EXECUTE IMMEDIATE stmt INTO topology_in USING topology_id, abs(feature_L_id);
---
>     EXECUTE IMMEDIATE STMT INTO TOPOLOGY_IN USING TOPOLOGY_ID, ABS(FEATURE_L_ID);
> 
421a426,427
>     TOPOLOGY := SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TOPOLOGY_IN);
>     
423,426c429
<     topology := SYS.DBMS_ASSERT.qualified_sql_name(topology_in);
<     /* lock the old rows from the primitive tables, if the tg_layer_id
<        is a leaf level layer */
<     EXECUTE IMMEDIATE
---
>     EXECUTE IMMEDIATE 
429c432
<     INTO layer_level USING topology_id,  feature_l_id;
---
>     INTO LAYER_LEVEL USING TOPOLOGY_ID,  FEATURE_L_ID;     
431,432c434,435
<     IF ( feature_l_id < 0) THEN
<        layer_level := 0;
---
>     IF ( FEATURE_L_ID < 0) THEN
>        LAYER_LEVEL := 0;
435c438
<     IF (layer_level = 0) THEN
---
>     IF (LAYER_LEVEL = 0) THEN
437c440
<       stmt_n := ' select topo_id from  '||topology||'_RELATION$ '||
---
>       STMT_N := ' select topo_id from  '||TOPOLOGY||'_RELATION$ '||
439c442
<                 ' and tg_layer_id = :lid ';
---
>                 ' and tg_layer_id = :lid '; 
441c444
<       stmt_e := ' select abs(topo_id) from  '||topology||'_RELATION$ '||
---
>       STMT_E := ' select abs(topo_id) from  '||TOPOLOGY||'_RELATION$ '||
443c446
<                 ' and tg_layer_id = :lid ';
---
>                 ' and tg_layer_id = :lid '; 
445c448
<       stmt_f := ' select topo_id from  '||topology||'_RELATION$ '||
---
>       STMT_F := ' select topo_id from  '||TOPOLOGY||'_RELATION$ '||
449,450c452,453
<       stmt := ' select node_id from  '||topology||'_NODE$'  ||
<               ' where node_id in ( ' ||stmt_n|| ') for update ';
---
>       STMT := ' select node_id from  '||TOPOLOGY||'_NODE$'  ||
>               ' where node_id in ( ' ||STMT_N|| ') for update ';
452c455
<       OPEN query_crs FOR stmt USING feature_id, feature_l_id;
---
>       OPEN QUERY_CRS FOR STMT USING FEATURE_ID, FEATURE_L_ID; 
455,456c458,459
<           FETCH query_crs INTO id;
<           EXIT when query_crs%NOTFOUND ;
---
>           FETCH QUERY_CRS INTO ID;
>           EXIT WHEN QUERY_CRS%NOTFOUND ;
459c462
<       CLOSE query_crs;
---
>       CLOSE QUERY_CRS;
461,462c464,465
<       stmt := ' select edge_id from  '||topology||'_EDGE$'  ||
<               ' where edge_id in ( ' ||stmt_e|| ') for update ';
---
>       STMT := ' select edge_id from  '||TOPOLOGY||'_EDGE$'  ||
>               ' where edge_id in ( ' ||STMT_E|| ') for update ';
464c467
<       OPEN query_crs FOR stmt USING feature_id, feature_l_id;
---
>       OPEN QUERY_CRS FOR STMT USING FEATURE_ID, FEATURE_L_ID; 
467,468c470,471
<           FETCH query_crs INTO id;
<           EXIT when query_crs%NOTFOUND ;
---
>           FETCH QUERY_CRS INTO ID;
>           EXIT WHEN QUERY_CRS%NOTFOUND ;
471c474
<       CLOSE query_crs;
---
>       CLOSE QUERY_CRS;
473,474c476,477
<       stmt := ' select face_id from  '||topology||'_FACE$'  ||
<               ' where face_id in ( ' ||stmt_f|| ') for update ';
---
>       STMT := ' select face_id from  '||TOPOLOGY||'_FACE$'  ||
>               ' where face_id in ( ' ||STMT_F|| ') for update ';
476c479
<       OPEN query_crs FOR stmt USING feature_id, feature_l_id;
---
>       OPEN QUERY_CRS FOR STMT USING FEATURE_ID, FEATURE_L_ID; 
479,480c482,483
<           FETCH query_crs INTO id;
<           EXIT when query_crs%NOTFOUND ;
---
>           FETCH QUERY_CRS INTO ID;
>           EXIT WHEN QUERY_CRS%NOTFOUND ;
483c486
<       CLOSE query_crs;
---
>       CLOSE QUERY_CRS;
487,496c490,499
<     -- delete from the <>_Relation$ table the rows for feature
<     -- do  this only if this is not a row migration case
<     IF ( ( (bitand( env.EnvFlags, SYS.ODCIConst.RowMigration)
<               = SYS.ODCIConst.RowMigration) AND
<            (bitand( env.EnvFlags, SYS.ODCIConst.IndexKeyChanged)
<               =  SYS.ODCIConst.IndexKeyChanged) ) OR
<          (bitand( env.EnvFlags, SYS.ODCIConst.RowMigration)
<               <> SYS.ODCIConst.RowMigration) ) THEN
<       IF (rid is not NULL) THEN
<         stmt := 'delete from '||topology||'_relation$ where  ' ||
---
>     
>     
>     IF ( ( (BITAND( ENV.ENVFLAGS, SYS.ODCICONST.ROWMIGRATION) 
>               = SYS.ODCICONST.ROWMIGRATION) AND
>            (BITAND( ENV.ENVFLAGS, SYS.ODCICONST.INDEXKEYCHANGED) 
>               =  SYS.ODCICONST.INDEXKEYCHANGED) ) OR
>          (BITAND( ENV.ENVFLAGS, SYS.ODCICONST.ROWMIGRATION)
>               <> SYS.ODCICONST.ROWMIGRATION) ) THEN
>       IF (RID IS NOT NULL) THEN
>         STMT := 'delete from '||TOPOLOGY||'_relation$ where  ' ||
498c501
<         EXECUTE IMMEDIATE stmt USING feature_L_id,  feature_id;
---
>         EXECUTE IMMEDIATE STMT USING FEATURE_L_ID,  FEATURE_ID;
502,505c505,508
<     -- PARTITION OR NON PARTITION CASE
<     IF (ia.IndexPartition IS NULL ) THEN
<       -- insert the rowid, feature id into the index table
<       stmt := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
---
>     
>     IF (IA.INDEXPARTITION IS NULL ) THEN
>       
>       STMT := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
508c511
<       EXECUTE IMMEDIATE stmt INTO idx_tab USING ia.IndexSchema, ia.IndexName;
---
>       EXECUTE IMMEDIATE STMT INTO IDX_TAB USING IA.INDEXSCHEMA, IA.INDEXNAME;
510c513
<       stmt := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
---
>       STMT := 'select SDO_INDEX_TABLE from mdsys.all_sdo_index_metadata ' ||
514,515c517,518
<       EXECUTE IMMEDIATE stmt INTO idx_tab USING
<         ia.IndexSchema, ia.IndexName, ia.IndexPartition;
---
>       EXECUTE IMMEDIATE STMT INTO IDX_TAB USING
>         IA.INDEXSCHEMA, IA.INDEXNAME, IA.INDEXPARTITION;
518,528c521
<     /* see if this tg_is is referred to by any other layer in the relation
<        table for each parent layer that has this layer as the child layer
<        count the rows in relation tables pointing to this tg_id
<        if count > 0 then this violates the hierarchical constraint */
<     -- do  this only if this is not a row migration case
<     IF ( ( (bitand( env.EnvFlags, SYS.ODCIConst.RowMigration)
<               = SYS.ODCIConst.RowMigration) AND
<            (bitand( env.EnvFlags, SYS.ODCIConst.IndexKeyChanged)
<               = SYS.ODCIConst.IndexKeyChanged) ) OR
<          (bitand( env.EnvFlags, SYS.ODCIConst.RowMigration)
<               <> SYS.ODCIConst.RowMigration) ) THEN
---
>     
530,531c523,534
<       IF (rid IS NOT NULL) THEN
<         EXECUTE IMMEDIATE
---
> 
> 
>     
>     IF ( ( (BITAND( ENV.ENVFLAGS, SYS.ODCICONST.ROWMIGRATION)
>               = SYS.ODCICONST.ROWMIGRATION) AND
>            (BITAND( ENV.ENVFLAGS, SYS.ODCICONST.INDEXKEYCHANGED)
>               = SYS.ODCICONST.INDEXKEYCHANGED) ) OR
>          (BITAND( ENV.ENVFLAGS, SYS.ODCICONST.ROWMIGRATION)
>               <> SYS.ODCICONST.ROWMIGRATION) ) THEN
> 
>       IF (RID IS NOT NULL) THEN
>         EXECUTE IMMEDIATE 
533,534c536,537
<           '(a '||topology||'_REL_LID$ ) */   count(*) ' ||
<           'from mdsys.user_sdo_topo_info b, ' || topology || '_RELATION$ a ' ||
---
>           '(a '||TOPOLOGY||'_REL_LID$ ) */   count(*) ' ||
>           'from mdsys.user_sdo_topo_info b, ' || TOPOLOGY || '_RELATION$ a ' ||
539,541c542,544
<         INTO cnt USING oldval.topology_id, abs(oldval.tg_layer_id), oldval.tg_id;
< 
<         IF (cnt > 0)  THEN
---
>         INTO CNT USING OLDVAL.TOPOLOGY_ID, ABS(OLDVAL.TG_LAYER_ID), OLDVAL.TG_ID; 
>         
>         IF (CNT > 0)  THEN 
543,549c546,552
<             /* this is hierarchical case */
<             /* setup the variables for WM check  bug 9206217*/
<             isVersioned := 0;
<             ver_status := NULL;
<             idx_columns := ia.IndexCols;
<             table_name := idx_columns(1).TableName;
<             table_name := substr(table_name, 1, length(table_name)-3);
---
>             
>             
>             ISVERSIONED := 0;
>             VER_STATUS := NULL;
>             IDX_COLUMNS := IA.INDEXCOLS;
>             TABLE_NAME := IDX_COLUMNS(1).TABLENAME;
>             TABLE_NAME := SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME)-3);
554,555c557,558
<             INTO isVersioned
<             USING idx_columns(1).tableschema, table_name;
---
>             INTO ISVERSIONED
>             USING IDX_COLUMNS(1).TABLESCHEMA, TABLE_NAME;
557c560
<             IF (isVersioned > 0)  THEN
---
>             IF (ISVERSIONED > 0)  THEN
562c565
<                 INTO ver_status USING idx_columns(1).tableschema, table_name;
---
>                 INTO VER_STATUS USING IDX_COLUMNS(1).TABLESCHEMA, TABLE_NAME;
564,565c567,568
<                 /* need more checks if this is version enabled topology */
<                 EXECUTE IMMEDIATE
---
>                 
>                 EXECUTE IMMEDIATE 
568c571
<                 INTO old_sp;
---
>                 INTO OLD_SP;
569a573,575
>                 EXECUTE IMMEDIATE 
>                   'select wmsys.lt.getworkspace from SYS.DUAL' INTO OLD_WS;
>        
571,574c577
<                   'select wmsys.lt.getworkspace from SYS.DUAL' INTO old_ws;
< 
<                 EXECUTE IMMEDIATE
<                   'select parent_workspace, parent_savepoint' ||
---
>                   'select parent_workspace, parent_savepoint' || 
576,577c579,580
<                   ' where workspace = dbms_wm.getworkspace '
<                 INTO parent_ws, parent_sp;
---
>                   ' where workspace = dbms_wm.getworkspace ' 
>                 INTO PARENT_WS, PARENT_SP;
579c582
<                 IF (parent_sp IS NOT NULL) THEN
---
>                 IF (PARENT_SP IS NOT NULL) THEN
583c586
<                   USING parent_ws, parent_sp;
---
>                   USING PARENT_WS, PARENT_SP;
586,587c589,590
<                 cnt := -1;
<                 EXECUTE IMMEDIATE 'select count(*) from ' || topology ||
---
>                 CNT := -1;
>                 EXECUTE IMMEDIATE 'select count(*) from ' || TOPOLOGY ||
589c592
<                 INTO cnt USING abs(feature_L_id), feature_id;
---
>                 INTO CNT USING ABS(FEATURE_L_ID), FEATURE_ID;
593,595c596,598
<                 USING  old_ws;
< 
<                 IF (old_sp <> 'LATEST') THEN
---
>                 USING  OLD_WS;
>        
>                 IF (OLD_SP <> 'LATEST') THEN
598c601
<                   USING  old_sp;
---
>                   USING  OLD_SP;
601,602c604,605
<                 IF ( (cnt = 0) AND (ver_status <> 'DV') ) THEN
<                   mderr.raise_md_error('MD', 'SDO', -13199,
---
>                 IF ( (CNT = 0) AND (VER_STATUS <> 'DV') ) THEN
>                   MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
604c607
<                   RETURN SYS.ODCIConst.Error;
---
>                   RETURN SYS.ODCICONST.ERROR;
608,609c611,612
<               BEGIN
<                 mderr.raise_md_error('MD', 'SDO', -13199,
---
>               BEGIN 
>                 MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
611c614
<                 RETURN SYS.ODCIConst.Error;
---
>                 RETURN SYS.ODCICONST.ERROR;
613c616
<             END IF;  /* isVersioned */
---
>             END IF;  
615,616c618,619
<         END IF;  /* cnt > 0 */
<       END IF;  /* RID is not NULL */
---
>         END IF;  
>       END IF;  
619,622c622,625
<     -- delete from the index table
<     IF (rid is not NULL) THEN
<       idx_tab := ia.IndexSchema||'.'||idx_tab;
<       stmt := 'DELETE '|| SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(idx_tab) ||
---
>     
>     IF (RID IS NOT NULL) THEN
>       IDX_TAB := IA.INDEXSCHEMA||'.'||IDX_TAB;
>       STMT := 'DELETE '|| SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(IDX_TAB) || 
625c628
<       EXECUTE IMMEDIATE stmt USING feature_id, rid;
---
>       EXECUTE IMMEDIATE STMT USING FEATURE_ID, RID;
628c631
<     RETURN SYS.ODCIConst.Success;
---
>     RETURN SYS.ODCICONST.SUCCESS;
631,636c634,639
<   FUNCTION isversioned(topology IN VARCHAR2) return integer IS
<     topo_name varchar2(130);
<     owner varchar2(130);
<     stmt varchar2(200);
<     versionedTopology integer;
<     owmInstalled integer;
---
>   FUNCTION ISVERSIONED(TOPOLOGY IN VARCHAR2) RETURN INTEGER IS
>     TOPO_NAME VARCHAR2(130);
>     OWNER VARCHAR2(130);
>     STMT VARCHAR2(200);
>     VERSIONEDTOPOLOGY INTEGER;
>     OWMINSTALLED INTEGER;
638,640c641,643
<     mdsys.SDO_TOPO_METADATA.extract_topo_owner(
<       nls_upper(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(topology)), owner,topo_name);
<     versionedTopology := 0;
---
>     MDSYS.SDO_TOPO_METADATA.EXTRACT_TOPO_OWNER(
>       NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TOPOLOGY)), OWNER,TOPO_NAME);
>     VERSIONEDTOPOLOGY := 0;
642c645
<     SELECT MDSYS.SDO_OWM_INSTALLED INTO owmInstalled FROM SYS.DUAL;
---
>     SELECT MDSYS.SDO_OWM_INSTALLED INTO OWMINSTALLED FROM SYS.DUAL;
644,645c647,648
<     IF ( owmInstalled > 0 ) THEN
<       stmt := '  select count(*) ' ||
---
>     IF ( OWMINSTALLED > 0 ) THEN
>       STMT := '  select count(*) ' ||
648,649c651,652
<       EXECUTE IMMEDIATE stmt INTO versionedTopology
<         USING owner, SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(topo_name) || '_NODE$';
---
>       EXECUTE IMMEDIATE STMT INTO VERSIONEDTOPOLOGY
>         USING OWNER, SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(TOPO_NAME) || '_NODE$';
652c655
<     RETURN versionedTopology;
---
>     RETURN VERSIONEDTOPOLOGY;
655,656c658
< END sdo_tpidx;
< 
---
> END SDO_TPIDX;
MDSYS.SDO_TRKR - PACKAGE BODY (RU):
12c12
<     PARAMETERS (
---
>     PARAMETERS(
29c29
<     PARAMETERS (
---
>     PARAMETERS(
35,36c35,36
<   FUNCTION OTLOCINREGION(LONGITUDE IN NUMBER, 
<                          LATITUDE IN NUMBER, 
---
>   FUNCTION OTLOCINREGION(LONGITUDE IN NUMBER,
>                          LATITUDE IN NUMBER,
44c44
<     PARAMETERS (
---
>     PARAMETERS(
58c58
<                               NUM_LOC_QUEUES IN INTEGER); 
---
>                               NUM_LOC_QUEUES IN INTEGER);
82,89c82,102
<   PROCEDURE LOG_MSG (LOG_TABLE IN VARCHAR2,
<                       MSG_LVL  IN VARCHAR2,
<                       MSG      IN VARCHAR2)
<   AS
<     STMT VARCHAR2(1000); 
<   BEGIN   
<     STMT := 'INSERT INTO ' || LOG_TABLE || 'VALUES (:1, :2, :3)';
<     EXECUTE IMMEDIATE STMT USING MSG_LVL, MSG, CURRENT_TIMESTAMP();
---
>   PROCEDURE LOG_MSG(LOG_TABLE IN VARCHAR2,
>                     MSG_LVL   IN VARCHAR2,
>                     MSG       IN VARCHAR2)
>   AS
>     STMT VARCHAR2(1000);
>   BEGIN
>     STMT := 'INSERT INTO ' || LOG_TABLE ||
>             ' VALUES(:1, :2, :3)';
> 
>     BEGIN
>       EXECUTE IMMEDIATE STMT USING MSG_LVL, MSG, CURRENT_TIMESTAMP();
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')1]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           RAISE;
>     END;
93c106,107
<   PROCEDURE LOG_DEBUG(TRACKING_SET_NAME IN VARCHAR2, MSG IN VARCHAR2)
---
>   PROCEDURE LOG_DEBUG(TRACKING_SET_NAME IN VARCHAR2,
>                       MSG IN VARCHAR2)
97c111,116
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
102c121,122
<   PROCEDURE LOG_ERROR(LOG_TABLE IN VARCHAR2, MSG IN VARCHAR2)
---
>   PROCEDURE LOG_ERROR(LOG_TABLE IN VARCHAR2,
>                       MSG IN VARCHAR2)
108c128,129
<   PROCEDURE LOG_INFO(LOG_TABLE IN VARCHAR2, MSG IN VARCHAR2)
---
>   PROCEDURE LOG_INFO(LOG_TABLE IN VARCHAR2,
>                      MSG IN VARCHAR2)
113c134
<    
---
> 
119c140
<   PROCEDURE PERFORM_PREPROCESSING(TRACKING_SET_NAME IN VARCHAR2, 
---
>   PROCEDURE PERFORM_PREPROCESSING(TRACKING_SET_NAME IN VARCHAR2,
126c147
<     TABLE_NAME_NA VARCHAR2(128);       
---
>     TABLE_NAME_NA VARCHAR2(128);     
136a158,159
>     QUEUE_ALREADY_EXISTS EXCEPTION;
>     PRAGMA EXCEPTION_INIT(QUEUE_ALREADY_EXISTS, -24006);
138c161,166
<     TABLE_NAME := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     TABLE_NAME :=
145,152c173,188
<       EXECUTE IMMEDIATE STMT; 
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         SYS.DBMS_SYSTEM.KSDWRT(
<           SYS.DBMS_SYSTEM.TRACE_FILE,
<           'EXCEPTION[sdo_trkr(' || STMT || ')]: ' || SQLERRM); 
<         RAISE;
---
>       EXECUTE IMMEDIATE STMT;
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN QUEUE_ALREADY_EXISTS THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')2]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           RAISE;
154,157c190,195
<     
<     BEGIN  
<       STMT := 'CREATE TABLE ' || TABLE_NAME || 
<               '(message_level varchar2(1), message varchar2(512), ts TIMESTAMP WITH TIME ZONE)';
---
> 
>     BEGIN
>       STMT := 'CREATE TABLE ' || TABLE_NAME || '(' ||
>               'message_level varchar2(1), ' ||
>               'message varchar2(512), ' ||
>               'ts TIMESTAMP WITH TIME ZONE)';
159,164c197,205
<     EXCEPTION
<       WHEN OTHERS THEN
<         SYS.DBMS_SYSTEM.KSDWRT(
<           SYS.DBMS_SYSTEM.TRACE_FILE,
<           'EXCEPTION[sdo_trkr(' || STMT || ')]: ' || SQLERRM); 
<         RAISE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')3]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           RAISE;
168c209
<        
---
> 
173,178c214,227
<       EXECUTE IMMEDIATE STMT; 
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
>       EXECUTE IMMEDIATE STMT;
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')4]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
180,183c229,237
<     
<     BEGIN  
<       STMT := 'CREATE TABLE ' || TABLE_NAME || 
<                 '(object_id NUMBER, region_id NUMBER, time TIMESTAMP, x NUMBER, y NUMBER, state VARCHAR2(8))';
---
> 
>     BEGIN
>       STMT := 'CREATE TABLE ' || TABLE_NAME || '(' ||
>                 'object_id NUMBER, ' ||
>                 'region_id NUMBER, ' ||
>                 'time TIMESTAMP, ' ||
>                 'x NUMBER, ' ||
>                 'y NUMBER, ' ||
>                 'state VARCHAR2(8))';
185,189c239,250
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')5]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
> 
>           LOG_ERROR(LOG_TABLE,
>             'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
196,200c257,270
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')6]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
> 
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
204,205c274,277
<       STMT := 'CREATE TABLE '|| TABLE_NAME || '(object_id NUMBER,' || 
<               ' time TIMESTAMP, trajectory MDSYS.SDO_GEOMETRY)';
---
>       STMT := 'CREATE TABLE '|| TABLE_NAME || '(' ||
>               'object_id NUMBER, ' ||
>               'time TIMESTAMP, ' ||
>               'trajectory MDSYS.SDO_GEOMETRY)';
207,211c279,290
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')7]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
> 
>           LOG_ERROR(LOG_TABLE,
>             'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
214c293
<     TABLE_NAME := 
---
>     TABLE_NAME :=
219,223c298,311
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')8]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
> 
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
226c314
<     CONSTRAINT_NAME := 
---
>     CONSTRAINT_NAME :=
230,232c318,321
<       STMT := 'CREATE TABLE ' || TABLE_NAME ||
<                 '(region_id NUMBER, geometry MDSYS.SDO_GEOMETRY, CONSTRAINT ' ||
<                 CONSTRAINT_NAME || ' PRIMARY KEY(region_id))';
---
>       STMT := 'CREATE TABLE ' || TABLE_NAME || '(' ||
>                 'region_id NUMBER, ' ||
>                 'geometry MDSYS.SDO_GEOMETRY, ' ||
>                 'CONSTRAINT ' || CONSTRAINT_NAME || ' PRIMARY KEY(region_id))';
234,238c323,333
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')9]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE,
>             'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
241c336
<     TABLE_NAME_NA := 
---
>     TABLE_NAME_NA :=
246,255c341,356
<       STMT := 'DELETE FROM mdsys.user_sdo_geom_metadata WHERE ' 
<                || 'table_name = NLS_UPPER(:1)';
<      EXECUTE IMMEDIATE STMT USING TABLE_NAME_NA;
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'DELETE FROM user_sdo_geom_metadata: ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
<     END;    
<   
---
>       STMT := 'DELETE FROM mdsys.user_sdo_geom_metadata ' ||
>               'WHERE table_name = NLS_UPPER(:1)';
>       EXECUTE IMMEDIATE STMT USING TABLE_NAME_NA;
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')10]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE,
>             'DELETE FROM user_sdo_geom_metadata: ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
>     END;
> 
258,259c359,360
<                  MDSYS.SDO_DIM_ELEMENT('X', -180, 180, 0.5), 
<                  MDSYS.SDO_DIM_ELEMENT('Y', -90, 90, 0.5));    
---
>                  MDSYS.SDO_DIM_ELEMENT('X', -180, 180, 0.5),
>                  MDSYS.SDO_DIM_ELEMENT('Y', -90, 90, 0.5));
265c366,367
<       STMT := 'INSERT INTO MDSYS.USER_SDO_GEOM_METADATA VALUES (:1, :2, :3, :4)';
---
>       STMT := 'INSERT INTO MDSYS.USER_SDO_GEOM_METADATA ' ||
>               'VALUES(:1, :2, :3, :4)';
267,272c369,380
<         NLS_UPPER(COLUMN_NAME), DIMINFO, SRID;
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'INSERT INTO user_sdo_geom_metadata: ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
>         COLUMN_NAME, DIMINFO, SRID;
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')11]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE,
>             'INSERT INTO user_sdo_geom_metadata: ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
274c382
<     
---
> 
279,283c387,398
<     EXCEPTION
<       WHEN INDEX_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
<                                'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')6]: ' || SQLERRM); RAISE;
---
> 
>       EXCEPTION
>         WHEN INDEX_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>                                  'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')12]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           RAISE;
287,288c402,404
<       STMT := 'CREATE INDEX ' || IDX_NAME || ' ON ' || TABLE_NAME ||
<               '(geometry) indextype is mdsys.spatial_index_v2';
---
>       STMT := 'CREATE INDEX ' || IDX_NAME || ' ' ||
>               'ON ' || TABLE_NAME || '(geometry) ' ||
>               'indextype is mdsys.spatial_index_v2';
290,294c406,416
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'CREATE INDEX ' || IDX_NAME ||': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')13]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE,
>             'CREATE INDEX ' || IDX_NAME ||': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
301,305c423,435
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')14]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
309c439
<       CONSTRAINT_NAME := 
---
>       CONSTRAINT_NAME :=
312,314c442,447
<       STMT := 'CREATE TABLE ' || TABLE_NAME || '(object_id NUMBER, ' || 
<               ' region_id  NUMBER, queue_no NUMBER, alert_when VARCHAR2(2), CONSTRAINT ' ||
<               CONSTRAINT_NAME || ' PRIMARY KEY(object_id, region_id))';
---
>       STMT := 'CREATE TABLE ' || TABLE_NAME || '(' ||
>               'object_id NUMBER, ' ||
>               'region_id  NUMBER, ' ||
>               'queue_no NUMBER, ' ||
>               'alert_when VARCHAR2(2), ' ||
>               'CONSTRAINT ' || CONSTRAINT_NAME || ' PRIMARY KEY(object_id, region_id))';
316,320c449,459
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')15]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE,
>             'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
323c462
<     TABLE_NAME := 
---
>     TABLE_NAME :=
328,332c467,479
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')16]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
336,337c483,485
<       STMT := 'CREATE TABLE ' || TABLE_NAME || 
<                 '(num_loc_queues NUMBER, num_trkr_queues NUMBER)';
---
>       STMT := 'CREATE TABLE ' || TABLE_NAME || '(' ||
>               'num_loc_queues NUMBER, ' ||
>               'num_trkr_queues NUMBER)';
339c487,489
<       STMT := 'INSERT INTO ' || TABLE_NAME || ' VALUES(:1, :2)';
---
> 
>       STMT := 'INSERT INTO ' || TABLE_NAME ||
>               ' VALUES(:1, :2)';
342,346c492,502
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 
<           'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')17]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE,
>             'CREATE TABLE ' || TABLE_NAME || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
351c507
<     IF (ERROR_FLG) THEN 
---
>     IF (ERROR_FLG) THEN
354,355c510,511
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<        'Errors found in sdo_trkr.create_tracking_set: preprocessing');
---
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Errors found in sdo_trkr.perform_preprocessing: preprocessing');
369c525,530
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
378,382c539,551
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')18]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
390,394c559,571
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')19]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
402,406c579,591
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')20]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
414,418c599,611
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')21]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
420c613
<     
---
> 
426,430c619,631
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')22]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
438,442c639,651
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN NULL;
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           NULL;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')23]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           LOG_ERROR(LOG_TABLE, STMT || ': ' || SUBSTR(SQLERRM, 1, 256));
>           ERROR_FLG := TRUE;
446,447c655,656
<     IF (ERROR_FLG) THEN 
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>     IF (ERROR_FLG) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
451c660
<   
---
> 
463c672,677
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
469c683
<       TQ_NAME := 
---
>       TQ_NAME :=
471,473d684
<       PQ_NAME := 
<         SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_proc_q_' || I);
< 
474a686,688
> 
>       PQ_NAME :=
>         SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_proc_q_' || I);
482c696
<       LQ_NAME := 
---
>       LQ_NAME :=
484d697
< 
490c703
<     NQ_NAME := 
---
>     NQ_NAME :=
494,497d706
<   EXCEPTION
<     WHEN OTHERS THEN
<       LOG_ERROR(LOG_TABLE, 'Start queues: ' || SUBSTR(SQLERRM, 1, 256));
<       STOP_QUEUES(TRACKING_SET_NAME, NUM_TRKR_QUEUES, NUM_LOC_QUEUES);
499,500c708,717
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<        'Errors found in sdo_trkr.start_tracking_set: start queues');
---
>     EXCEPTION
>       WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')24]: ' || SQLERRM);
> 
>         LOG_ERROR(LOG_TABLE, 'Start queues: ' || SUBSTR(SQLERRM, 1, 256));
>         STOP_QUEUES(TRACKING_SET_NAME, NUM_TRKR_QUEUES, NUM_LOC_QUEUES);
> 
>         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>           'Errors found in sdo_trkr.start_tracking_set: start queues');
511a729,730
>     QUEUE_EXISTS EXCEPTION;
>     PRAGMA       EXCEPTION_INIT(QUEUE_EXISTS, -24001);
513c732,737
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
520c744
<     
---
> 
523c747
<       T_QT := 
---
>       T_QT :=
525c749
<       P_QT := 
---
>       P_QT :=
533c757
<   
---
> 
547c771
<     
---
> 
553c777
<     N_QT := 
---
>     N_QT :=
562a787,789
>     WHEN QUEUE_EXISTS THEN
>       NULL;
> 
563a791,793
>       SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>         'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')25]: ' || SQLERRM);
> 
567c797
<       PERFORM_POSTPROCESSING(TRACKING_SET_NAME); 
---
>       PERFORM_POSTPROCESSING(TRACKING_SET_NAME);
569,570c799,800
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<        'Errors found in sdo_trkr.create_tracking_set: create queue tables');
---
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Errors found in sdo_trkr.create_queue_tables: create queue tables');
585a816,817
>     QUEUE_ALREADY_EXISTS EXCEPTION;
>     PRAGMA EXCEPTION_INIT(QUEUE_ALREADY_EXISTS, -24006);
587c819,824
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
595c832
<       T_Q := 
---
>       T_Q :=
638a876,878
>     WHEN QUEUE_ALREADY_EXISTS THEN
>       NULL;
> 
639a880,882
>       SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>         'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')26]: ' || SQLERRM);
> 
643c886
<       PERFORM_POSTPROCESSING(TRACKING_SET_NAME); 
---
>       PERFORM_POSTPROCESSING(TRACKING_SET_NAME);
645c888
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
658c901
<     N_Q         VARCHAR2(130);    
---
>     N_Q         VARCHAR2(130);
660c903,908
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
662c910
<     
---
> 
675,678c923,929
<     EXCEPTION
<       WHEN OTHERS THEN 
<         LOG_ERROR(LOG_TABLE, 'Error dropping tracker and process queues');
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')27]: ' || SQLERRM);
>           LOG_ERROR(LOG_TABLE, 'Error dropping tracker and process queues');
>           ERROR_FLG := TRUE;
690,693c941,947
<     EXCEPTION
<       WHEN OTHERS THEN 
<         LOG_ERROR(LOG_TABLE, 'Error dropping location queues');
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')28]: ' || SQLERRM);
>           LOG_ERROR(LOG_TABLE, 'Error dropping location queues');
>           ERROR_FLG := TRUE;
698c952
<     BEGIN 
---
>     BEGIN
702,705c956,962
<     EXCEPTION
<       WHEN OTHERS THEN 
<         LOG_ERROR(LOG_TABLE, 'Error dropping notification queue');
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')29]: ' || SQLERRM);
>           LOG_ERROR(LOG_TABLE, 'Error dropping notification queue');
>           ERROR_FLG := TRUE;
709,710c966,967
<     IF (ERROR_FLG) THEN 
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>     IF (ERROR_FLG) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
726c983,988
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
728c990
<     
---
> 
740,743c1002,1008
<     EXCEPTION
<       WHEN OTHERS THEN
<         LOG_ERROR(LOG_TABLE, 'Error dropping tracker and process queue tables');
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')30]: ' || SQLERRM);
>           LOG_ERROR(LOG_TABLE, 'Error dropping tracker and process queue tables');
>           ERROR_FLG := TRUE;
755,758c1020,1026
<     EXCEPTION
<       WHEN OTHERS THEN 
<         LOG_ERROR(LOG_TABLE, 'Error dropping location queue tables');
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')31]: ' || SQLERRM);
>           LOG_ERROR(LOG_TABLE, 'Error dropping location queue tables');
>           ERROR_FLG := TRUE;
768,771c1036,1042
<     EXCEPTION
<       WHEN OTHERS THEN 
<         LOG_ERROR(LOG_TABLE, 'Error dropping notification queue table');
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')32]: ' || SQLERRM);
>           LOG_ERROR(LOG_TABLE, 'Error dropping notification queue table');
>           ERROR_FLG := TRUE;
775,776c1046,1047
<     IF (ERROR_FLG) THEN 
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>     IF (ERROR_FLG) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
791c1062,1067
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
798a1075,1076
>       DBMS_AQADM.STOP_QUEUE(QUEUE_NAME => T_Q, WAIT => TRUE);
> 
801,802d1078
< 
<       DBMS_AQADM.STOP_QUEUE(QUEUE_NAME => T_Q, WAIT => TRUE);
846a1123,1127
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
862,863c1143,1144
<       IF (PAYLOAD.ARR(I).ALERT_WHEN LIKE 'T%') THEN 
<         TABLE_NAME := 
---
>       IF (PAYLOAD.ARR(I).ALERT_WHEN LIKE 'T%') THEN
>         TABLE_NAME :=
866,867c1147,1153
<         STMT := 'SELECT /*+ RESULT_CACHE */ alert_when FROM ' || TABLE_NAME || 
<                 ' WHERE object_id=:1 AND region_id=:2';
---
>         STMT := 'SELECT /*+ RESULT_CACHE */ alert_when ' ||
>                 'FROM ' || TABLE_NAME || ' ' ||
>                 'WHERE object_id = :1 AND region_id = :2';
> 
>         BEGIN
>           EXECUTE IMMEDIATE STMT INTO ALERT
>             USING PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID;
869,870c1155,1165
<         EXECUTE IMMEDIATE STMT INTO ALERT 
<           USING PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID;
---
>           EXCEPTION
>             WHEN NO_DATA_FOUND THEN
>               ALERT := NULL;
> 
>             WHEN OTHERS THEN
>               SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>                 'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')33]: ' || SQLERRM);
>               SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>                 'EXCEPTION[' || STMT || ']');
>               RAISE;
>        END;
873,875c1168,1172
<         IF ((ISINSIDE) AND (ALERT !='TO')) THEN
<           STMT := 'UPDATE ' || TABLE_NAME || ' SET alert_when=' || '''TO''' ||
<                   ' WHERE object_id=:1 AND region_id=:2';
---
>         IF ((ISINSIDE) AND (ALERT != 'TO')) THEN
>           STMT := 'UPDATE ' || TABLE_NAME ||
>                   ' SET alert_when = ' || '''TO''' ||
>                   ' WHERE object_id = :1 ' ||
>                   'AND region_id = :2';
877c1174,1175
<           EXECUTE IMMEDIATE STMT USING PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID;
---
>           EXECUTE IMMEDIATE STMT
>             USING PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID;
879,881c1177,1181
<         ELSIF ((NOT ISINSIDE) AND (ALERT !='TI')) THEN
<           STMT := 'UPDATE ' || TABLE_NAME || ' SET alert_when=' || '''TI''' ||
<                   ' WHERE object_id=:1 AND region_id=:2';
---
>         ELSIF ((NOT ISINSIDE) AND (ALERT != 'TI')) THEN
>           STMT := 'UPDATE ' || TABLE_NAME ||
>                   ' SET alert_when = ' || '''TI''' ||
>                   ' WHERE object_id = :1 ' ||
>                   'AND region_id = :2';
883c1183,1184
<           EXECUTE IMMEDIATE STMT USING PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID;
---
>           EXECUTE IMMEDIATE STMT
>             USING PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID;
893c1194
<       ELSE 
---
>       ELSE
898c1199
<         PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID, PAYLOAD.ARR(I).TIME, 
---
>         PAYLOAD.ARR(I).OBJECT_ID, PAYLOAD.ARR(I).REGION_ID, PAYLOAD.ARR(I).TIME,
908,913c1209,1218
<   EXCEPTION 
<     WHEN TIMEOUT_OR_EOF THEN NULL;
<     WHEN OTHERS THEN
<       LOG_TABLE := 
<         SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
<       LOG_ERROR(LOG_TABLE, 'Error processing process messages: '|| SUBSTR(SQLERRM, 1, 256));
---
> 
>     EXCEPTION
>       WHEN TIMEOUT_OR_EOF THEN
>         NULL;
>       WHEN OTHERS THEN
>         SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>           'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')34]: ' || SQLERRM);
>         LOG_TABLE :=
>           SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
>         LOG_ERROR(LOG_TABLE, 'Error processing process messages: '|| SUBSTR(SQLERRM, 1, 256));
932a1238
>     STMT            VARCHAR2(1000);
934c1240
<     STMTG           VARCHAR2(1000); 
---
>     STMTG           VARCHAR2(1000);
942c1248
<     T_Q             VARCHAR2(130);      
---
>     T_Q             VARCHAR2(130);
950a1257
>     JOB_NAME        VARCHAR2(130);
951a1259,1265
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     JOB_NAME :=
>       SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_TRACKING_REGIONS');
953,954c1267,1268
<        SYS_CONTEXT('USERENV', 'CURRENT_USER'), 
<        (TRACKING_SET_NAME || '_TRACKING_REGIONS'), 
---
>        SYS_CONTEXT('USERENV', 'CURRENT_USER'),
>        JOB_NAME,
960c1274
<  
---
> 
963,964c1277,1278
<  
<     TABLE_NAME_R := 
---
> 
>     TABLE_NAME_R :=
968,972c1282,1287
<     STMTD := 
<       'SELECT region_id, geometry FROM ' || TABLE_NAME_R || ' ' ||
<       'WHERE region_id IN '|| 
<         '(SELECT DISTINCT region_id FROM ' || TABLE_NAME ||
<         ' WHERE queue_no='|| SYS.DBMS_ASSERT.ENQUOTE_LITERAL(QNO) || ')';
---
>     STMTD := 'SELECT region_id, geometry ' ||
>              'FROM ' || TABLE_NAME_R || ' ' ||
>              'WHERE region_id IN '||
>                '(SELECT DISTINCT region_id ' ||
>                ' FROM ' || TABLE_NAME ||
>                ' WHERE queue_no = '|| SYS.DBMS_ASSERT.ENQUOTE_LITERAL(QNO) || ')';
975c1290
<     LOOP 
---
>     LOOP
984,985c1299,1302
<     STMTG := 'SELECT geometry FROM ' || TABLE_NAME_R || ' WHERE region_id = :1';
<                 
---
>     STMTG := 'SELECT geometry ' ||
>              'FROM ' || TABLE_NAME_R || ' ' ||
>              'WHERE region_id = :1';
> 
987,988c1304,1307
<     STMTC := ' SELECT COUNT(*) FROM ' || TABLE_NAME || 
<              ' WHERE object_id =:1 AND region_id=:2';
---
>     STMTC := 'SELECT COUNT(*) ' ||
>              'FROM ' || TABLE_NAME || ' ' ||
>              'WHERE object_id = :1 ' ||
>              'AND region_id = :2';
991c1310,1312
<     STMTD := 'DELETE FROM ' || TABLE_NAME || ' WHERE object_id=:1 AND region_id=:2';
---
>     STMTD := 'DELETE FROM ' || TABLE_NAME || ' ' ||
>              'WHERE object_id = :1 ' ||
>              'AND region_id = :2';
994c1315,1316
<     STMTI := 'INSERT INTO ' || TABLE_NAME || ' VALUES(:1, :2, :3, :4)';
---
>     STMTI := 'INSERT INTO ' || TABLE_NAME || ' ' ||
>              'VALUES(:1, :2, :3, :4)';
997,998c1319,1322
<     STMTU := 'UPDATE  ' || TABLE_NAME || 
<              ' SET alert_when=:1 WHERE object_id=:2 AND region_id=:3';
---
>     STMTU := 'UPDATE ' || TABLE_NAME || ' ' ||
>              'SET alert_when = :1 ' ||
>              'WHERE object_id = :2 ' ||
>              'AND region_id = :3';
1008c1332
<     P_Q := 
---
>     P_Q :=
1046c1370
<           
---
> 
1049c1373
<         END IF; 
---
>         END IF;
1067c1391
<           EXECUTE IMMEDIATE STMTI 
---
>           EXECUTE IMMEDIATE STMTI
1073c1397
<           EXECUTE IMMEDIATE STMTU  
---
>           EXECUTE IMMEDIATE STMTU
1091,1098d1414
<   EXCEPTION
<     WHEN OTHERS THEN
<       BEGIN
<         LOG_TABLE := 
<           SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
<         
<         LOG_ERROR(LOG_TABLE, 
<           'tracker/process dequeue: ' || SUBSTR(SQLERRM, 1, 256));
1100,1111c1416,1437
<         OPEN R_CURSOR FOR 
<           'SELECT region_id FROM ' ||
<             SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker') ||
<           ' WHERE queue_no=' || SYS.DBMS_ASSERT.ENQUOTE_LITERAL(QNO);
< 
<         LOOP 
<           FETCH R_CURSOR INTO RID;
<           EXIT WHEN R_CURSOR%NOTFOUND;
<           SDO_TRKR.OTUNLOADINMEMREGIONS(RID);
<         END LOOP;
<         CLOSE R_CURSOR;
<       END;
---
>     EXCEPTION
>       WHEN OTHERS THEN
>         BEGIN
>           LOG_TABLE :=
>             SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
> 
>           LOG_ERROR(LOG_TABLE,
>             'tracker/process dequeue: ' || SUBSTR(SQLERRM, 1, 256));
> 
>           STMT := 'SELECT region_id ' ||
>                   'FROM ' ||
>               SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker') ||
>                   ' WHERE queue_no=' || SYS.DBMS_ASSERT.ENQUOTE_LITERAL(QNO);
>           OPEN R_CURSOR FOR STMT;
>           LOOP
>             FETCH R_CURSOR INTO RID;
>             EXIT WHEN R_CURSOR%NOTFOUND;
> 
>             SDO_TRKR.OTUNLOADINMEMREGIONS(RID);
>           END LOOP;
>           CLOSE R_CURSOR;
>         END;
1121,1122c1447,1448
<     PAYLOAD_LOC     LOCATION_MSG_PKD;
<     MSG             LOCATION_MSG;
---
>     PAYLOAD_LOC     MDSYS.LOCATION_MSG_PKD;
>     MSG             MDSYS.LOCATION_MSG;
1127a1454
>     STMT            VARCHAR2(1000);
1138a1466
>     JOB_NAME        VARCHAR2(130);
1139a1468,1474
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     JOB_NAME :=
>       SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_TRACKING_REGIONS');
1141,1142c1476,1477
<       SYS_CONTEXT('USERENV', 'CURRENT_USER'), 
<       (TRACKING_SET_NAME || '_TRACKING_REGIONS'), 
---
>       SYS_CONTEXT('USERENV', 'CURRENT_USER'),
>       JOB_NAME,
1149c1484
<     TABLE1_NAME := 
---
>     TABLE1_NAME :=
1157c1492
<     L_Q := 
---
>     L_Q :=
1186,1191c1521,1526
<           OPEN R_CURSOR FOR 
<             'SELECT tr.region_id, t.queue_no, t.alert_when ' ||
<             'FROM ' || TABLE1_NAME || ' tr, ' || TABLE2_NAME || ' t ' ||
<             'WHERE t.object_id = ' || SYS.DBMS_ASSERT.ENQUOTE_LITERAL(OUT_REC.OBJECT_ID) || 
<             ' AND t.region_id=tr.region_id';
<             
---
>           STMT := 'SELECT tr.region_id, t.queue_no, t.alert_when ' ||
>                   'FROM ' || TABLE1_NAME || ' tr, ' || TABLE2_NAME || ' t ' ||
>                   'WHERE t.object_id = ' ||
>                   SYS.DBMS_ASSERT.ENQUOTE_LITERAL(OUT_REC.OBJECT_ID) ||
>                   ' AND t.region_id = tr.region_id';
>           OPEN R_CURSOR FOR STMT;
1206c1541
<         IF ((ARR(I).ARR.COUNT) > 0) THEN 
---
>         IF ((ARR(I).ARR.COUNT) > 0) THEN
1220,1224d1554
<   EXCEPTION
<     WHEN OTHERS THEN
<       BEGIN
<         LOG_TABLE := 
<           SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
1226,1228c1556,1566
<         LOG_ERROR(LOG_TABLE, 
<           'location dequeue: ' || SUBSTR(SQLERRM, 1, 256));
<       END;
---
>     EXCEPTION
>       WHEN OTHERS THEN
>         BEGIN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')35]: ' || SQLERRM);
>           LOG_TABLE :=
>             SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
> 
>           LOG_ERROR(LOG_TABLE,
>             'location dequeue: ' || SUBSTR(SQLERRM, 1, 256));
>         END;
1237c1575,1580
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
1248c1591
<                                  || TRACKING_SET_NAME ||  ''',' || I || 
---
>                                  || TRACKING_SET_NAME ||  ''',' || I ||
1251c1594
<         COMMENTS             => 'Listening and dequeuing tracking 
---
>         COMMENTS             => 'Listening and dequeuing tracking
1260a1604,1606
>       SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>         'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')36]: ' || SQLERRM);
> 
1264c1610
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
1275c1621,1626
<     LOG_TABLE := 
---
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     LOG_TABLE :=
1285,1286c1636,1637
<         JOB_ACTION           => 'begin sdo_trkr.run_loc_deq(''' 
<                                  || TRACKING_SET_NAME || ''',' || I || 
---
>         JOB_ACTION           => 'begin sdo_trkr.run_loc_deq('''
>                                  || TRACKING_SET_NAME || ''',' || I ||
1289a1641
> 
1295,1298d1646
<   EXCEPTION
<     WHEN OTHERS THEN
<       LOG_ERROR(LOG_TABLE, 'Start location jobs: ' || SUBSTR(SQLERRM, 1, 256));
<       STOP_LOC_JOBS(TRACKING_SET_NAME, NUM_LOC_QUEUES);
1300,1301c1648,1657
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<        'Errors found in sdo_trkr.start_tracking_set: start location jobs');
---
>     EXCEPTION
>       WHEN OTHERS THEN
>         SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>           'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')37]: ' || SQLERRM);
> 
>         LOG_ERROR(LOG_TABLE, 'Start location jobs: ' || SUBSTR(SQLERRM, 1, 256));
>         STOP_LOC_JOBS(TRACKING_SET_NAME, NUM_LOC_QUEUES);
> 
>         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>          'Errors found in sdo_trkr.start_tracking_set: start location jobs');
1310a1667,1671
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1323,1326c1684,1692
<         EXCEPTION
<           WHEN JOB_NOT_RUNNING THEN NULL;
<           WHEN OTHERS THEN
<             RAISE;
---
> 
>           EXCEPTION
>             WHEN JOB_NOT_RUNNING THEN
>               NULL;
> 
>             WHEN OTHERS THEN
>               SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>                 'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')38]: ' || SQLERRM);
>               RAISE;
1332,1333c1698,1703
<       EXCEPTION
<         WHEN OTHERS THEN NULL;
---
> 
>         EXCEPTION
>           WHEN OTHERS THEN
>             SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>               'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')39]: ' || SQLERRM);
>             NULL;
1341a1712,1713
>     JOB_NAME            VARCHAR2(128);
>     FULL_NAME           VARCHAR2(260);
1344a1717,1721
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1348c1725,1728
<       BEGIN 
---
>       JOB_NAME := SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_loc_job_' || I);
>       FULL_NAME := USER || '.' || JOB_NAME;
> 
>       BEGIN
1351c1731
<           NAME  => USER || '.' || TRACKING_SET_NAME || '_loc_job_' || I);
---
>           NAME  => FULL_NAME);
1356,1360c1736,1745
<           JOB_NAME => USER || '.' || TRACKING_SET_NAME || '_loc_job_' || I);
<         EXCEPTION
<           WHEN JOB_NOT_RUNNING THEN NULL;
<           WHEN OTHERS THEN
<             RAISE;
---
>           JOB_NAME => FULL_NAME);
> 
>           EXCEPTION
>             WHEN JOB_NOT_RUNNING THEN
>               NULL;
> 
>             WHEN OTHERS THEN
>               SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>                 'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')40]: ' || SQLERRM);
>               RAISE;
1365,1367c1750,1756
<           JOB_NAME => USER|| '.' || TRACKING_SET_NAME || '_loc_job_'|| I);
<       EXCEPTION
<         WHEN OTHERS THEN NULL;
---
>           JOB_NAME => FULL_NAME);
> 
>         EXCEPTION
>           WHEN OTHERS THEN
>             SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>               'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')41]: ' || SQLERRM);
>             NULL;
1377a1767,1770
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
1380,1381c1773,1774
<      MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<       ' Exceeded maximum allowed number of Tracker queues: 1000'); 
---
>      MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>       ' Exceeded maximum allowed number of Tracker queues: 1000');
1385,1386c1778,1779
<      MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<       ' Exceeded maximum allowed number of Location queues: 100'); 
---
>      MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>       ' Exceeded maximum allowed number of Location queues: 100');
1388,1389c1781,1782
<   
<    LOG_TABLE := 
---
> 
>    LOG_TABLE :=
1395a1789
> 
1396a1791
> 
1397a1793
> 
1413a1810,1814
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1416c1817
<    BEGIN 
---
>    BEGIN
1417a1819,1832
> 
>      EXCEPTION
>        WHEN TABLE_NOT_FOUND THEN
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Invalid tracking set name: ' || TRACKING_SET_NAME);
> 
>        WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')42]: ' || SQLERRM);
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>            'sdo_trkr.start_tracking_set: fetching queue counts');
>    END;
> 
>    BEGIN
1419,1425c1834,1844
<    EXCEPTION
<      WHEN TABLE_NOT_FOUND THEN
<        MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Invalid tracking set name: ' || TRACKING_SET_NAME); 
<      WHEN OTHERS THEN
<        MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<          'sdo_trkr.start_tracking_set: fetching queue counts');
---
> 
>      EXCEPTION
>        WHEN TABLE_NOT_FOUND THEN
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Invalid tracking set name: ' || TRACKING_SET_NAME);
> 
>        WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')43]: ' || SQLERRM);
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>            'sdo_trkr.start_tracking_set: fetching queue counts');
1428c1847
<    LOG_TABLE := 
---
>    LOG_TABLE :=
1433c1852
<      'WHERE job_name LIKE ' ||
---
>            'WHERE job_name LIKE ' ||
1435,1436c1854,1855
<    EXECUTE IMMEDIATE STMT INTO CNT; 
<   
---
>    EXECUTE IMMEDIATE STMT INTO CNT;
> 
1438c1857
<    IF (CNT > 0) THEN 
---
>    IF (CNT > 0) THEN
1444c1863
<      
---
> 
1450c1869
<      BEGIN 
---
>      BEGIN
1452,1457c1871,1880
<      EXCEPTION
<        WHEN OTHERS THEN  
<          
<          
<          STOP_TRKR_JOBS(TRACKING_SET_NAME, NUM_TRKR_QUEUES);
<          START_TRKR_JOBS(TRACKING_SET_NAME, NUM_TRKR_QUEUES);
---
> 
>        EXCEPTION
>          WHEN OTHERS THEN
>            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>              'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')44]: ' || SQLERRM);
> 
>            
>            
>            STOP_TRKR_JOBS(TRACKING_SET_NAME, NUM_TRKR_QUEUES);
>            START_TRKR_JOBS(TRACKING_SET_NAME, NUM_TRKR_QUEUES);
1460c1883
<      BEGIN 
---
>      BEGIN
1462,1467c1885,1894
<      EXCEPTION
<                                WHEN OTHERS THEN
<          
<          
<          STOP_LOC_JOBS(TRACKING_SET_NAME, NUM_LOC_QUEUES);
<          START_LOC_JOBS(TRACKING_SET_NAME, NUM_LOC_QUEUES, NUM_TRKR_QUEUES);
---
> 
>        EXCEPTION
>          WHEN OTHERS THEN
>            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>              'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')45]: ' || SQLERRM);
> 
>            
>            
>            STOP_LOC_JOBS(TRACKING_SET_NAME, NUM_LOC_QUEUES);
>            START_LOC_JOBS(TRACKING_SET_NAME, NUM_LOC_QUEUES, NUM_TRKR_QUEUES);
1485a1913,1917
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1488c1920
<    BEGIN 
---
>    BEGIN
1489a1922,1934
> 
>      EXCEPTION
>        WHEN TABLE_NOT_FOUND THEN
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Invalid tracking set name: ' || TRACKING_SET_NAME);
>        WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')46]: ' || SQLERRM);
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>            'Errors found in sdo_trkr.stop_tracking_set: fetching queue counts');
>    END;
> 
>    BEGIN
1491,1497c1936,1945
<    EXCEPTION
<      WHEN TABLE_NOT_FOUND THEN
<        MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Invalid tracking set name: ' || TRACKING_SET_NAME); 
<      WHEN OTHERS THEN
<        MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<          'Errors found in sdo_trkr.stop_tracking_set: fetching queue counts');
---
> 
>      EXCEPTION
>        WHEN TABLE_NOT_FOUND THEN
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Invalid tracking set name: ' || TRACKING_SET_NAME);
>        WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')47]: ' || SQLERRM);
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>            'Errors found in sdo_trkr.stop_tracking_set: fetching queue counts');
1500c1948
<    LOG_TABLE := 
---
>    LOG_TABLE :=
1506,1507c1954,1959
<    EXCEPTION
<      WHEN OTHERS THEN NULL;
---
> 
>      EXCEPTION
>        WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')48]: ' || SQLERRM);
>          NULL;
1512,1513c1964,1967
<    EXCEPTION
<      WHEN OTHERS THEN NULL;
---
> 
>      EXCEPTION
>        WHEN OTHERS THEN
>          NULL;
1516c1970
<    BEGIN 
---
>    BEGIN
1518,1523c1972,1981
<    EXCEPTION
<      WHEN OTHERS THEN
<        LOG_TABLE := 
<          SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
<        LOG_ERROR(LOG_TABLE, 'Stop location queues: ' || SUBSTR(SQLERRM, 1, 256));
<        ERROR_FLG := TRUE;
---
> 
>      EXCEPTION
>        WHEN OTHERS THEN
>          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>            'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')49]: ' || SQLERRM);
> 
>          LOG_TABLE :=
>            SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_tracker_log');
>          LOG_ERROR(LOG_TABLE, 'Stop location queues: ' || SUBSTR(SQLERRM, 1, 256));
>          ERROR_FLG := TRUE;
1529,1530c1987,1988
<    IF (ERROR_FLG) THEN 
<      MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>    IF (ERROR_FLG) THEN
>      MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
1543a2002,2006
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1546c2009
<     BEGIN 
---
>     BEGIN
1547a2011,2023
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>              'Invalid tracking set name: ' || TRACKING_SET_NAME);
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')50]: ' || SQLERRM);
>           MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Errors found in sdo_trkr.stop_tracking_set: fetching queue counts');
>     END;
> 
>     BEGIN
1549,1555c2025,2034
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN
<         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<            'Invalid tracking set name: ' || TRACKING_SET_NAME); 
<       WHEN OTHERS THEN
<         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Errors found in sdo_trkr.stop_tracking_set: fetching queue counts');
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>           MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>              'Invalid tracking set name: ' || TRACKING_SET_NAME);
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')51]: ' || SQLERRM);
>           MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Errors found in sdo_trkr.stop_tracking_set: fetching queue counts');
1558c2037
<     LOG_TABLE := 
---
>     LOG_TABLE :=
1562c2041
<     BEGIN 
---
>     BEGIN
1564,1566c2043,2048
<     EXCEPTION
<       WHEN OTHERS THEN
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')52]: ' || SQLERRM);
>           ERROR_FLG := TRUE;
1569c2051
<     BEGIN 
---
>     BEGIN
1571,1573c2053,2058
<     EXCEPTION
<       WHEN OTHERS THEN
<         ERROR_FLG := TRUE;
---
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')53]: ' || SQLERRM);
>           ERROR_FLG := TRUE;
1576,1580c2061,2068
<     BEGIN 
<       PERFORM_POSTPROCESSING(TRACKING_SET_NAME); 
<     EXCEPTION
<       WHEN OTHERS THEN
<         ERROR_FLG := TRUE;
---
>     BEGIN
>       PERFORM_POSTPROCESSING(TRACKING_SET_NAME);
> 
>       EXCEPTION
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')54]: ' || SQLERRM);
>           ERROR_FLG := TRUE;
1585,1586c2073,2074
<     IF (ERROR_FLG) THEN 
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
---
>     IF (ERROR_FLG) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
1600a2089,2093
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1615,1619c2108,2114
<     EXCEPTION
<       WHEN TIMEOUT_OR_EOF THEN
<         MESSAGE := NULL;        
<       WHEN OTHERS THEN 
<         RAISE;
---
>       EXCEPTION
>         WHEN TIMEOUT_OR_EOF THEN
>           MESSAGE := NULL;
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')55]: ' || SQLERRM);
>           RAISE;
1634a2130,2134
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1637,1643c2137,2146
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN
<        MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Invalid tracking set name: ' || TRACKING_SET_NAME); 
<       WHEN OTHERS THEN
<         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Tracking Message Send Failed'); 
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Invalid tracking set name: ' || TRACKING_SET_NAME);
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')56]: ' || SQLERRM);
>           MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Tracking Message Send Failed');
1645c2148
<     
---
> 
1647c2150
<     
---
> 
1670c2173
<     ARR                 LOC_MSG_PKD_ARR; 
---
>     ARR                 LOC_MSG_PKD_ARR;
1674a2178,2182
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
1677,1683c2185,2194
<     EXCEPTION
<       WHEN TABLE_NOT_FOUND THEN
<        MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Invalid tracking set name: ' || TRACKING_SET_NAME); 
<       WHEN OTHERS THEN
<         MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<           'Location Message Send Failed'); 
---
> 
>       EXCEPTION
>         WHEN TABLE_NOT_FOUND THEN
>          MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Invalid tracking set name: ' || TRACKING_SET_NAME);
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')57]: ' || SQLERRM);
>           MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>             'Location Message Send Failed');
1687,1688c2198,2199
<       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199, 
<         'Location Message, invalid queue count: ' || TO_CHAR(NOQ)); 
---
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>         'Location Message, invalid queue count: ' || TO_CHAR(NOQ));
1690c2201
<     
---
> 
1699c2210
<     FOR I IN 1..LOCATION_MSGS.COUNT 
---
>     FOR I IN 1..LOCATION_MSGS.COUNT
1707c2218
<     FOR I IN 1..NOQ 
---
>     FOR I IN 1..NOQ
1713c2224
<         QUEUE_NAME         => QUEUE_NAME, 
---
>         QUEUE_NAME         => QUEUE_NAME,
1726c2237,2240
<     CNT             NUMBER := 0; 
---
>     CNT             NUMBER := 0;
>     JOB_NAME        VARCHAR2(260);
>     TABLE_NOT_FOUND EXCEPTION;
>     PRAGMA EXCEPTION_INIT(TABLE_NOT_FOUND, -00942);
1727a2242,2249
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     JOB_NAME :=
>       SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_TRACKER_QUEUES');
> 
1729,1731c2251,2252
<     STMT := 'SELECT /*+ RESULT_CACHE */ num_loc_queues FROM ' ||
<       SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || 
<         '_TRACKER_QUEUES');
---
>     STMT := 'SELECT /*+ RESULT_CACHE */ num_loc_queues ' ||
>             'FROM ' || JOB_NAME;
1733c2254,2273
<     EXECUTE IMMEDIATE STMT INTO CNT; 
---
>     BEGIN
>       EXECUTE IMMEDIATE STMT INTO CNT;
> 
>       EXCEPTION
>         WHEN NO_DATA_FOUND THEN
>           CNT := 0;
> 
>         WHEN TABLE_NOT_FOUND THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[Cannot find table ' || JOB_NAME || ']');
>           RAISE;
> 
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')58]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           RAISE;
>     END;
1742c2282,2283
<     CNT        NUMBER := 0; 
---
>     CNT        NUMBER := 0;
>     JOB_NAME   VARCHAR2(260);
1743a2285,2292
>     IF ( TRACKING_SET_NAME IS NULL ) THEN
>       MDERR.RAISE_MD_ERROR('MD', 'SDO', -13199,
>        'Tracking set name is NULL');
>     END IF;
> 
>     JOB_NAME :=
>       SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || '_TRACKER_QUEUES');
> 
1745,1747c2294,2298
<     STMT := 'SELECT /*+ RESULT_CACHE */ num_trkr_queues FROM ' ||
<       SYS.DBMS_ASSERT.ENQUOTE_NAME(TRACKING_SET_NAME || 
<         '_TRACKER_QUEUES');
---
>     STMT := 'SELECT /*+ RESULT_CACHE */ num_trkr_queues ' ||
>             'FROM ' || JOB_NAME;
> 
>     BEGIN
>       EXECUTE IMMEDIATE STMT INTO CNT;
1749c2300,2310
<     EXECUTE IMMEDIATE STMT INTO CNT; 
---
>       EXCEPTION
>         WHEN NO_DATA_FOUND THEN
>           CNT := 0;
>         WHEN OTHERS THEN
>           SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdoobjtrkrb.sql(' || $$PLSQL_LINE || ')59]: ' || SQLERRM);
>           SYS.DBMS_SYSTEM.KSDWRT(
>             SYS.DBMS_SYSTEM.TRACE_FILE,
>             'EXCEPTION[sdo_trkr(' || STMT || ')]');
>           RAISE;
>     END;
MDSYS.SDO_TUNE - PACKAGE BODY (RU):
180,182c180,183
<   STMT := 'SELECT ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(COLUMN_NAME) || ' FROM ' || 
<        SYS.DBMS_ASSERT.ENQUOTE_NAME(OWNER) || '.' ||
<        SYS.DBMS_ASSERT.ENQUOTE_NAME(TABLE_NAME);
---
>   STMT := 'SELECT "' || SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(COLUMN_NAME) ||
>           '" FROM "' || 
>           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(OWNER) || '"."' ||
>           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(TABLE_NAME) || '"';
395a397,402
>   G_TABNAM      VARCHAR2(130);
>   G_TABNAM_NQ   VARCHAR2(130);
>   G_COLNAM      VARCHAR2(1024);
>   G_COLNAM_NQ   VARCHAR2(1024);
>   G_PTNNAM      VARCHAR2(130);
>   G_PTNNAM_NQ   VARCHAR2(130);
410c417
<     TNAME := NLS_UPPER(TABLE_NAME);
---
>     TNAME := TABLE_NAME;
413c420,446
<     TNAME := NLS_UPPER(SUBSTR(TABLE_NAME, DOT_INDEX+1));
---
>     TNAME := SUBSTR(TABLE_NAME, DOT_INDEX+1);
>   END IF;
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(TNAME) ) THEN
>     G_TABNAM := TNAME;
>   ELSE
>     G_TABNAM := REPLACE(NLS_UPPER(TNAME), '"');
>   END IF;
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME) ) THEN
>     G_COLNAM := COLUMN_NAME;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(COLUMN_NAME), '"');
>   END IF;
>   G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
>   IF ( PARTITION_NAME IS NOT NULL ) THEN
>     IF ( SDO_UTIL.IS_BUMPY_CASE(PARTITION_NAME) ) THEN
>       G_PTNNAM := PARTITION_NAME;
>     ELSE
>       G_PTNNAM := REPLACE(NLS_UPPER(PARTITION_NAME), '"');
>     END IF;
>     G_PTNNAM_NQ := REPLACE(G_PTNNAM, '"');
>   ELSE
>     G_PTNNAM := NULL;
>     G_PTNNAM_NQ := NULL;
428c461
<           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(TNAME) ;
---
>           SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM_NQ);
430c463
<       UPPER_TABLE := TNAME; 
---
>       UPPER_TABLE := G_TABNAM_NQ; 
433c466
<     UPPER_TABLE := TNAME; 
---
>     UPPER_TABLE := G_TABNAM_NQ; 
443,444c476,477
<     SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(UPPER_TABLE),
<     NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME)),
---
>     SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM),
>     SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM),
463,464c496,497
<         AND A.SDO_INDEX_PARTITION = NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(PARTITION_NAME))
<         AND REPLACE(A.SDO_COLUMN_NAME,'"') = NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME)); 
---
>         AND A.SDO_INDEX_PARTITION = SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_PTNNAM_NQ)
>         AND REPLACE(A.SDO_COLUMN_NAME,'"') = SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM_NQ); 
474c507
<         AND REPLACE(A.SDO_COLUMN_NAME,'"') = NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME)); 
---
>         AND REPLACE(A.SDO_COLUMN_NAME,'"') = SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM_NQ);
490,492c523,525
<             ' AND TABLE_NAME = :2 ' || 
<             ' AND SDO_INDEX_PARTITION = :3 ' ||
<             ' AND COLUMN_NAME = :4 ';
---
>             'AND TABLE_NAME = :2 ' || 
>             'AND SDO_INDEX_PARTITION = :3 ' ||
>             'AND COLUMN_NAME = :4 ';
495,497c528,530
<             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(UPPER_TABLE), 
<             NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(PARTITION_NAME)),
<             NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME));
---
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM_NQ), 
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_PTNNAM_NQ),
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM_NQ);
502,503c535,536
<             ' AND TABLE_NAME = :2 ' || 
<             ' AND COLUMN_NAME = :3 ';
---
>             'AND TABLE_NAME = :2 ' || 
>             'AND COLUMN_NAME = :3 ';
506,507c539,540
<             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(UPPER_TABLE), 
<             NLS_UPPER(SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(COLUMN_NAME));
---
>             SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM_NQ), 
>             SYS.DBMS_ASSERT.QUALIFIED_SQL_NAME(G_COLNAM_NQ);
654a688,691
>   G_TABNAM      VARCHAR2(130);
>   G_TABNAM_NQ   VARCHAR2(130);
>   G_COLNAM      VARCHAR2(130);
>   G_COLNAM_NQ   VARCHAR2(130);
669c706
<     UPPER_TABLE := NLS_UPPER(TABLE_NAME);
---
>     UPPER_TABLE := TABLE_NAME;
672c709
<     UPPER_TABLE := NLS_UPPER(SUBSTR(TABLE_NAME, DOT_INDEX+1));
---
>     UPPER_TABLE := SUBSTR(TABLE_NAME, DOT_INDEX+1);
674a712,725
>   IF ( SDO_UTIL.IS_BUMPY_CASE(UPPER_TABLE) ) THEN
>     G_TABNAM := UPPER_TABLE;
>   ELSE
>     G_TABNAM := REPLACE(NLS_UPPER(UPPER_TABLE), '"');
>   END IF;
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME) ) THEN
>     G_COLNAM := COLUMN_NAME;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(COLUMN_NAME), '"');
>   END IF;
>   G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
678,679c729,730
<     UPPER_TABLE,
<     COLUMN_NAME,
---
>     G_TABNAM,
>     G_COLNAM,
685,686c736,737
<   STATUS := AVG_DELTAS_OF_OBJECTS(UPPER_USER, UPPER_TABLE,
<                                   COLUMN_NAME, DIMARRAY, 
---
>   STATUS := AVG_DELTAS_OF_OBJECTS(UPPER_USER, G_TABNAM_NQ,
>                                   G_COLNAM_NQ, DIMARRAY, 
724a776,779
>   G_TABNAM       VARCHAR2(130);
>   G_TABNAM_NQ    VARCHAR2(130);
>   G_COLNAM       VARCHAR2(130);
>   G_COLNAM_NQ    VARCHAR2(130);
733,735c788,803
<   STMT := 'SELECT ' || 
<       SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(COLUMN_NAME) || ' FROM ' || 
<       SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(TABLE_NAME);
---
>   IF ( SDO_UTIL.IS_BUMPY_CASE(TABLE_NAME) ) THEN
>     G_TABNAM := TABLE_NAME;
>   ELSE
>     G_TABNAM := REPLACE(NLS_UPPER(TABLE_NAME), '"');
>   END IF;
>   G_TABNAM_NQ := REPLACE(G_TABNAM, '"');
> 
>   IF ( SDO_UTIL.IS_BUMPY_CASE(COLUMN_NAME) ) THEN
>     G_COLNAM := COLUMN_NAME;
>   ELSE
>     G_COLNAM := REPLACE(NLS_UPPER(COLUMN_NAME), '"');
>   END IF;
>   G_COLNAM_NQ := REPLACE(G_COLNAM, '"');
> 
>   STMT := 'SELECT "' || SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_COLNAM_NQ) ||
>           '" FROM "' || SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(G_TABNAM_NQ) || '"';
MDSYS.SDO_UTIL - PACKAGE BODY (RU):
64a65,79
>   FUNCTION GET_TABLE_PTN_OBJ_ID(TABLE_OWNER IN VARCHAR2,
>                                 TABLE_NAME IN VARCHAR2,
>                                 TABLE_PTN IN VARCHAR2 DEFAULT NULL)
>   RETURN NUMBER IS
>     EXTERNAL
>     NAME "get_table_ptn_obj_id"
>     LIBRARY ORDMD_UTL_LIBS
>     WITH CONTEXT
>     PARAMETERS(CONTEXT,
>                TABLE_OWNER, TABLE_OWNER INDICATOR, TABLE_OWNER LENGTH,
>                TABLE_NAME, TABLE_NAME INDICATOR, TABLE_NAME LENGTH,
>                TABLE_PTN, TABLE_PTN INDICATOR, TABLE_PTN LENGTH,
>                RETURN INDICATOR, RETURN);
> 
>   
167a183,224
>   FUNCTION IS_BUMPY_CASE(NAME IN VARCHAR2,
>                          SKIP_QUOTES IN BOOLEAN DEFAULT FALSE)
>   RETURN BOOLEAN DETERMINISTIC IS
>     LEN NUMBER;
>     CH VARCHAR2(2);
>   BEGIN
>     LEN := LENGTH(NAME);
> 
>     
>     
>     IF ( NOT SKIP_QUOTES ) THEN
>       IF ( LEN <= 2 ) THEN
>         RETURN FALSE;
>       END IF;
>     END IF;
> 
>     
>     IF ( NOT SKIP_QUOTES ) THEN
>       IF ( (SUBSTR(NAME, 1, 1) <> '"') OR
>            (SUBSTR(NAME, LEN, 1) <> '"') ) THEN
>         RETURN FALSE;
>       END IF;
>     END IF;
> 
>     
>     
>     
>     
>     FOR I IN 1 .. LEN
>     LOOP
>       CH := SUBSTR(NAME, I, 1);
>       IF ( CH <> NLS_UPPER(CH) ) THEN
>         RETURN TRUE;
>       END IF;
>     END LOOP;
> 
>     
>     RETURN FALSE;
>   END IS_BUMPY_CASE;
> 
>   
>   
230c287
<     RETURN '"' || OBJNAME || '"';
---
>     RETURN SYS.DBMS_ASSERT.ENQUOTE_NAME(OBJNAME, FALSE);
6549c6606,6607
<  FUNCTION FROM_GEOJSON(GEOMETRY IN VARCHAR2, CRS IN VARCHAR2 DEFAULT NULL,
---
>  FUNCTION FROM_GEOJSON(GEOMETRY IN VARCHAR2,
>                        CRS IN VARCHAR2 DEFAULT NULL,
MDSYS.SDO_GEOM_TRIG_INS1 - TRIGGER (RU):
6,16c6,16
<  tname varchar2(130);
<  stmt  varchar2(2048);
<  vcount INTEGER;
<  dimcount INTEGER;
<  tolerance NUMBER;
<  dimelement MDSYS.SDO_DIM_ELEMENT;
<  idx  number;
<  colname  varchar2(1024);
<  jsoncol  varchar2(1024);
<  jsonpath varchar2(1024);
<  nextPos  pls_integer;
---
>   stmt varchar2(2048);
>   vcount INTEGER;
>   dimcount INTEGER;
>   tolerance NUMBER;
>   dimelement MDSYS.SDO_DIM_ELEMENT;
>   idx      number;
>   owner    varchar2(130);
>   tabname  varchar2(130);
>   colname  varchar2(1024);
>   jsoncol  varchar2(1024);
>   jsonpath varchar2(1024);
18,44c18
<   tname := sys_context('userenv', 'session_user');
<   colname := nls_upper(:n.column_name);
< 
<   if ( (instr(:n.table_name, ' ') > 0 ) OR
<        (instr(:n.table_name, '''') > 0 ) )  then
<    mderr.raise_md_error('MD', 'SDO', -13199,
<                'wrong table name: ' || :n.table_name);
<    end if;
< 
<   if ((instrb(colname, 'JSON_VALUE') > 0) and
<       (instrb(colname, '(') > 0) and
<       (instrb(colname, ')') > 0) and
<       (instrb(colname, ',') > 0) and
<       (instrb(colname, 'RETURNING') > 0)) then
<     colname := mdsys.mdprvt_gmd.get_json_geom_col(colname);
<   elsif ( (instr(colname, ' ') > 0 ) OR
<           (instr(colname, '''') > 0 ) ) then
<    mderr.raise_md_error('MD', 'SDO', -13199,
<                'wrong column name: ' || :n.column_name);
<    end if;
< 
<   stmt :=  'SELECT count(*) FROM MDSYS.SDO_GEOM_METADATA_TABLE ' ||
<   'WHERE sdo_owner = :tname  AND sdo_table_name = :table_name  '||
<   '  AND  sdo_column_name = :column_name  ';
< 
< EXECUTE IMMEDIATE stmt INTO vcount
<    USING tname, nls_upper(:n.table_name), colname;
---
>   owner := sys_context('userenv', 'session_user');
45a20,54
>   if ( sdo_util.is_bumpy_case(:n.table_name) ) then
>     tabname := :n.table_name;
>   elsif ( (instr(:n.table_name, ' ') > 0 ) or
>           (instr(:n.table_name, '''') > 0 ) ) then
>     mderr.raise_md_error('MD', 'SDO', -13199,
>                          'wrong table name: ' || :n.table_name);
>   else
> 
>     tabname := replace(nls_upper(:n.table_name), '"');
>   end if;
> 
>   if ( (instrb(:n.column_name, 'JSON_VALUE') > 0) and
>        (instrb(:n.column_name, '(') > 0) and
>        (instrb(:n.column_name, ')') > 0) and
>        (instrb(:n.column_name, ',') > 0) and
>        (instrb(:n.column_name, 'RETURNING') > 0)) then
>     colname := mdsys.mdprvt_gmd.get_json_geom_col(:n.column_name);
>   elsif ( sdo_util.is_bumpy_case(:n.column_name) ) then
>     colname := :n.column_name;
>   elsif ( (instr(:n.column_name, ' ') > 0 ) or
>           (instr(:n.column_name, '''') > 0 ) ) then
>     mderr.raise_md_error('MD', 'SDO', -13199,
>                          'wrong column name: ' || :n.column_name);
>   else
> 
>     colname := replace(nls_upper(:n.column_name), '"');
>   end if;
> 
>   stmt := 'SELECT count(*) ' ||
>           'FROM MDSYS.SDO_GEOM_METADATA_TABLE ' ||
>           'WHERE sdo_owner = :own ' ||
>           'AND sdo_table_name = :tab '||
>           'AND sdo_column_name = :col';
>   EXECUTE IMMEDIATE stmt INTO vcount
>     USING owner, tabname, colname;
58,59c67,68
<     mdsys.sdo_meta.insert_all_sdo_geom_metadata(tname,
<                                                 :n.table_name,
---
>     mdsys.sdo_meta.insert_all_sdo_geom_metadata(owner,
>                                                 tabname,
MDSYS.SDO_GEOM_TRIG_UPD1 - TRIGGER (RU):
5a6,8
>   owner varchar2(130);
>   tabname varchar2(130);
>   colname varchar2(1024);
6a10
>   owner := sys_context('userenv', 'session_user');
8c12,38
<   mdsys.sdo_meta.change_all_sdo_geom_metadata(sys_context('userenv', 'session_user'),
---
>   if ( sdo_util.is_bumpy_case(:n.table_name) ) then
>     tabname := :n.table_name;
>   elsif ( (instr(:n.table_name, ' ') > 0 ) OR
>           (instr(:n.table_name, '''') > 0 ) ) then
>     mderr.raise_md_error('MD', 'SDO', -13199,
>                          'wrong table name: ' || :n.table_name);
>   else
>     tabname := replace(nls_upper(:n.table_name), '"');
>   end if;
> 
>   if ( (instrb(:n.column_name, 'JSON_VALUE') > 0) and
>        (instrb(:n.column_name, '(') > 0) and
>        (instrb(:n.column_name, ')') > 0) and
>        (instrb(:n.column_name, ',') > 0) and
>        (instrb(:n.column_name, 'RETURNING') > 0)) then
>     colname := mdsys.mdprvt_gmd.get_json_geom_col(:n.column_name);
>   elsif ( sdo_util.is_bumpy_case(:n.column_name) ) then
>     colname := :n.column_name;
>   elsif ( (instr(:n.column_name, ' ') > 0 ) OR
>           (instr(:n.column_name, '''') > 0 ) ) then
>     mderr.raise_md_error('MD', 'SDO', -13199,
>                          'wrong column name: ' || :n.column_name);
>   else
>     colname := replace(nls_upper(:n.column_name), '"');
>   end if;
> 
>   mdsys.sdo_meta.change_all_sdo_geom_metadata(owner,
11,12c41,42
<                                               :n.table_name,
<                                               :n.column_name,
---
>                                               tabname,
>                                               colname,
MDSYS.SAMCLUST_IMP_T - TYPE BODY (RU):
11a12,14
>     TNAME_NQ    VARCHAR2(130); 
>     CNAME       VARCHAR2(130);
>     CNAME_NQ    VARCHAR2(130); 
52c55,58
<         SELECT NLS_UPPER(SUBSTR(TABLENAME, LEN+1)) INTO TNAME FROM SYS.DUAL;
---
>         SELECT SUBSTR(TABLENAME, LEN+1) INTO TNAME FROM SYS.DUAL;
>         IF ( NOT SDO_UTIL.IS_BUMPY_CASE(TNAME) ) THEN
>           TNAME := REPLACE(NLS_UPPER(TNAME), '"');
>         END IF;
57c63,74
<       TNAME := NLS_UPPER(TABLENAME);
---
>       IF ( SDO_UTIL.IS_BUMPY_CASE(TABLENAME) ) THEN
>         TNAME := TABLENAME;
>       ELSE
>         TNAME := REPLACE(NLS_UPPER(TABLENAME), '"');
>       END IF;
>     END IF;
>     TNAME_NQ := REPLACE(TNAME, '"');
> 
>     IF ( SDO_UTIL.IS_BUMPY_CASE(COLNAME) ) THEN
>       CNAME := COLNAME;
>     ELSE
>       CNAME := REPLACE(NLS_UPPER(COLNAME), '"');
58a76
>     CNAME_NQ := REPLACE(CNAME, '"');
77c95
<               'and a.sdo_column_name = SYS.DBMS_ASSERT.ENQUOTE_NAME(:colnam) ';
---
>               'and replace(a.sdo_column_name, ''"'') = :colnam ';
80c98
<       USING TSCHEMA, TNAME, COLNAME;
---
>       USING TSCHEMA, TNAME_NQ, CNAME_NQ;
113c131,135
<         TPARTN := NLS_UPPER(TABLEPARTITION);
---
>         IF ( SDO_UTIL.IS_BUMPY_CASE(TABLEPARTITION) ) THEN
>           TPARTN := TABLEPARTITION;
>         ELSE
>           TPARTN := REPLACE(NLS_UPPER(TABLEPARTITION), '"');
>         END IF;
124c146
<         USING TSCHEMA, TNAME, TPARTN, ISCHEMA, INAME;
---
>         USING TSCHEMA, TNAME_NQ, TPARTN, ISCHEMA, INAME;
130c152
<     COLS(1) := SYS.ODCICOLINFO(TSCHEMA, TNAME, NLS_UPPER(COLNAME),
---
>     COLS(1) := SYS.ODCICOLINFO(TSCHEMA, TNAME_NQ, CNAME_NQ,
MDSYS.SDO_INDEX_METHOD_10I - TYPE BODY (RU):
277c277
<         SYS.DBMS_ASSERT.NOOP(SDO_UTIL.NUMBER_TO_CHAR(NND2));
---
>         SDO_UTIL.NUMBER_TO_CHAR(NND2);
291c291
<         SYS.DBMS_ASSERT.NOOP(SDO_UTIL.NUMBER_TO_CHAR(NND1));
---
>         SDO_UTIL.NUMBER_TO_CHAR(NND1);
377,378c377
<       STATUS := MDSYS.PRVT_IDX.CRT_DUMMY_IDX(PART_IA2, 
<                                              PART_NAME2.INDEXPARTITION);
---
>       STATUS := MDSYS.PRVT_IDX.CRT_DUMMY_IDX(PART_IA2);
443,444c442
<          STATUS := MDSYS.PRVT_IDX.CRT_DUMMY_IDX(PART_IA1,
<                                                 PART_NAME1.INDEXPARTITION);
---
>          STATUS := MDSYS.PRVT_IDX.CRT_DUMMY_IDX(PART_IA1);
465,466c463
<           STATUS := MDSYS.PRVT_IDX.CRT_DUMMY_IDX(PART_IA2, 
<                                                  PART_NAME2.INDEXPARTITION);
---
>           STATUS := MDSYS.PRVT_IDX.CRT_DUMMY_IDX(PART_IA2);
MDSYS.SPARQL_SERVICE_IMPL_T - TYPE BODY (RU):
77c77
<         REST_VARIABLES := UPPER(VARIABLES); 
---
>         REST_VARIABLES := NLS_UPPER(VARIABLES); 
604c604
<             VAR := UPPER(SUBSTRB(SELF.STRBUFFER,IDXSTART,IDXEND-IDXSTART));
---
>             VAR := NLS_UPPER(SUBSTRB(SELF.STRBUFFER,IDXSTART,IDXEND-IDXSTART));
887c887
<               VAR := UPPER(XMLDOM.GETNODEVALUE(XMLDOM.ITEM(XMLDOM.GETATTRIBUTES(N1),0)));
---
>               VAR := NLS_UPPER(XMLDOM.GETNODEVALUE(XMLDOM.ITEM(XMLDOM.GETATTRIBUTES(N1),0)));
MDSYS.ALL_SDO_GEOM_METADATA - VIEW (RU):
8c8
< WHERE  b.sdo_table_name = a.table_name
---
> WHERE replace(b.sdo_table_name, '"') = a.table_name
MDSYS.ALL_SDO_INDEX_METADATA - VIEW (RU):
13c13,15
<         SDO_DML_BATCH_SIZE, SDO_RTREE_ENT_XPND,
---
>         SDO_DML_BATCH_SIZE,
>         SDO_RTREE_READ_ONLY,
>         SDO_RTREE_ENT_XPND,
MDSYS.MY_SDO_INDEX_METADATA - VIEW (RU):
18c18,20
<         SDO_DML_BATCH_SIZE, SDO_RTREE_ENT_XPND,
---
>         SDO_DML_BATCH_SIZE,
>         SDO_RTREE_READ_ONLY,
>         SDO_RTREE_ENT_XPND,
MDSYS.USER_SDO_INDEX_METADATA - VIEW (RU):
18c18,20
<         SDO_DML_BATCH_SIZE, SDO_RTREE_ENT_XPND,
---
>         SDO_DML_BATCH_SIZE,
>         SDO_RTREE_READ_ONLY,
>         SDO_RTREE_ENT_XPND,
SYS.DG$GETFLATDG - FUNCTION (RU):
1,3c1
< function dg$getFlatDg(owner VARCHAR2,
<                              tableName VARCHAR2,
<                              jcolName VARCHAR2) RETURN dg$rowset PIPELINED
---
> function dg$getFlatDg(dg CLOB) RETURN dg$rowset PIPELINED
13,17c11,12
<   stmt := 'with dg_t as (SELECT sys.dg$getDgQuoteName(:1, :2, :3,
<                                 dbms_json.format_flat, 0) dg_doc
<                          FROM dual)
<            select jt.jpath as PATH, jt.jtype as TYPE, jt.tlength as LENGTH
<            from dg_t, json_table(dg_doc,''$[*]'' columns
---
>   stmt := 'select jt.jpath as PATH, jt.jtype as TYPE, jt.tlength as LENGTH
>            from json_table(:1,''$[*]'' columns
22c17
<   OPEN cur for stmt USING owner, tableName, jcolName;
---
>   OPEN cur for stmt USING dg;
SYS.DG$HASDGINDEX - FUNCTION (RU):
1,2c1,2
< function dg$hasDGIndex(owner VARCHAR2,
<                                          tableName VARCHAR2,
---
> function dg$hasDGIndex(owner NUMBER,
>                                          tab   NUMBER,
5,7d4
<   userId      NUMBER;
<   tableId     NUMBER;
<   indexName   varchar2(130);
10,30d6
<   -- get index name, owner's id and table number by checking if the
<   -- column has a context index
<   EXECUTE IMMEDIATE
<    'select ix.index_name, u.user_id, o.object_id
<     from dba_ind_columns ic, dba_indexes ix, dba_users u, dba_objects o
<     where
<       ic.table_owner = ix.table_owner and
<       ic.index_name = ix.index_name and
<       ic.table_name = ix.table_name and
<       ic.table_owner = u.username and
<       u.username = o.owner and
<       o.object_name = ic.table_name and
<       o.object_type = ''TABLE'' and
<       ic.column_name= :1 and
<       ic.table_name= :2 and
<       u.username= :3 and
<       ix.ITYP_OWNER = ''CTXSYS'' and
<       (ix.ITYP_NAME= ''CONTEXT'' or ix.ITYP_NAME = ''CONTEXT_V2'')'
<   INTO indexName, userId, tableId
<   USING jcolName, tableName, owner;
< 
32,33d7
<   /* bug 23548844: execute immediate without into does not raise
<      no_data_found error */
38c12
<       idx_name = :1 and
---
>       idx_table_owner# = :1 and
40c14
<       idx_table_owner# = :3 and
---
>       idx_text_name = :3 and
43c17
<   USING indexName, tableId, userId;
---
>   USING owner, tab, jcolName;
48c22
<     WHEN no_data_found THEN
---
>     WHEN others THEN
SYS.DBMS_ASH - PACKAGE (RU):
1c1
< PACKAGE dbms_ash AUTHID CURRENT_USER IS
---
> PACKAGE dbms_ash AUTHID DEFINER IS
73a74
>   , RESOLUTION        VARCHAR(30)
120c121
<   REPORT_INTERNAL_VERSION CONSTANT VARCHAR2(64) := '44';
---
>   REPORT_INTERNAL_VERSION CONSTANT VARCHAR2(64) := '47';
128c129
<   OMC_ALLOWED_ERR_RATIO CONSTANT NUMBER := 0.98;
---
>   OMC_ALLOWED_ERR_RATIO CONSTANT NUMBER := 1;
131,132d131
<   OMC_DEF_BUCKETS CONSTANT NUMBER := 120;
< 
134,135c133,149
<   OMC_DEF_ROWS_PER_BUCKET CONSTANT NUMBER := 20;
< 
---
>   
>   
>   
>   
>   
>   OMC_LOW_RESOLUTION CONSTANT VARCHAR2(10) := 'LOW';
>   OMC_LOW_BUCKETS CONSTANT NUMBER := 120;
>   OMC_LOW_ROWS_PER_BUCKET CONSTANT NUMBER := 20;
>   OMC_MED_RESOLUTION CONSTANT VARCHAR2(10) := 'MEDIUM';
>   OMC_MED_BUCKETS CONSTANT NUMBER := 180;
>   OMC_MED_ROWS_PER_BUCKET CONSTANT NUMBER := 35;
>   OMC_HIGH_RESOLUTION CONSTANT VARCHAR2(10) := 'HIGH';
>   OMC_HIGH_BUCKETS CONSTANT NUMBER := 360;
>   OMC_HIGH_ROWS_PER_BUCKET CONSTANT NUMBER := 50;
>   OMC_MAX_RESOLUTION CONSTANT VARCHAR2(10) := 'MAX';
>   
>   
188,198c202,236
<   FUNCTION FETCH_SQLTEXT_LOCAL(P_SQLID IN VARCHAR, P_DBID IN NUMBER, 
<                                P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR;
< 
<   FUNCTION FETCH_SQLTEXT_AWR(P_SQLID IN VARCHAR, P_DBID IN NUMBER, 
<                              P_IS_PDB IN VARCHAR, P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR;
< 
<   FUNCTION FETCH_OBJ_NAME_LOCAL(P_OBJ_ID IN NUMBER, P_DBID IN NUMBER,
<                                 P_CON_DBID IN NUMBER, P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR;
---
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION FETCH_SQLTEXT(P_SQLID IN VARCHAR, 
>                          P_DBID IN NUMBER, P_CON_DBID IN NUMBER,
>                          P_IS_LOCAL IN VARCHAR, P_IS_PDB IN VARCHAR,
>                          P_IS_OLD IN VARCHAR, P_TIME_LIMIT IN VARCHAR)
>   RETURN   XMLTYPE;
200,203c238,299
<   FUNCTION FETCH_OBJ_NAME_AWR(P_OBJ_ID IN NUMBER, P_DBID IN NUMBER, 
<                               P_CON_DBID IN NUMBER, P_IS_PDB IN VARCHAR,
<                               P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR;
---
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION FETCH_OBJ_NAME(P_OBJ_ID IN NUMBER, P_DBID IN NUMBER,
>                           P_CON_DBID IN NUMBER, P_IS_LOCAL IN VARCHAR,
>                           P_LOCAL_TYPE IN VARCHAR, P_IS_OLD IN VARCHAR,
>                           P_TIME_LIMIT IN VARCHAR)
>   RETURN   XMLTYPE;
204a301,310
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
208a315,324
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
266a383
>   
349a467,468
>   
>   
356c475,476
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
374a495,496
>   
>   
381c503,504
<     , AWR_INFO IN VARCHAR2 := 'n')
---
>     , AWR_INFO IN VARCHAR2 := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
396a520,521
>   
>   
406c531,532
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
420a547,548
>   
>   
428c556,557
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
447a577,578
>   
>   
455c586,587
<     , INSTANCE_NUMBER IN NUMBER := NULL)
---
>     , INSTANCE_NUMBER IN NUMBER := NULL
>     , RESOLUTION      IN VARCHAR2 := 'medium')
471a604,605
>   
>   
482c616,617
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
499a635,636
>   
>   
507c644,645
<     , MINIMIZE_COST   IN VARCHAR2 := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR2 := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
528a667,668
>   
>   
537c677,678
<     , MINIMIZE_COST   IN VARCHAR2 := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR2 := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
555a697,698
>   
>   
566c709,710
<     , MINIMIZE_COST   IN VARCHAR2 := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR2 := 'n'
>     , RESOLUTION      IN VARCHAR2 := 'medium')
SYS.DBMS_BACKUP_RESTORE - PACKAGE (19.7RUR):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '19.07.00.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '19.07.01.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('19.07.00.00', '.');
<   msn  CONSTANT NUMBER := instr('19.07.00.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('19.07.00.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('19.07.01.00', '.');
>   msn  CONSTANT NUMBER := instr('19.07.01.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('19.07.01.00', '.', msn + 1);
29c29
<                            to_number(substr('19.07.00.00', 1, fsn - 1));
---
>                            to_number(substr('19.07.01.00', 1, fsn - 1));
31c31
<                to_number(substr('19.07.00.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('19.07.01.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('19.07.00.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('19.07.01.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('19.07.00.00',  psn + 1));
---
>                              to_number(substr('19.07.01.00',  psn + 1));
SYS.DBMS_BACKUP_RESTORE - PACKAGE (19.6RUR):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '19.06.01.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '19.06.02.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('19.06.01.00', '.');
<   msn  CONSTANT NUMBER := instr('19.06.01.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('19.06.01.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('19.06.02.00', '.');
>   msn  CONSTANT NUMBER := instr('19.06.02.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('19.06.02.00', '.', msn + 1);
29c29
<                            to_number(substr('19.06.01.00', 1, fsn - 1));
---
>                            to_number(substr('19.06.02.00', 1, fsn - 1));
31c31
<                to_number(substr('19.06.01.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('19.06.02.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('19.06.01.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('19.06.02.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('19.06.01.00',  psn + 1));
---
>                              to_number(substr('19.06.02.00',  psn + 1));
SYS.DBMS_BACKUP_RESTORE - PACKAGE (RU):
12c12
<   bannerVersion CONSTANT VARCHAR2(15) := '19.07.00.00';
---
>   bannerVersion CONSTANT VARCHAR2(15) := '19.08.00.00';
24,26c24,26
<   fsn  CONSTANT NUMBER := instr('19.07.00.00', '.');
<   msn  CONSTANT NUMBER := instr('19.07.00.00', '.', fsn + 1);
<   psn  CONSTANT NUMBER := instr('19.07.00.00', '.', msn + 1);
---
>   fsn  CONSTANT NUMBER := instr('19.08.00.00', '.');
>   msn  CONSTANT NUMBER := instr('19.08.00.00', '.', fsn + 1);
>   psn  CONSTANT NUMBER := instr('19.08.00.00', '.', msn + 1);
29c29
<                            to_number(substr('19.07.00.00', 1, fsn - 1));
---
>                            to_number(substr('19.08.00.00', 1, fsn - 1));
31c31
<                to_number(substr('19.07.00.00', fsn + 1, msn - fsn - 1));
---
>                to_number(substr('19.08.00.00', fsn + 1, msn - fsn - 1));
33c33
<               to_number(substr('19.07.00.00',  msn + 1, psn - msn - 1));
---
>               to_number(substr('19.08.00.00',  msn + 1, psn - msn - 1));
35c35
<                              to_number(substr('19.07.00.00',  psn + 1));
---
>                              to_number(substr('19.08.00.00',  psn + 1));
SYS.DBMS_HADOOP_INTERNAL - PACKAGE (RU):
475a476,489
> -- NAME: EVAL_PART_KEY_OPERATOR
> --
> -- DESCRIPTION:
> -- Replace PL/SQL functions such as CAST_TO_RAW, TO_DATE, TIME_STAMP
> -- with the actual results of their evaluations in the DDL statement
> --
> -- PARAMETERS: TEXT_OF_DDL - Text of DDL that contains the partition spec
> --             KEY - One of CAST_TO_RAW, TO_DATE, TIME_STAMP
> --
> -- RETURNS: Modified TEXT_OF_DDL
> --
> FUNCTION EVAL_PART_KEY_OPERATOR(TEXT_OF_DDL IN OUT CLOB, KEY VARCHAR2)
> RETURN CLOB;
> 
SYS.DBMS_REGISTRY - PACKAGE (19.6RUR):
13c13
<                                '19.6.1.0.0';
---
>                                '19.6.2.0.0';
SYS.DBMS_REGISTRY - PACKAGE (RU):
13c13
<                                '19.7.0.0.0';
---
>                                '19.8.0.0.0';
SYS.DBMS_REGISTRY - PACKAGE (19.7RUR):
13c13
<                                '19.7.0.0.0';
---
>                                '19.7.1.0.0';
SYS.DBMS_SQLTUNE_UTIL2 - PACKAGE (RU):
18,21c18,22
<   CLOUD_SERVICE_TYPE_ADW     CONSTANT VARCHAR2(30) := 'DWCS';
<   CLOUD_SERVICE_TYPE_EXADATA CONSTANT VARCHAR2(30) := 'EECS';
<   CLOUD_SERVICE_TYPE_PAAS    CONSTANT VARCHAR2(30) := 'PAAS';
<   CLOUD_SERVICE_TYPE_ATP     CONSTANT VARCHAR2(30) := 'OLTP';
---
>   CLOUD_SERVICE_TYPE_ADW_D   CONSTANT VARCHAR2(30) := 'ADW-D';
>   CLOUD_SERVICE_TYPE_ADW_S   CONSTANT VARCHAR2(30) := 'ADW-S';
>   CLOUD_SERVICE_TYPE_ATP_D   CONSTANT VARCHAR2(30) := 'ATP-D';
>   CLOUD_SERVICE_TYPE_ATP_S   CONSTANT VARCHAR2(30) := 'ATP-S';
>   CLOUD_SERVICE_TYPE_OTHER   CONSTANT VARCHAR2(30) := 'OTHER';
369,373c370,375
<   --     NONE: None
<   --     DWCS: Autonomous Data Warehouse
<   --     EECS: Exadata Express Cloud Service
<   --     PAAS: Platform As A Service (MDBCS)
<   --     OLTP: ATP
---
>   --   CLOUD_SERVICE_TYPE_NONE    =>  'NONE';
>   --   CLOUD_SERVICE_TYPE_ADW_D   =>  'ADW-D';
>   --   CLOUD_SERVICE_TYPE_ADW_S   =>  'ADW-S';
>   --   CLOUD_SERVICE_TYPE_ATP_D   =>  'ATP-D';
>   --   CLOUD_SERVICE_TYPE_ATP_S   =>  'ATP-S';
>   --   CLOUD_SERVICE_TYPE_OTHER   =>  'OTHER';
378c380
<   --------------------------------- is_adw  -----------------------------------
---
>   -------------------------- get_tz_offset  -----------------------------------
380c382
<   --     is_adw
---
>   --     get_tz_offset
383c385
<   --     check if current DB is Autonomous Data Warehouse
---
>   --     get timezone offset from systimestamp
386,387c388
<   --     TRUE is current DB is Autonomous Data Warehouse
<   --     FALSE otherwise
---
>   --     timezone offset in TZ_HOUR:TZ_MINUTE format
389,390c390,420
<   FUNCTION is_adw
<   RETURN BOOLEAN;
---
>   FUNCTION get_tz_offset
>   RETURN VARCHAR2;
> 
>   ----------------------------- chooseAwrForPdb -------------------------
>   -- NAME:
>   --     chooseAwrForPdb
>   --
>   -- DESCRIPTION:
>   --     This function determines the location/prefix of the AWR view to use
>   --     for the database considering the following conditions:
>   --     1. Check whether local awr_pdb has snapshots.
>   --        If not, return AWR_VIEW_ROOT
>   --     2. If local awr has some snapshots use AWR_VIEW_PDB
>   --     3. If by change local awr was stopped/disabled for some time
>   --         (say for eg., last 3 hrs not local awr snapshots)
>   --         then use AWR_VIEW_ROOT
>   --
>   --
>   -- NOTE: The beginTime and endTime used are in DB Timezone.
>   --       Unlike the case of ASH, no need to convert to UTC,
>   --       since end_interval_time in awr_root, awr_pdb  are in same TZ
>   --
>   -- PARAMETERS:
>   --     dbid            (IN)  - database id
>   --
>   -- RETURN:
>   --     Returned type can be 'AWR_ROOT' or 'AWR_PDB'.
>   --
>   -----------------------------------------------------------------------------
>   FUNCTION chooseAwrForPdb(beginTime IN DATE)
>   RETURN VARCHAR2;
SYS.PRVT_ASH_OMX - PACKAGE (RU):
41a42,43
>   
>   
54a57
>     RESOLUTION      IN VARCHAR2 := NULL,
90a94,95
>   
>   
103a109
>     RESOLUTION      IN VARCHAR2 := NULL,
SYS.PRVT_AWR_VIEWER - PACKAGE (RU):
943a944,947
> 
>   
>   
>   
964,969c968,979
<   FUNCTION REPORT_ADW_WORKLOAD_REALTIME(
<     START_TIME        IN DATE           DEFAULT NULL,
<     END_TIME          IN DATE           DEFAULT NULL,
<     INST_ID_LOW       IN NUMBER         DEFAULT NULL,
<     INST_ID_HIGH      IN NUMBER         DEFAULT NULL,
<     SHOW_SQL          IN NUMBER         DEFAULT 0)
---
>   
>   
>   
>   FUNCTION GET_RMMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME      IN DATE               DEFAULT NULL,
>     END_TIME        IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT 0)
994,999c1004,1016
<   FUNCTION REPORT_ADW_WORKLOAD_HISTORICAL(
<     START_TIME        IN DATE           DEFAULT NULL,
<     END_TIME          IN DATE           DEFAULT NULL,
<     DBID              IN NUMBER         DEFAULT NULL,
<     INST_ID           IN NUMBER         DEFAULT NULL,
<     SHOW_SQL          IN NUMBER         DEFAULT 0)
---
>   
>   
>   
>   
>   FUNCTION GET_SQL_N_PARSE_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
1001a1019,1159
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_WAIT_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SYSMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_STORAGE_METRICS_XML(
>     SERVICE_TYPE IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL     IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SESSION_METRICS_XML(
>     SHOW_SQL        IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION REPORT_WORKLOAD(
>     SERVICE_TYPE   IN VARCHAR2 DEFAULT NULL,
>     IS_REALTIME    IN NUMBER   DEFAULT 1,
>     DBID           IN NUMBER   DEFAULT NULL,
>     START_TIME     IN DATE     DEFAULT NULL,
>     END_TIME       IN DATE     DEFAULT NULL,
>     REPORT_LEVEL   IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL       IN NUMBER   DEFAULT 0)
>   RETURN XMLTYPE;
SYS.PRVT_DBMS_INMEMORY_ADMIN - PACKAGE (RU):
2d1
<   PROCEDURE TRACE(TRACE_INFO VARCHAR2);
4,10d2
<   FUNCTION SPACE_USAGE2(SEGMENT_OWNER    IN VARCHAR2,
<                          SEGMENT_NAME    IN VARCHAR2,
<                          SEGMENT_TYPE    IN VARCHAR2,
<                          PARTITION_NAME  IN VARCHAR2,
<                          BITMAPPED       IN NUMBER,
<                          FREELIST_GROUPS IN NUMBER
<                          ) RETURN NUMBER;
SYS.DBMS_ASH - PACKAGE BODY (RU):
146a147
>     DBMS_OUTPUT.PUT_LINE('resolution = ' || CONTEXT.RESOLUTION);
399,400c400
<              CONTEXT.ERROR_XML,
<              XMLFOREST(
---
>              XMLATTRIBUTES(
411,413c411,415
<              , CONTEXT.SYSTZ AS "sysTZ"
<              , TO_CHAR(CONTEXT.MINAVAILTIMEUTC,OMC_TIME_FORMAT) AS "minAvailTimeUTC"
<              , TO_CHAR(CONTEXT.MAXAVAILTIMEUTC,OMC_TIME_FORMAT) AS "maxAvailTimeUTC"
---
>              , TO_CHAR(ROUND(CONTEXT.SYSTZ,6)) AS "sysTZ"
>              , TO_CHAR(CONTEXT.MINAVAILTIMEUTC,OMC_TIME_FORMAT) 
>                   AS "minAvailTimeUTC"
>              , TO_CHAR(CONTEXT.MAXAVAILTIMEUTC,OMC_TIME_FORMAT)
>                   AS "maxAvailTimeUTC"
417a420
>              , CONTEXT.RESOLUTION AS "resolution"
422,423c425,426
<              , CONTEXT.MEMSIZEDAYS AS "memSizeDays"
<              , CONTEXT.MEMTZ AS "memTZ"
---
>              , TO_CHAR(ROUND(CONTEXT.MEMSIZEDAYS,6)) AS "memSizeDays"
>              , TO_CHAR(ROUND(CONTEXT.MEMTZ,6)) AS "memTZ"
426,428c429,431
<              , CONTEXT.DBID AS "dbid"
<              , CONTEXT.BEGINSNAPID AS "beginSnapID"
<              , CONTEXT.ENDSNAPID AS "endSnapID"
---
>              , TO_CHAR(CONTEXT.DBID) AS "dbid"
>              , TO_CHAR(CONTEXT.BEGINSNAPID) AS "beginSnapID"
>              , TO_CHAR(CONTEXT.ENDSNAPID) AS "endSnapID"
430,431c433,435
<              , TO_CHAR(CONTEXT.DISKENDTIMEUTC,OMC_TIME_FORMAT) AS "diskEndTimeUTC"
<              , CONTEXT.DISKTZ AS "diskTZ"
---
>              , TO_CHAR(CONTEXT.DISKENDTIMEUTC,OMC_TIME_FORMAT) 
>                   AS "diskEndTimeUTC"
>              , TO_CHAR(ROUND(CONTEXT.DISKTZ,6)) AS "diskTZ"
437c441
<            ))
---
>            ), CONTEXT.ERROR_XML)
478c482,483
<                            AWR_INFO IN VARCHAR, IGNORE_CPU_HISTORY IN VARCHAR)
---
>                            AWR_INFO IN VARCHAR, IGNORE_CPU_HISTORY IN VARCHAR,
>                            RESOLUTION IN VARCHAR)
527a533,543
> 
>     
>     IF LOWER(RESOLUTION) LIKE 'all%' OR LOWER(RESOLUTION) LIKE 'max%' THEN
>       CONTEXT.RESOLUTION := OMC_MAX_RESOLUTION;
>     ELSIF LOWER(RESOLUTION) LIKE 'low%' THEN
>       CONTEXT.RESOLUTION := OMC_LOW_RESOLUTION;
>     ELSIF LOWER(RESOLUTION) LIKE 'high%' THEN
>       CONTEXT.RESOLUTION := OMC_HIGH_RESOLUTION;
>     ELSE
>       CONTEXT.RESOLUTION := OMC_MED_RESOLUTION;
>     END IF;
571c587,588
<         OR (CONTEXT.LOCAL_CONDBID IS NOT NULL AND DBID = CONTEXT.LOCAL_DBID)) THEN
---
>         OR (CONTEXT.LOCAL_CONDBID IS NOT NULL 
>             AND DBID = CONTEXT.LOCAL_CONDBID)) THEN
619a637
>     L_BUCKETS NUMBER;
631c649,653
<       L_SIZE := ROUND(GREATEST(L_MIN_SIZE, L_DIFF_SEC / OMC_DEF_BUCKETS),0);
---
>       L_BUCKETS := 
>         (CASE WHEN CONTEXT.RESOLUTION = OMC_LOW_RESOLUTION THEN OMC_LOW_BUCKETS
>               WHEN CONTEXT.RESOLUTION = OMC_MED_RESOLUTION THEN OMC_MED_BUCKETS
>               ELSE OMC_HIGH_BUCKETS END);
>       L_SIZE := ROUND(GREATEST(L_MIN_SIZE, L_DIFF_SEC / L_BUCKETS),0);
900c922,923
<        , AWR_INFO IN VARCHAR)
---
>        , AWR_INFO IN VARCHAR
>        , RESOLUTION IN VARCHAR)
905c928
<          MINIMIZE_COST, AWR_INFO, 'n');
---
>          MINIMIZE_COST, AWR_INFO, 'n', RESOLUTION);
925c948,949
<        , IGNORE_CPU_HISTORY IN VARCHAR)
---
>        , IGNORE_CPU_HISTORY IN VARCHAR
>        , RESOLUTION IN VARCHAR)
930c954
<               MINIMIZE_COST, AWR_INFO, IGNORE_CPU_HISTORY);
---
>               MINIMIZE_COST, AWR_INFO, IGNORE_CPU_HISTORY, RESOLUTION);
967c991,992
<        , IGNORE_CPU_HISTORY IN VARCHAR)
---
>        , IGNORE_CPU_HISTORY IN VARCHAR
>        , RESOLUTION IN VARCHAR)
972c997
<          MINIMIZE_COST, AWR_INFO, IGNORE_CPU_HISTORY);
---
>          MINIMIZE_COST, AWR_INFO, IGNORE_CPU_HISTORY, RESOLUTION);
1570c1595
<    CONTEXT := INITBASECONTEXT(P_DBID,'n','n','n',P_INST_NUM,'n','y','n');
---
>    CONTEXT := INITBASECONTEXT(P_DBID,'n','n','n',P_INST_NUM,'n','y','n','low');
1926c1951
<        , 'n', 'n', IGNORE_CPU_HISTORY);
---
>        , 'n', 'n', IGNORE_CPU_HISTORY, 'low');
2159a2185,2190
>       
>       
>       
>       
>       
>       
2188c2219
<       AND  a.snap_id <= @E_SNAP@
---
>       AND  a.snap_id <= @E_SNAP@ + 5
2287a2319
>     L_CONTEXT_XML XMLTYPE;
2382a2415
>     L_CONTEXT_XML := CONTEXTTOXML(CONTEXT);
2390c2423
<              ,L_TIMING ,P_INPUT, L_CPU, L_AWR, L_BASE)
---
>              ,L_TIMING, L_CONTEXT_XML, P_INPUT, L_CPU, L_AWR, L_BASE)
2604c2637
<       AND  a.snap_id <= @E_SNAP@
---
>       AND  a.snap_id <= @E_SNAP@ + 5
2805a2839,2840
>     L_IS_OLD      VARCHAR2(10);
>     L_IS_PDB      VARCHAR2(10);
2806a2842,2843
>     L_CONDBID_COL VARCHAR2(10);
>     L_LOCAL_SOURCE VARCHAR2(10);
2812a2850,2859
>     IF CONTEXT.LOCAL_COMP_VER >= VER_12_2 THEN
>       L_IS_OLD := '''N''';
>     ELSE 
>       L_IS_OLD := '''Y''';
>     END IF;
>     IF CONTEXT.LOCAL_IS_PDB THEN
>       L_IS_PDB := '''Y''';
>     ELSE
>       L_IS_PDB := '''N''';
>     END IF;
2990,2991c3037,3039
<                                           sqlid as "v"),
<                                XMLCDATA(sql_text)))) as xml
---
>                                           sqlid as "v",
>                                extractvalue(sql_text, '/a/c') as "op"),
>                                XMLCDATA(extractvalue(sql_text, '/a/s'))))) as xml
2998,2999c3046,3052
<     ' sys.dbms_ash.fetch_sqltext_local(t.sqlid, ' || 
<             CONTEXT.LOCAL_DBID || ',' || L_TIME_LIMIT || ')');
---
>     ' sys.dbms_ash.fetch_sqltext(t.sqlid, ' 
>             || CONTEXT.LOCAL_DBID || ',' 
>             || NVL(TO_CHAR(CONTEXT.LOCAL_CONDBID),'NULL') || ',' 
>             || '''Y''' || ',' 
>             || L_IS_PDB || ',' 
>             || L_IS_OLD || ',' 
>             || L_TIME_LIMIT || ')');
3003,3004c3056,3062
<     ' sys.dbms_ash.fetch_sqltext_awr(t.sqlid, ' || 
<         CONTEXT.LOCAL_DBID || ',' || L_USE_PDB_AWR || ',' || L_TIME_LIMIT || ')');
---
>     ' sys.dbms_ash.fetch_sqltext(t.sqlid, ' 
>             || CONTEXT.DBID || ',' 
>             || 'NULL' || ',' 
>             || '''N''' || ',' 
>             || L_IS_PDB || ',' 
>             || L_IS_OLD || ',' 
>             || L_TIME_LIMIT || ')');
3671c3729,3731
<                                           n.name as "name")))) as xml
---
>                                           extractvalue(n.name,'/a/n') as "name",
>                                           extractvalue(n.name,'/a/t') as "type"
>                     )))) as xml
3673a3734,3735
>     
>     
3679,3688c3741
<       IF CONTEXT.IS_LOCAL THEN
<         L_TEXT := REPLACE(L_TEXT, '%fetch%',
<           ' sys.dbms_ash.fetch_obj_name_local(object, '
<           || CONTEXT.DBID || ', con_dbid,' || L_TIME_LIMIT || ')'); 
<       ELSE
<         L_TEXT := REPLACE(L_TEXT, '%fetch%',
<           ' sys.dbms_ash.fetch_obj_name_awr(object, '
<           || CONTEXT.DBID || ', con_dbid' || 
<              L_USE_PDB_AWR || ',' || L_TIME_LIMIT || ')'); 
<       END IF;
---
>       L_CONDBID_COL := 'con_dbid';
3693,3696c3746,3765
<       IF CONTEXT.IS_LOCAL THEN
<         L_TEXT := REPLACE(L_TEXT, '%fetch%',
<           ' sys.dbms_ash.fetch_obj_name_local(object, '
<           || CONTEXT.DBID || ', NULL,' || L_TIME_LIMIT || ')');
---
>       L_CONDBID_COL := 'NULL';
>     END IF;
>     
> 
>     IF CONTEXT.IS_LOCAL THEN 
>       IF CONTEXT.IS_CDB_ROOT THEN
>         L_LOCAL_SOURCE := '''ROOT''';
>       ELSIF CONTEXT.LOCAL_IS_PDB THEN
>         L_LOCAL_SOURCE := '''PDB''';
>         L_CONDBID_COL := TO_CHAR(CONTEXT.LOCAL_CONDBID);
>       ELSE 
>         L_LOCAL_SOURCE := '''STANDARD''';
>       END IF;
>       L_TEXT := REPLACE(L_TEXT, '%fetch%',
>           ' sys.dbms_ash.fetch_obj_name(object, '
>           || CONTEXT.LOCAL_DBID || ',' || L_CONDBID_COL || ',''Y'','
>           || L_LOCAL_SOURCE || ',' || L_IS_OLD || ',' || L_TIME_LIMIT || ')');
>     ELSE 
>       IF CONTEXT.LOCAL_IS_PDB THEN
>         L_LOCAL_SOURCE := '''PDB''';
3698,3701c3767
<         L_TEXT := REPLACE(L_TEXT, '%fetch%',
<           ' sys.dbms_ash.fetch_obj_name_awr(object, '
<           || CONTEXT.DBID || ', NULL,' || L_USE_PDB_AWR || ',' || 
<              L_TIME_LIMIT || ')');
---
>         L_LOCAL_SOURCE := '''STANDARD''';
3702a3769,3772
>       L_TEXT := REPLACE(L_TEXT, '%fetch%',
>           ' sys.dbms_ash.fetch_obj_name(object, '
>           || CONTEXT.LOCAL_DBID || ',' || L_CONDBID_COL || ',''N'','
>           || L_LOCAL_SOURCE || ',' || L_IS_OLD || ',' || L_TIME_LIMIT || ')');
3794c3864
<                                              , n.common as "c" )))) as xml
---
>                                              , n.common as "co" )))) as xml
4009c4079
<         TORET := DBMS_ASSERT.SIMPLE_SQL_NAME(FROMTABLE);
---
>         TORET := SYS.DBMS_ASSERT.SIMPLE_SQL_NAME(FROMTABLE);
4105a4176
>     L_ROWS_PER_BUCKET NUMBER;
4134c4205,4211
<     CONTEXT.EXP_ROW_COUNT := OMC_DEF_ROWS_PER_BUCKET * CONTEXT.BUCKETCOUNT;
---
>     L_ROWS_PER_BUCKET := 
>         (CASE WHEN CONTEXT.RESOLUTION = OMC_LOW_RESOLUTION 
>                    THEN OMC_LOW_ROWS_PER_BUCKET
>               WHEN CONTEXT.RESOLUTION = OMC_MED_RESOLUTION 
>                    THEN OMC_MED_ROWS_PER_BUCKET
>               ELSE OMC_HIGH_ROWS_PER_BUCKET END);
>     CONTEXT.EXP_ROW_COUNT := L_ROWS_PER_BUCKET * CONTEXT.BUCKETCOUNT;
4384c4461
<       AND  a.snap_id <= @E_SNAP@
---
>       AND  a.snap_id <= @E_SNAP@ + 5
4771a4849
>     L_CONTEXT_XML XMLTYPE;
4817c4895,4896
<     IF CONTEXT.EXP_ROW_COUNT IS NULL OR CONTEXT.EXP_ROW_COUNT <= 1 THEN
---
>     IF CONTEXT.EXP_ROW_COUNT IS NULL OR CONTEXT.EXP_ROW_COUNT <= 1 
>        OR CONTEXT.RESOLUTION = OMC_MAX_RESOLUTION THEN
4840a4920
>     L_CONTEXT_XML := CONTEXTTOXML(CONTEXT);
4851c4931
<               L_SYS_INFO,L_TIMING, P_INPUT,
---
>               L_SYS_INFO,L_TIMING, L_CONTEXT_XML, P_INPUT,
4888a4969,4970
> 
>   
4892,4894c4974,5007
<   FUNCTION FETCH_SQLTEXT_LOCAL(P_SQLID IN VARCHAR, P_DBID IN NUMBER,
<                                P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR
---
>   FUNCTION CONSTRUCT_SQL_ELEMENT(P_SQLTEXT IN VARCHAR, P_COMMAND_ID IN NUMBER)
>   RETURN   XMLTYPE
>   IS
>     L_RESULT XMLTYPE;
>     L_COMMAND_NAME VARCHAR2(64);
>   BEGIN
>     IF P_SQLTEXT IS NULL THEN
>       RETURN NULL;
>     END IF;
>     IF P_COMMAND_ID IS NOT NULL THEN 
>       SELECT MAX(COMMAND_NAME) INTO L_COMMAND_NAME
>       FROM   SYS.V_$SQLCOMMAND
>       WHERE  COMMAND_TYPE = P_COMMAND_ID;
>     END IF;
>   
>     SELECT XMLELEMENT("a", 
>             XMLELEMENT("c", L_COMMAND_NAME),
>             XMLELEMENT("s", XMLCDATA(P_SQLTEXT)))
>     INTO   L_RESULT
>     FROM   SYS.DUAL;
> 
>     RETURN L_RESULT;
>   END CONSTRUCT_SQL_ELEMENT;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION FETCH_SQLTEXT_MEMORY(P_SQLID IN VARCHAR, P_TIME_LIMIT IN BOOLEAN)
>   RETURN   XMLTYPE
4896a5010
>     L_COMMAND_ID NUMBER;
4900c5014
<     IF P_TIME_LIMIT = 'Y' AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
---
>     IF P_TIME_LIMIT AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
4907,4914c5021,5027
< ' SELECT max(substr(sql_text,1,:1))
<     FROM   v$sql
<     WHERE  sql_id = :2
<       AND  rownum <= 1 '
<     INTO L_TEXT USING OMC_DEF_SQLTEXT_LEN, P_SQLID;
< 
< 
< 
---
> ' SELECT max(substr(sql_text,1,:1)), max(command_type)
>     FROM (
>      SELECT sql_text, command_type
>      FROM   sys.v_$sql
>      WHERE  sql_id = :2
>        AND  rownum <= 1)'
>     INTO L_TEXT, L_COMMAND_ID USING OMC_DEF_SQLTEXT_LEN, P_SQLID;
4918c5031
<       RETURN FETCH_SQLTEXT_AWR(P_SQLID, P_DBID, 'N', P_TIME_LIMIT);
---
>       RETURN NULL;
4920,4921c5033,5037
<     RETURN STR_TO_ASCII(L_TEXT);
<   END FETCH_SQLTEXT_LOCAL;
---
>     RETURN CONSTRUCT_SQL_ELEMENT(STR_TO_ASCII(L_TEXT), L_COMMAND_ID);
>     
>     
>     EXCEPTION WHEN OTHERS THEN RETURN NULL;
>   END FETCH_SQLTEXT_MEMORY;
4922a5039,5051
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
4924,4925c5053,5054
<                              P_IS_PDB IN VARCHAR, P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR
---
>                              P_SOURCE IN VARCHAR, P_TIME_LIMIT IN BOOLEAN)
>   RETURN   XMLTYPE
4926a5056
>     L_SQLTEXT VARCHAR2(4000);
4927a5058
>     L_COMMAND_ID NUMBER;
4931c5062
<     IF P_TIME_LIMIT = 'Y' AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
---
>     IF P_TIME_LIMIT  AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
4937,4954c5068,5079
<     IF P_IS_PDB = 'N' THEN
<       EXECUTE IMMEDIATE 
< 'SELECT max(dbms_lob.substr(sql_text,:1,1))
<  FROM   dba_hist_sqltext 
<  WHERE  sql_id = :2
<    AND  dbid = :3
<    AND  rownum <= 1'
<       INTO L_TEXT
<       USING OMC_DEF_SQLTEXT_LEN, P_SQLID, P_DBID;
<     ELSE 
<       EXECUTE IMMEDIATE 
< 'SELECT max(dbms_lob.substr(sql_text,:1,1))
<  FROM   awr_pdb_sqltext 
<  WHERE  sql_id = :2
<    AND  dbid = :3
<    AND  rownum <= 1'
<       INTO L_TEXT
<       USING OMC_DEF_SQLTEXT_LEN, P_SQLID, P_DBID;
---
>     L_SQLTEXT := 
> 'SELECT max(dbms_lob.substr(sql_text,:1,1)), MAX(command_type)
>  FROM   (
>   SELECT sql_text, command_type
>   FROM   dba_hist_sqltext 
>   WHERE  sql_id = :2
>     AND  dbid = :3
>     AND  rownum <= 1)';
>     IF P_SOURCE = 'PDB' THEN
>       L_SQLTEXT := REPLACE(L_SQLTEXT, 'dba_hist_', 'awr_pdb_');
>     ELSIF P_SOURCE = 'ROOT' THEN
>       L_SQLTEXT := REPLACE(L_SQLTEXT, 'dba_hist_', 'awr_root_');
4955a5081,5085
> 
>     EXECUTE IMMEDIATE L_SQLTEXT
>     INTO L_TEXT, L_COMMAND_ID
>     USING OMC_DEF_SQLTEXT_LEN, P_SQLID, P_DBID;
> 
4957a5088,5169
>     IF L_TEXT IS NULL THEN
>       RETURN NULL;
>     END IF;
>     RETURN CONSTRUCT_SQL_ELEMENT(STR_TO_ASCII(L_TEXT), L_COMMAND_ID);
>     
>     
>     EXCEPTION WHEN OTHERS THEN RETURN NULL;
>   END FETCH_SQLTEXT_AWR;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION FETCH_SQLTEXT(P_SQLID IN VARCHAR,
>                          P_DBID IN NUMBER, P_CON_DBID IN NUMBER,
>                          P_IS_LOCAL IN VARCHAR, P_IS_PDB IN VARCHAR,
>                          P_IS_OLD IN VARCHAR, P_TIME_LIMIT IN VARCHAR)
>   RETURN   XMLTYPE
>   IS
>     L_IS_LOCAL BOOLEAN;
>     L_IS_PDB   BOOLEAN;
>     L_IS_OLD   BOOLEAN;
>     L_TIME_LIMIT BOOLEAN;
>     L_RESULT XMLTYPE := NULL;
>   BEGIN
>     IF P_DBID IS NULL THEN 
>       RETURN NULL;
>     END IF;
>     IF UPPER(P_IS_LOCAL) = 'Y' THEN 
>       L_IS_LOCAL := TRUE; 
>     ELSE 
>       L_IS_LOCAL := FALSE; 
>     END IF;
>     IF UPPER(P_IS_PDB) = 'Y' THEN 
>       L_IS_PDB := TRUE; 
>     ELSE 
>       L_IS_PDB := FALSE; 
>     END IF;
>     IF UPPER(P_IS_OLD) = 'Y' THEN 
>       L_IS_OLD := TRUE; 
>     ELSE 
>       L_IS_OLD := FALSE; 
>     END IF;
>     IF UPPER(P_TIME_LIMIT) = 'Y' THEN 
>       L_TIME_LIMIT := TRUE; 
>     ELSE 
>       L_TIME_LIMIT := FALSE; 
>     END IF;
4958a5171,5189
>     IF L_IS_LOCAL THEN 
>        L_RESULT := FETCH_SQLTEXT_MEMORY(P_SQLID, L_TIME_LIMIT);
>        IF L_RESULT IS NOT NULL THEN 
>          RETURN L_RESULT; 
>        END IF;
>        IF ((NOT L_IS_PDB) OR (L_IS_PDB AND L_IS_OLD)) THEN 
>          L_RESULT := FETCH_SQLTEXT_AWR(P_SQLID, P_DBID, 'DBA', L_TIME_LIMIT);
>        ELSE 
>          L_RESULT := FETCH_SQLTEXT_AWR(P_SQLID, P_CON_DBID, 'PDB', L_TIME_LIMIT);
>          IF L_RESULT IS NOT NULL THEN 
>            RETURN L_RESULT; 
>          END IF;
>          L_RESULT := FETCH_SQLTEXT_AWR(P_SQLID, P_DBID, 'ROOT', L_TIME_LIMIT);
>        END IF;
>      ELSIF L_IS_OLD THEN 
>        L_RESULT := FETCH_SQLTEXT_AWR(P_SQLID, P_DBID, 'DBA', L_TIME_LIMIT);
>      ELSE 
>        L_RESULT := FETCH_SQLTEXT_AWR(P_SQLID, P_DBID, 'PDB', L_TIME_LIMIT);
>      END IF;
4959a5191,5192
>      RETURN L_RESULT;
>   END FETCH_SQLTEXT;
4961,4962c5194,5199
<     RETURN STR_TO_ASCII(L_TEXT);
<   END FETCH_SQLTEXT_AWR;
---
>   
>   
>   
>   
>   
>   
4964,4966c5201,5230
<   FUNCTION FETCH_OBJ_NAME_LOCAL(P_OBJ_ID IN NUMBER, P_DBID IN NUMBER,
<                                 P_CON_DBID IN NUMBER, P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR
---
>   
>   
>   
>   
>   FUNCTION CONSTRUCT_OBJ_ELEMENT(P_NAME IN VARCHAR, P_TYPE IN VARCHAR)
>   RETURN   XMLTYPE
>   IS
>     L_RESULT XMLTYPE;
>   BEGIN
>     IF P_NAME IS NULL THEN
>       RETURN NULL;
>     END IF;
>     SELECT XMLELEMENT("a",
>             XMLELEMENT("n", P_NAME),
>             XMLELEMENT("t", P_TYPE))
>     INTO   L_RESULT
>     FROM   SYS.DUAL;
>     RETURN L_RESULT;
>   END CONSTRUCT_OBJ_ELEMENT;
> 
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION FETCH_OBJ_NAME_DICT(P_OBJ_ID IN NUMBER, P_CON_DBID IN NUMBER, 
>                                P_TIME_LIMIT IN BOOLEAN)
>   RETURN   XMLTYPE
4968a5233
>     L_TYPE VARCHAR2(64);
4971a5237
>     L_RESULT XMLTYPE;
4973,4977c5239
<     L_NAME := FETCH_OBJ_NAME_AWR(P_OBJ_ID,P_DBID,P_CON_DBID,'N',P_TIME_LIMIT);
<     IF L_NAME IS NOT NULL THEN
<       RETURN STR_TO_ASCII(L_NAME);
<     END IF;
<     IF P_TIME_LIMIT = 'Y' AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
---
>     IF P_TIME_LIMIT AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
4984,4988c5246,5253
<            decode(subobject_name, NULL, NULL, '.' || subobject_name)) 
<     FROM   cdb_objects
<     WHERE  object_id = :1
<       AND  con_id = con_dbid_to_id(:2)
<       AND  rownum <= 1 ]';
---
>            decode(subobject_name, NULL, NULL, '.' || subobject_name)),
>            max(object_type) 
>     FROM   (
>       SELECT owner, object_name, subobject_name, object_type
>       FROM   cdb_objects
>       WHERE  object_id = :1
>         AND  con_id = con_dbid_to_id(:2)
>         AND  rownum <= 1 )]';
4990c5255
<       INTO L_NAME
---
>       INTO L_NAME, L_TYPE
4995,4998c5260,5266
<            decode(subobject_name, NULL, NULL, '.' || subobject_name)) 
<     FROM   dba_objects
<     WHERE  object_id = :1
<       AND  rownum <= 1 ]';
---
>            decode(subobject_name, NULL, NULL, '.' || subobject_name)),
>            max(object_type) 
>     FROM   (
>       SELECT owner, object_name, subobject_name, object_type
>       FROM   dba_objects
>       WHERE  object_id = :1
>         AND  rownum <= 1) ]';
5000c5268
<       INTO L_NAME
---
>       INTO L_NAME, L_TYPE
5003,5009c5271,5282
<     L_SECS := TIMING_TO_SECONDS(L_T, SYSTIMESTAMP);
<     ADD_INFO_TIME := ADD_INFO_TIME + L_SECS;
< 
< 
< 
<     RETURN STR_TO_ASCII(L_NAME);
<   END FETCH_OBJ_NAME_LOCAL;
---
>     IF P_TIME_LIMIT THEN
>       L_SECS := TIMING_TO_SECONDS(L_T, SYSTIMESTAMP);
>       ADD_INFO_TIME := ADD_INFO_TIME + L_SECS;
>     END IF;
>     IF L_NAME IS NULL THEN
>       RETURN NULL;
>     END IF;
>     RETURN CONSTRUCT_OBJ_ELEMENT(STR_TO_ASCII(L_NAME), L_TYPE);
>     
>     
>     EXCEPTION WHEN OTHERS THEN RETURN NULL;
>   END FETCH_OBJ_NAME_DICT;
5010a5284,5294
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
5012,5014c5296,5298
<                               P_CON_DBID IN NUMBER, P_IS_PDB IN VARCHAR,
<                               P_TIME_LIMIT IN VARCHAR)
<   RETURN   VARCHAR
---
>                               P_CON_DBID IN NUMBER, P_SOURCE IN VARCHAR,
>                               P_TIME_LIMIT IN BOOLEAN)
>   RETURN   XMLTYPE
5016a5301
>     L_TYPE VARCHAR2(64);
5018c5303
<     L_T    TIMESTAMP := SYSTIMESTAMP;
---
>     L_T    TIMESTAMP;
5021c5306
<     IF P_TIME_LIMIT = 'Y' AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
---
>     IF P_TIME_LIMIT AND ADD_INFO_TIME >= ADD_INFO_BUDGET THEN 
5023a5309
>     L_T := SYSTIMESTAMP;
5025c5311
< q'[SELECT max(name) 
---
> q'[SELECT max(name), max(object_type) 
5028,5029c5314,5316
<            decode(subobject_name, NULL, NULL, '.' || subobject_name) as name
<     FROM   @AWRTAB@seg_stat_obj
---
>            decode(subobject_name, NULL, NULL, '.' || subobject_name) as name,
>            object_type
>     FROM   dba_hist_seg_stat_obj
5034,5037c5321,5325
<     IF P_IS_PDB = 'Y' THEN
<       L_TEXT := REPLACE(L_TEXT, '@AWRTAB@', 'awr_pdb_');
<     ELSE
<       L_TEXT := REPLACE(L_TEXT, '@AWRTAB@', 'dba_hist_');
---
>     IF P_SOURCE = 'PDB' THEN
>       L_TEXT := REPLACE(L_TEXT, 'dba_hist_', 'awr_pdb_');
>     END IF;
>     IF P_SOURCE = 'ROOT' THEN
>       L_TEXT := REPLACE(L_TEXT, 'dba_hist_', 'awr_root_');
5042c5330
<       INTO L_NAME
---
>       INTO L_NAME, L_TYPE
5047c5335
<       INTO L_NAME
---
>       INTO L_NAME, L_TYPE
5050,5051c5338,5349
<     L_SECS := TIMING_TO_SECONDS(L_T, SYSTIMESTAMP);
<     ADD_INFO_TIME := ADD_INFO_TIME + L_SECS;
---
>     IF P_TIME_LIMIT THEN
>       L_SECS := TIMING_TO_SECONDS(L_T, SYSTIMESTAMP);
>       ADD_INFO_TIME := ADD_INFO_TIME + L_SECS;
>     END IF;
>     IF L_NAME IS NULL THEN
>       RETURN NULL;
>     END IF;
>     RETURN CONSTRUCT_OBJ_ELEMENT(STR_TO_ASCII(L_NAME), L_TYPE);
>     
>     
>     EXCEPTION WHEN OTHERS THEN RETURN NULL;
>   END FETCH_OBJ_NAME_AWR;
5052a5351,5421
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION FETCH_OBJ_NAME(P_OBJ_ID IN NUMBER, P_DBID IN NUMBER,
>                           P_CON_DBID IN NUMBER, P_IS_LOCAL IN VARCHAR,
>                           P_LOCAL_TYPE IN VARCHAR, P_IS_OLD IN VARCHAR,
>                           P_TIME_LIMIT IN VARCHAR)
>   RETURN   XMLTYPE
>   IS
>     L_RESULT XMLTYPE := NULL;
>     L_TIME_LIMIT BOOLEAN;
>   BEGIN
>     IF UPPER(P_TIME_LIMIT) = 'Y' THEN
>       L_TIME_LIMIT := TRUE;
>     ELSE
>       L_TIME_LIMIT := FALSE;
>     END IF;
5053a5423,5466
>     IF UPPER(P_IS_LOCAL) = 'Y' THEN 
>       IF UPPER(P_LOCAL_TYPE) = 'ROOT' THEN 
>         L_RESULT := FETCH_OBJ_NAME_DICT(P_OBJ_ID, P_CON_DBID, L_TIME_LIMIT);
>         IF L_RESULT IS NOT NULL THEN
>           RETURN L_RESULT;
>         END IF;
>         L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_DBID, P_CON_DBID, 
>                                         'HIST', L_TIME_LIMIT);
>       ELSIF UPPER(P_LOCAL_TYPE) = 'PDB' THEN 
>         IF UPPER(P_IS_OLD) = 'Y' THEN 
>           L_RESULT := FETCH_OBJ_NAME_DICT(P_OBJ_ID, NULL, L_TIME_LIMIT);
>           IF L_RESULT IS NOT NULL THEN
>             RETURN L_RESULT;
>           END IF;
>           L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_DBID, P_CON_DBID, 
>                                           'HIST', L_TIME_LIMIT);
>         ELSE 
>           L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_CON_DBID, NULL, 
>                                           'PDB', L_TIME_LIMIT);
>           IF L_RESULT IS NOT NULL THEN
>             RETURN L_RESULT;
>           END IF;
>           L_RESULT := FETCH_OBJ_NAME_DICT(P_OBJ_ID, NULL, L_TIME_LIMIT);
>           IF L_RESULT IS NOT NULL THEN
>             RETURN L_RESULT;
>           END IF;
>           L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_DBID, P_CON_DBID, 
>                                           'ROOT', L_TIME_LIMIT);
>         END IF;
>       ELSE 
>         L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_DBID, NULL, 
>                                         'HIST', L_TIME_LIMIT);
>         IF L_RESULT IS NOT NULL THEN
>           RETURN L_RESULT;
>         END IF;
>         L_RESULT := FETCH_OBJ_NAME_DICT(P_OBJ_ID, NULL, L_TIME_LIMIT);
>       END IF;     
>     ELSIF UPPER(P_LOCAL_TYPE) = 'PDB' THEN 
>       L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_DBID, P_CON_DBID, 
>                                       'PDB', L_TIME_LIMIT);
>     ELSE 
>       L_RESULT := FETCH_OBJ_NAME_AWR(P_OBJ_ID, P_DBID, P_CON_DBID, 
>                                       'HIST', L_TIME_LIMIT);
>     END IF;
5055,5056c5468,5469
<     RETURN STR_TO_ASCII(L_NAME);
<   END FETCH_OBJ_NAME_AWR;
---
>     RETURN L_RESULT;
>   END FETCH_OBJ_NAME;  
5057a5471,5479
>   
>   
>   
>   
>   
>   
>   
>   
>   
5091,5093d5512
< 
< 
< 
5094a5514,5516
>     
>     
>     EXCEPTION WHEN OTHERS THEN RETURN NULL;
5096a5519,5527
>   
>   
>   
>   
>   
>   
>   
>   
>   
5128,5130d5558
< 
< 
< 
5131a5560,5562
>     
>     
>     EXCEPTION WHEN OTHERS THEN RETURN NULL;
5208a5640
>     L_RESOLUTION      VARCHAR2(100);
5227a5660
>         ,T.RESOLUTION AS RESOLUTION
5240a5674
>                    ,RESOLUTION VARCHAR2(100) PATH 'resolution'
5267a5702
>       L_RESOLUTION      := A.RESOLUTION;
5314c5749
<             L_AWR_INFO);
---
>             L_AWR_INFO, L_RESOLUTION);
5318c5753,5754
<             L_SHOW_SQL, L_VERBOSE_XML, L_INSTANCE_NUMBER, L_AWR_INFO);
---
>             L_SHOW_SQL, L_VERBOSE_XML, L_INSTANCE_NUMBER, L_AWR_INFO, 
>             L_RESOLUTION);
5322c5758,5759
<             L_SHOW_SQL, L_VERBOSE_XML, L_INSTANCE_NUMBER, L_AWR_INFO);
---
>             L_SHOW_SQL, L_VERBOSE_XML, L_INSTANCE_NUMBER, L_AWR_INFO,
>             L_RESOLUTION);
5328c5765,5766
<             L_INCLUDE_BG, L_INSTANCE_NUMBER, L_MINIMIZE_COST);
---
>             L_INCLUDE_BG, L_INSTANCE_NUMBER, L_MINIMIZE_COST,
>             L_RESOLUTION);
5333c5771,5772
<             L_INCLUDE_BG, L_INSTANCE_NUMBER, L_MINIMIZE_COST);
---
>             L_INCLUDE_BG, L_INSTANCE_NUMBER, L_MINIMIZE_COST,
>             L_RESOLUTION);
5338c5777,5778
<             L_MINIMIZE_COST);
---
>             L_MINIMIZE_COST,
>             L_RESOLUTION);
5344c5784,5785
<             L_INCLUDE_BG, L_INSTANCE_NUMBER);
---
>             L_INCLUDE_BG, L_INSTANCE_NUMBER,
>             L_RESOLUTION);
5349c5790,5791
<             L_INCLUDE_BG, L_INSTANCE_NUMBER);
---
>             L_INCLUDE_BG, L_INSTANCE_NUMBER,
>             L_RESOLUTION);
5353c5795,5796
<             L_SHOW_SQL, L_VERBOSE_XML, L_INCLUDE_BG, L_INSTANCE_NUMBER);
---
>             L_SHOW_SQL, L_VERBOSE_XML, L_INCLUDE_BG, L_INSTANCE_NUMBER,
>             L_RESOLUTION);
5403c5846,5847
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5411c5855,5856
<                NVL(AWR_INFO,'n'), NVL(IGNORE_CPU_HISTORY,'n'));
---
>                NVL(AWR_INFO,'n'), NVL(IGNORE_CPU_HISTORY,'n'),
>                NVL(RESOLUTION,'medium'));
5418a5864
>             ,NVL(RESOLUTION,'medium') AS "resolution"
5450c5896,5897
<     , AWR_INFO IN VARCHAR2 := 'n')
---
>     , AWR_INFO IN VARCHAR2 := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5459c5906,5907
<                      INSTANCE_NUMBER,'n',NVL(AWR_INFO,'n'));
---
>                      INSTANCE_NUMBER,'n',NVL(AWR_INFO,'n'),
>                      NVL(RESOLUTION,'medium'));
5467a5916
>             ,NVL(RESOLUTION,'medium') AS "resolution"
5499c5948,5949
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5509c5959,5960
<                   NVL(IGNORE_CPU_HISTORY,'n'));
---
>                   NVL(IGNORE_CPU_HISTORY,'n'),
>                   NVL(RESOLUTION,'medium'));
5519a5971
>             ,NVL(RESOLUTION,'medium') AS "resolution"
5549c6001,6002
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5561c6014,6015
<                    MINIMIZE_COST,'n',IGNORE_CPU_HISTORY);
---
>                    MINIMIZE_COST,'n',IGNORE_CPU_HISTORY,
>                    NVL(RESOLUTION,'medium'));
5570a6025
>             ,RESOLUTION AS "resolution"
5614c6069,6070
<     , MINIMIZE_COST   IN VARCHAR := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5627c6083,6084
<                      INSTANCE_NUMBER, MINIMIZE_COST,'n');
---
>                      INSTANCE_NUMBER, MINIMIZE_COST,'n',
>                      NVL(RESOLUTION,'medium'));
5637a6095
>             ,RESOLUTION AS "resolution"
5679c6137,6138
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5692c6151,6152
<                   MINIMIZE_COST,'n',IGNORE_CPU_HISTORY);
---
>                   MINIMIZE_COST,'n',IGNORE_CPU_HISTORY,
>                   NVL(RESOLUTION,'medium'));
5704a6165
>             ,RESOLUTION AS "resolution"
5741c6202,6203
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5748c6210,6211
<               NVL(IGNORE_CPU_HISTORY,'n'));
---
>               NVL(IGNORE_CPU_HISTORY,'n'),
>               NVL(RESOLUTION,'medium'));
5775c6238,6239
<     , INSTANCE_NUMBER IN NUMBER := NULL)
---
>     , INSTANCE_NUMBER IN NUMBER := NULL
>     , RESOLUTION IN VARCHAR2 := 'medium')
5781c6245,6246
<               NVL(INCLUDE_BG,'n'), INSTANCE_NUMBER, 'n');
---
>               NVL(INCLUDE_BG,'n'), INSTANCE_NUMBER, 'n',
>               NVL(RESOLUTION,'medium'));
5808c6273,6274
<     , IGNORE_CPU_HISTORY IN VARCHAR := 'n')
---
>     , IGNORE_CPU_HISTORY IN VARCHAR := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5816c6282,6283
<               NVL(IGNORE_CPU_HISTORY,'n'));
---
>               NVL(IGNORE_CPU_HISTORY,'n'),
>               NVL(RESOLUTION,'medium'));
5839c6306,6307
<     , MINIMIZE_COST   IN VARCHAR2 := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR2 := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5845c6313,6314
<               NVL(INCLUDE_BG,'n'), INSTANCE_NUMBER, NVL(MINIMIZE_COST,'n'),'n');
---
>               NVL(INCLUDE_BG,'n'), INSTANCE_NUMBER, NVL(MINIMIZE_COST,'n'),'n',
>               NVL(RESOLUTION,'medium'));
5873c6342,6343
<     , MINIMIZE_COST   IN VARCHAR2 := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR2 := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5879c6349,6350
<               NVL(INCLUDE_BG,'n'), INSTANCE_NUMBER, NVL(MINIMIZE_COST,'n'));
---
>               NVL(INCLUDE_BG,'n'), INSTANCE_NUMBER, NVL(MINIMIZE_COST,'n'),
>               NVL(RESOLUTION,'medium'));
5907c6378,6379
<     , MINIMIZE_COST   IN VARCHAR2 := 'n')
---
>     , MINIMIZE_COST   IN VARCHAR2 := 'n'
>     , RESOLUTION IN VARCHAR2 := 'medium')
5914c6386,6387
<               NVL(MINIMIZE_COST,'n'),'n');
---
>               NVL(MINIMIZE_COST,'n'),'n',
>               NVL(RESOLUTION,'medium'));
SYS.DBMS_AUTO_INDEX - PACKAGE BODY (19.6RUR):
457a458,485
>  
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>   PROCEDURE DDL_EXECUTE_CALLOUT(
>     STMT     IN      VARCHAR2)
>   IS
>   EXTERNAL NAME "kapiDDLExecute" WITH CONTEXT
>   PARAMETERS(CONTEXT,
>     STMT     OCISTRING,      STMT         INDICATOR       SB4)
>   LIBRARY DBMS_AUTO_INDEX_LIB;
> 
527c555,558
<         EXECUTE IMMEDIATE STMT;
---
>         
>         
>         
>         DDL_EXECUTE_CALLOUT('/*AUTO_INDEX:ddl*/' || STMT);
SYS.DBMS_AUTO_INDEX_INTERNAL - PACKAGE BODY (RU):
323a324,325
>   
>   
327c329
<                                                       AI_STS_CAPTURE_TASK_ON;
---
>                                                       AI_STS_CAPTURE_TASK_OFF;
SYS.DBMS_DBFS_CONTENT - PACKAGE BODY (RU):
5485a5486,5496
>         IF (TRCLVL = 0) THEN
>             EXECUTE IMMEDIATE 'alter session set "_kdlu_trace_system"=0';
>             EXECUTE IMMEDIATE 'alter session set "_kdlu_trace_layer"=0';
>             EXECUTE IMMEDIATE 'alter session set "_securefile_timers"=FALSE';
>         ELSE
>             EXECUTE IMMEDIATE 'alter session set "_kdlu_trace_system"=1532';
>             EXECUTE IMMEDIATE 'alter session set "_kdlu_trace_layer"=1048576';
>             EXECUTE IMMEDIATE 'alter session set "_securefile_timers"=TRUE';
>         END IF;             
>         
> 
5513a5525
>         TIME        TIMESTAMP := SYSTIMESTAMP;
5517a5530,5532
>                 TO_CHAR(TIME, 'HH24:MI:SS') ||
>                 '# 
>                 '         ||
SYS.DBMS_HADOOP - PACKAGE BODY (RU):
158,159c158,159
< 
< 
---
>   
>   
163a164,173
> 
>   IF (INSTR(TEXT_OF_DDL, 'UTL_RAW.CAST_TO_RAW') > 0) THEN
>     TEXT_OF_DDL := DBMS_HADOOP_INTERNAL.EVAL_PART_KEY_OPERATOR(TEXT_OF_DDL, 'UTL_RAW.CAST_TO_RAW');
>   END IF;
>   IF (INSTR(TEXT_OF_DDL, 'TO_DATE') > 0) THEN
>     TEXT_OF_DDL := DBMS_HADOOP_INTERNAL.EVAL_PART_KEY_OPERATOR(TEXT_OF_DDL, 'TO_DATE');
>   END IF;
>   IF (INSTR(TEXT_OF_DDL, 'TO_TIMESTAMP') > 0) THEN
>     TEXT_OF_DDL := DBMS_HADOOP_INTERNAL.EVAL_PART_KEY_OPERATOR(TEXT_OF_DDL, 'TO_TIMESTAMP');
>   END IF;
SYS.DBMS_HADOOP_INTERNAL - PACKAGE BODY (RU):
322a323
>     TMP_DDL CLOB := ORIG_DDL;
324a326,332
>    
>    
>    
>    TMP_DDL := REPLACE(TMP_DDL, 'COLLATE "USING_NLS_COMP"', '');
>    TMP_DDL := REPLACE(TMP_DDL, 'DEFAULT COLLATION "USING_NLS_COMP"', '');
> 
> 
326c334
<    COLKEYS := SUBSTR(ORIG_DDL, INSTR(ORIG_DDL, '(')+1);
---
>    COLKEYS := SUBSTR(TMP_DDL, INSTR(TMP_DDL, '(')+1);
1405c1413
<            AND DBMS_HADOOP_INTERNAL.GET_OBJNO_FROM_PARTITIONED_ET(DT.TABLE_NAME,
---
>            AND DBMS_HADOOP_INTERNAL.GET_OBJNO_FROM_PARTITIONED_ET(DT.CLUSTER_ID,
1489a1498,1552
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> FUNCTION EVAL_PART_KEY_OPERATOR(TEXT_OF_DDL IN OUT CLOB, KEY VARCHAR2)
>   RETURN CLOB
> IS
>   KEYSTR CLOB;
>   RAWVAL RAW(256); 
>   STARTPOS NUMBER := 0;
>   VALSTR VARCHAR2(4000);
>   REPLACESTR VARCHAR2(4000);
>   COUNTOFKEY NUMBER := 0;
> BEGIN
>    COUNTOFKEY := REGEXP_COUNT(TEXT_OF_DDL, KEY);
> 
>    
>    
>    
>    
>    
>    FOR I IN 1..COUNTOFKEY
>    LOOP
>      STARTPOS := INSTR(TEXT_OF_DDL, KEY);
> 
>      KEYSTR := SUBSTR(TEXT_OF_DDL, STARTPOS + LENGTH(KEY)+2);
>      KEYSTR := SUBSTR(KEYSTR, 0, INSTR(KEYSTR, ')')-2);
> 
>      IF (KEY = 'UTL_RAW.CAST_TO_RAW') THEN
>        RAWVAL := UTL_RAW.CAST_TO_RAW(KEYSTR);
>        VALSTR := '''' || RAWVAL || '''';
>      ELSIF (KEY = 'TO_DATE') THEN
>        VALSTR := TO_CHAR(TO_DATE(KEYSTR, 'YYYY-MM-DD'));
>        VALSTR := '''' || VALSTR || '''';
>      ELSIF (KEY = 'TO_TIMESTAMP') THEN
>        VALSTR := TO_CHAR(TO_TIMESTAMP(KEYSTR, 'YYYY-MM-DD HH24:MI:SS:FF'));
>        VALSTR := '''' || VALSTR || '''';
>      END IF;
> 
>      REPLACESTR := SUBSTR(TEXT_OF_DDL, STARTPOS, LENGTH(KEYSTR) + LENGTH(KEY)+4); 
> 
>      TEXT_OF_DDL := REPLACE(TEXT_OF_DDL, REPLACESTR, VALSTR);
>    END LOOP;
> 
>    RETURN TEXT_OF_DDL;
> END EVAL_PART_KEY_OPERATOR;
SYS.DBMS_ISCHED - PACKAGE BODY (RU):
5045,5046c5045,5046
<        IF TRACING THEN
<          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
---
>     IF TRACING THEN
>       SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
5048c5048
<          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
---
>       SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
5050,5051c5050,5060
<        END IF;
<        RAISE;
---
>     END IF;
>     
>     
>     IF LOCK_ERROR = 0 THEN
>       LOCK_ERROR := DBMS_LOCK.RELEASE(LOCKHANDLE=>LOCK_HANDLE);
>       IF TRACING THEN
>         SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
>         'Releasing evaluation lock with error ' || LOCK_ERROR);
>       END IF;
>     END IF;
>     RAISE;
SYS.DBMS_ISYNCREF - PACKAGE BODY (RU):
66a67,120
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> PROCEDURE DDL_EXECUTE_3GL(DDLTXT IN CLOB, USR IN BINARY_INTEGER DEFAULT 0) AS
> EXTERNAL
> NAME     "kkziImplDdl"
> LIBRARY DBMS_SNAPSHOT_LIB
> LANGUAGE C
> WITH CONTEXT
> PARAMETERS
> (CONTEXT,
>  DDLTXT OCILOBLOCATOR, DDLTXT INDICATOR SB2,
>  USR    UB4
> );
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> PROCEDURE DDL_EXECUTE(DDLTXT IN CLOB, USR IN BINARY_INTEGER DEFAULT 0) AS
> BEGIN
>   WRITE_TRACE('Executing DDL :'||DDLTXT); 
> 
>   DDL_EXECUTE_3GL(DDLTXT, USR);
>   COMMIT;
>  
>   WRITE_TRACE('Executing DDL : Succeeded');
> EXCEPTION
>   WHEN OTHERS THEN
>    WRITE_TRACE('Executing DDL : Failed with '|| SQLERRM);
>    RAISE;
> END;
> 
> 
> 
264c318
<     EXECUTE IMMEDIATE L_STRSQL;
---
>     DDL_EXECUTE(L_STRSQL);
415c469
<     EXECUTE IMMEDIATE RESULT_SQLSTR;
---
>     DDL_EXECUTE(RESULT_SQLSTR);
SYS.DBMS_LDAP - PACKAGE BODY (RU):
1255,1258d1254
<              IF SSLWALLETPASSWD IS NULL THEN
<                 DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(-31221);
<                 
<              END IF;
1276,1279d1271
<           END IF;
< 
<           IF SSLWALLETPASSWD IS NULL THEN
<              RETURN INVALID_SSLWALLETPASSWD;
SYS.DBMS_PERF - PACKAGE BODY (RU):
1019a1020,1023
>     L_ADDM_ELAPSED       NUMBER := 0;
>     L_ADDM_CPU           NUMBER := 0;
> 
>     
1044a1049
>     L_TZ             VARCHAR2(10)    := NULL;
1047a1053,1057
>     
>     
>     L_AWR_INFO       VARCHAR2(8) := 'y';
> 
>     
1084a1095,1098
> 	
>     L_START_TIME_ADDM  VARCHAR2(32767) := NULL;
>     L_END_TIME_ADDM    VARCHAR2(32767) := NULL;
> 
1454a1469,1472
>     L_TZ := DBMS_SQLTUNE_UTIL2.GET_TZ_OFFSET();
> 
>     
>     
1463,1476c1481,1489
<         IF (L_IS_REALTIME = 1) THEN
<           L_TIME_MODE := 'realtime';
<           L_BEGIN_TIME_UTC := 
<             TO_CHAR(CAST(SYS_EXTRACT_UTC(L_RT_OUTER_START_TIME) AS DATE), 
<                     DBMS_REPORT.DATE_FMT);
<           L_TIME_SINCE_SEC := (SYSDATE - L_RT_OUTER_START_TIME)*86400;
<         
<         ELSE
<           L_TIME_MODE := 'historical';
<           L_BEGIN_TIME_UTC := 
<             TO_CHAR(CAST(SYS_EXTRACT_UTC(L_OUTER_START_TIME) AS DATE), 
<                     DBMS_REPORT.DATE_FMT);
<           L_TIME_SINCE_SEC := (SYSDATE - L_OUTER_START_TIME)*86400;
<         END IF;
---
>         L_TIME_MODE := 'historical';
>         L_BEGIN_TIME_UTC := TO_CHAR(L_OUTER_START_TIME,
>                                     'yyyy-mm-dd hh24:mi:ss') || L_TZ;
>         L_BEGIN_TIME_UTC := 
>           TO_CHAR(CAST(SYS_EXTRACT_UTC(
>               TO_TIMESTAMP_TZ(L_BEGIN_TIME_UTC,
>                   'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
>                   DBMS_REPORT.DATE_FMT);
>         L_TIME_SINCE_SEC := (SYSDATE - L_OUTER_START_TIME)*86400;
1477a1491,1492
>         L_END_TIME_UTC := TO_CHAR(L_OUTER_END_TIME,
>                                   'yyyy-mm-dd hh24:mi:ss') || L_TZ;
1479c1494,1496
<           TO_CHAR(CAST(SYS_EXTRACT_UTC(L_OUTER_END_TIME) AS DATE), 
---
>           TO_CHAR(CAST(SYS_EXTRACT_UTC(
>               TO_TIMESTAMP_TZ(L_END_TIME_UTC,
>                   'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
1488a1506
>                               AWR_INFO        => L_AWR_INFO,
1637a1656,1658
> 
>         L_BEGIN_TIME_UTC := TO_CHAR(L_SELECTED_START_TIME,
>                                     'yyyy-mm-dd hh24:mi:ss') || L_TZ; 
1639,1640c1660,1666
<           TO_CHAR(CAST(SYS_EXTRACT_UTC(L_SELECTED_START_TIME) AS DATE), 
<                   DBMS_REPORT.DATE_FMT);
---
>              TO_CHAR(CAST(SYS_EXTRACT_UTC(
>                  TO_TIMESTAMP_TZ(L_BEGIN_TIME_UTC,
>                     'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
>                     DBMS_REPORT.DATE_FMT);
> 
>         L_END_TIME_UTC := TO_CHAR(L_SELECTED_END_TIME,
>                                   'yyyy-mm-dd hh24:mi:ss') || L_TZ;
1642,1643c1668,1672
<           TO_CHAR(CAST(SYS_EXTRACT_UTC(L_SELECTED_END_TIME) AS DATE), 
<                   DBMS_REPORT.DATE_FMT);
---
>             TO_CHAR(CAST(SYS_EXTRACT_UTC(
>                 TO_TIMESTAMP_TZ(L_END_TIME_UTC, 
>                     'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
>                     DBMS_REPORT.DATE_FMT);
> 
1747,1749c1776
<       IF (L_IS_REALTIME = 1 AND L_SPOTREP = 0
<           AND LOWER(REPORT_LEVEL) != REPORT_LEVEL_WATCHDOG 
<           AND L_OUTER_END_TIME = L_SELECTED_END_TIME) THEN
---
>       IF(IS_OMX = 1) THEN
1750a1778,1807
>         DBMS_REPORT.GET_TIMING_INFO(0, L_ADDM_ELAPSED, L_ADDM_CPU);
> 
>         IF(L_IS_REALTIME = 1) THEN
> 	  
>           L_START_TIME_ADDM := TO_CHAR(L_OUTER_START_TIME,
> 				    'mm/dd/yyyy hh24:mi:ss');
>           L_END_TIME_ADDM := TO_CHAR(L_OUTER_END_TIME,
>                                   'mm/dd/yyyy hh24:mi:ss');   
> 
>         ELSE
>           L_START_TIME_ADDM := TO_CHAR(L_SELECTED_START_TIME,
>                                       'mm/dd/yyyy hh24:mi:ss');
>           L_END_TIME_ADDM := TO_CHAR(L_SELECTED_END_TIME,
> 				    'mm/dd/yyyy hh24:mi:ss');
>  
>         END IF;
> 
>         L_ADDM_XML := SYS.PRVT_HDM.ADDM_REPORT_XML(
>                             P_DBID       => NULL,
>                             P_INST_ID    => INST_ID,
>                             P_BEGIN_TIME => L_START_TIME_ADDM,
>                             P_END_TIME   => L_END_TIME_ADDM,
>                             P_DAYS       => NULL,
>                             P_OWNER      => NULL,
>                             P_TASK_NAME  => NULL,
>                             P_SECTION    => 'ALL',
>                             P_SPOTREP    => NULL,
>                             P_SPOTLIST   => NULL,
>                             P_SHOW_SQL   => 0);
> 
1751a1809
>         DBMS_REPORT.GET_TIMING_INFO(1,L_ADDM_ELAPSED,L_ADDM_CPU);
1753,1754c1811,1812
<         L_SPOTREP := 1;
<       END IF;
---
>         L_REPORT_REFERENCE := DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
>                            'addm','main',L_REF_PARAMS);
1756,1760c1814,1817
<       IF (LOWER(REPORT_LEVEL) = REPORT_LEVEL_WATCHDOG) THEN
<         L_COMPRESS_ADDM := 0; 
<       ELSE
<         L_COMPRESS_ADDM := 1;
<       END IF;
---
>         
>         IF (L_ADDM_ELAPSED < 0) THEN
>             L_ADDM_ELAPSED  := 0;
>         END IF;
1762,1765c1819,1851
<       
<       
<       
<       IF (L_IS_REALTIME = 1) THEN
---
>         IF (L_ADDM_CPU < 0) THEN
>             L_ADDM_CPU  := 0;
>         END IF;
> 
>         L_REPORT_XML := PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
>                      L_REPORT_REFERENCE,L_ADDM_ELAPSED,L_ADDM_CPU);
> 
>         L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(
>                      XML_ROOT,L_ACTIVE_REPORT_PARAM_XML);
> 
>         L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT,L_ADDM_XML);
> 
>         L_ADDM_XML := L_REPORT_XML;
> 
>       ELSE 
> 
>         IF (L_IS_REALTIME = 1 AND L_SPOTREP = 0
>             AND LOWER(REPORT_LEVEL) != REPORT_LEVEL_WATCHDOG 
>             AND L_OUTER_END_TIME = L_SELECTED_END_TIME) THEN
>           
>           
>           
>           L_SPOTREP := 1;
>         END IF;
> 
>         IF (LOWER(REPORT_LEVEL) = REPORT_LEVEL_WATCHDOG) THEN
>           
>           L_COMPRESS_ADDM := 0;
>         ELSE
>           L_COMPRESS_ADDM := 1;
>         END IF;
> 
>         
1768c1854,1857
<         L_ADDM_XML := SYS.PRVT_AWR_VIEWER.REPORT_ADDM_XML(
---
>         IF (L_IS_REALTIME = 1) THEN
>           
>           
>           L_ADDM_XML := SYS.PRVT_AWR_VIEWER.REPORT_ADDM_XML(
1777,1779c1866,1868
<       ELSE
<         
<         
---
>         ELSE
>           
>           
1781c1870
<         L_ADDM_XML := SYS.PRVT_AWR_VIEWER.REPORT_ADDM_XML(
---
>           L_ADDM_XML := SYS.PRVT_AWR_VIEWER.REPORT_ADDM_XML(
1790a1880
>         END IF;
2160a2251
>     L_TZ              VARCHAR2(10)    := NULL;
2424a2516,2518
>     
>     
>     L_TZ := DBMS_SQLTUNE_UTIL2.GET_TZ_OFFSET();
2435,2439c2529
<         IF (L_IS_REALTIME = 1) THEN
<           L_TIME_MODE := 'realtime';
<           L_BEGIN_TIME_UTC := 
<             TO_CHAR(CAST(SYS_EXTRACT_UTC(L_RT_OUTER_START_TIME) AS DATE), 
<                     DBMS_REPORT.DATE_FMT);
---
>         L_TIME_MODE := 'historical';
2441,2446c2531,2537
<           L_TIME_SINCE_SEC := (SYSDATE - L_RT_OUTER_START_TIME)*86400;
<         ELSE
<           L_TIME_MODE := 'historical';
<           L_BEGIN_TIME_UTC := 
<             TO_CHAR(CAST(SYS_EXTRACT_UTC(L_OUTER_START_TIME) AS DATE), 
<                     DBMS_REPORT.DATE_FMT);
---
>         L_BEGIN_TIME_UTC := TO_CHAR(L_OUTER_START_TIME, 
>                                    'yyyy-mm-dd hh24:mi:ss') || L_TZ;
>         L_BEGIN_TIME_UTC := 
>           TO_CHAR(CAST(SYS_EXTRACT_UTC(
>               TO_TIMESTAMP_TZ(L_BEGIN_TIME_UTC, 
>                   'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
>                   DBMS_REPORT.DATE_FMT);
2448,2449c2539
<           L_TIME_SINCE_SEC := (SYSDATE - L_OUTER_START_TIME)*86400;
<         END IF;
---
>         L_TIME_SINCE_SEC := (SYSDATE - L_OUTER_START_TIME)*86400;
2450a2541,2542
>         L_END_TIME_UTC := TO_CHAR(L_OUTER_END_TIME, 
>                                   'yyyy-mm-dd hh24:mi:ss') || L_TZ;
2452c2544,2546
<           TO_CHAR(CAST(SYS_EXTRACT_UTC(L_OUTER_END_TIME) AS DATE), 
---
>           TO_CHAR(CAST(SYS_EXTRACT_UTC(
>               TO_TIMESTAMP_TZ(L_END_TIME_UTC,
>                   'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
2469c2563
<                           
---
>                               FILTER_LIST     => L_FILTER_LIST_XML,
2517a2612,2613
>         L_BEGIN_TIME_UTC := TO_CHAR(L_SELECTED_START_TIME,
>                                     'yyyy-mm-dd hh24:mi:ss') || L_TZ;
2519c2615,2617
<             TO_CHAR(CAST(SYS_EXTRACT_UTC(L_SELECTED_START_TIME) AS DATE), 
---
>             TO_CHAR(CAST(SYS_EXTRACT_UTC(
>                 TO_TIMESTAMP_TZ(L_BEGIN_TIME_UTC,
>                     'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
2521a2620,2621
>         L_END_TIME_UTC := TO_CHAR(L_SELECTED_END_TIME,
>                                   'yyyy-mm-dd hh24:mi:ss') || L_TZ;
2523c2623,2625
<             TO_CHAR(CAST(SYS_EXTRACT_UTC(L_SELECTED_END_TIME) AS DATE), 
---
>             TO_CHAR(CAST(SYS_EXTRACT_UTC(
>                 TO_TIMESTAMP_TZ(L_END_TIME_UTC,
>                     'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE), 
3157,3158c3259
<                        
<                        
---
>                               FILTER_LIST     => L_FILTER_LIST_XML,
SYS.DBMS_RCVMAN - PACKAGE BODY (19.7RUR):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '19.07.00.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '19.07.01.00'; 
SYS.DBMS_RCVMAN - PACKAGE BODY (19.6RUR):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '19.06.01.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '19.06.02.00'; 
SYS.DBMS_RCVMAN - PACKAGE BODY (RU):
122c122
< CATALOGVERSION CONSTANT VARCHAR2(11) := '19.07.00.00'; 
---
> CATALOGVERSION CONSTANT VARCHAR2(11) := '19.08.00.00'; 
6274c6274
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6480c6480
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6642c6642
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
6729c6729
<           DECODE(A.NEXT_CHANGE#, HIGHSCNVAL, -2, A.STAMP) STAMP,
---
>           DECODE(A.ARCHIVED, 'NO', -2, A.STAMP) STAMP,
7879,7892d7878
< WITH
< MY_DBINC AS
<    (SELECT RESETLOGS_TIME, 
<            RESETLOGS_CHANGE#,
<            PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
<     FROM V$DATABASE_INCARNATION             
<     START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
<           AND  RESETLOGS_TIME    = THIS_RESET_TIME  
<     CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
<     UNION ALL
<     SELECT THIS_RESET_TIME  RESETLOGS_TIME,
<            THIS_RESET_SCN   RESETLOGS_CHANGE#,
<            NULL             NEXT_RESETLOGS_CHANGE#
<     FROM DUAL)
7932c7918,7930
<            FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>            FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
8087c8085,8097
<             FROM V$DATAFILE_COPY CDF, MY_DBINC
---
>             FROM V$DATAFILE_COPY CDF, 
>             (SELECT RESETLOGS_TIME,
>               RESETLOGS_CHANGE#,
>              PRIOR RESETLOGS_CHANGE# NEXT_RESETLOGS_CHANGE#
>              FROM V$DATABASE_INCARNATION
>              START WITH RESETLOGS_CHANGE# = THIS_RESET_SCN
>               AND  RESETLOGS_TIME    = THIS_RESET_TIME
>               CONNECT BY PRIOR PRIOR_INCARNATION# = INCARNATION#
>               UNION ALL
>               SELECT THIS_RESET_TIME  RESETLOGS_TIME,
>                THIS_RESET_SCN   RESETLOGS_CHANGE#,
>                 NULL             NEXT_RESETLOGS_CHANGE#
>                FROM DUAL) MY_DBINC
SYS.DBMS_SQLTUNE - PACKAGE BODY (RU):
26420a26421,26463
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
>     
> 
>     IF ( (LOCAL_DB = 1) 
>           AND
>          (DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE() IN 
>           (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>            DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D))
>           AND 
>          (DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(START_TIME) = 
>                         DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB)
>        )
>     THEN  
>         TARGET_DBID := CON_DBID;
>     END IF;
> 
>     
SYS.DBMS_SQLTUNE_UTIL2 - PACKAGE BODY (RU):
683a684
>   
686a688
>     CLOUD_SERVICE_TYPE VARCHAR2(32);
689c691,713
<     RETURN NVL(SYS_CONTEXT('userenv', 'cloud_service'), CLOUD_SERVICE_TYPE_NONE);
---
>     SELECT 
>       CASE 
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='PAAS' THEN
>           CASE 
>             WHEN UPPER(MAX(PROPERTY_VALUE)) LIKE '%ADW.ORACLECLOUD.COM' THEN
>               CLOUD_SERVICE_TYPE_ADW_D
>       	    WHEN UPPER(MAX(PROPERTY_VALUE)) LIKE '%ATP.ORACLECLOUD.COM' THEN 
>               CLOUD_SERVICE_TYPE_ATP_D
>       	    ELSE CLOUD_SERVICE_TYPE_OTHER
>           END
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='DWCS' THEN 
>           CLOUD_SERVICE_TYPE_ADW_S
>         WHEN UPPER(SYS_CONTEXT('USERENV','CLOUD_SERVICE'))='OLTP' THEN 
>           CLOUD_SERVICE_TYPE_ATP_S
>         ELSE
>           UPPER(NVL(SYS_CONTEXT('USERENV','CLOUD_SERVICE'), 
>                 CLOUD_SERVICE_TYPE_NONE))
>       END
>     INTO CLOUD_SERVICE_TYPE
>     FROM DATABASE_PROPERTIES
>     WHERE UPPER(PROPERTY_NAME) = 'GLOBAL_DB_NAME';
> 
>     RETURN CLOUD_SERVICE_TYPE;
702a727,752
>   FUNCTION GET_TZ_OFFSET
>   RETURN VARCHAR2
>   IS
>     L_TZ VARCHAR2(10);
>   BEGIN
>     
>     
>     L_TZ := EXTRACT(TIMEZONE_HOUR FROM SYSTIMESTAMP) || ':' ||
>                    EXTRACT(TIMEZONE_MINUTE FROM SYSTIMESTAMP);
>     RETURN L_TZ;
>   END GET_TZ_OFFSET;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
704,705c754,768
<   FUNCTION IS_ADW
<   RETURN BOOLEAN
---
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION CHOOSEAWRFORPDB(
>         BEGINTIME IN DATE) 
>   RETURN VARCHAR2
706a770,774
>     L_AWR_LOCATION VARCHAR2(32) := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>     L_SQLTEXT   VARCHAR2(4000);
>     L_PDB_TIME  DATE;
>     L_ROOT_TIME DATE;
> 
707a776,790
>     
>     
>     L_SQLTEXT := 
>       'SELECT CAST(MAX(end_interval_time) AS DATE)
>        FROM   AWR_PDB_SNAPSHOT
>        WHERE  dbid = :1';
>     EXECUTE IMMEDIATE L_SQLTEXT 
>     INTO L_PDB_TIME
>     USING SYS_CONTEXT('USERENV', 'CON_DBID');
> 
>     IF L_PDB_TIME IS NULL THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>       RETURN L_AWR_LOCATION;
>     END IF;
709,712c792,795
<     IF (GET_CLOUD_SERVICE_TYPE() = CLOUD_SERVICE_TYPE_ADW) THEN
<       RETURN TRUE;
<     ELSE
<       RETURN FALSE;
---
>     IF L_PDB_TIME >= BEGINTIME THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB;
>       RETURN L_AWR_LOCATION;
715c798,825
<   END IS_ADW;
---
>     
>     
>     
>     L_SQLTEXT := 
>       'SELECT CAST(MAX(end_interval_time) AS DATE)
>        FROM   AWR_ROOT_SNAPSHOT
>        WHERE  dbid = :1';
>     EXECUTE IMMEDIATE L_SQLTEXT
>     INTO L_ROOT_TIME
>     USING SYS_CONTEXT('USERENV', 'DBID');
>     
>     IF ((L_ROOT_TIME IS NOT NULL) AND 
>         (L_ROOT_TIME >= BEGINTIME) 
>        ) 
>     THEN
>       
>       L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
>       RETURN L_AWR_LOCATION;
> 
>     ELSE 
>         
>         L_AWR_LOCATION := DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB;
>         RETURN L_AWR_LOCATION;
>     END IF;
> 
>     RETURN L_AWR_LOCATION;
> 
>   END CHOOSEAWRFORPDB;
SYS.PRVTEMX_PERF - PACKAGE BODY (RU):
7a8,13
>   AWR_PREFIX_ROOT   VARCHAR2(16) := 'sys.awr_root';
>   AWR_PREFIX_PDB    VARCHAR2(16) := 'sys.awr_pdb';
>   G_CLOUD_SERVICE_TYPE CONSTANT VARCHAR2(32) := 
>                     DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE();
> 
>   
379c385
<             from sys.dba_hist_active_sess_history a
---
>             from #AWR_VIEW_PREFIX#_active_sess_history a
462c468
<                             from sys.dba_hist_pdb_instance)) c');
---
>                             from #AWR_VIEW_PREFIX#_pdb_instance)) c');
485,502c491,550
<       SELECT MIN(SNAP_ID)
<         INTO L_BEGIN_SNAP
<         FROM SYS.DBA_HIST_ASH_SNAPSHOT
<        WHERE DBID            = L_DBID
<          AND INSTANCE_NUMBER = P_INST_ID
<          AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
<            OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
<            OR P_START_TIME BETWEEN BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
< 
<          
<       SELECT MAX(SNAP_ID)
<         INTO L_END_SNAP
<         FROM SYS.DBA_HIST_ASH_SNAPSHOT
<        WHERE DBID            = L_DBID
<          AND INSTANCE_NUMBER = P_INST_ID
<          AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
<            OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
<            OR P_END_TIME BETWEEN BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
---
>       
>       IF ((G_CLOUD_SERVICE_TYPE IN 
>             (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D))
>           AND 
>             (L_IS_ROOT = FALSE))
>       THEN  
>           L_QRY := REPLACE(L_QRY,'#AWR_VIEW_PREFIX#', AWR_PREFIX_PDB);
> 
>           
>           SELECT MIN(SNAP_ID)
>             INTO L_BEGIN_SNAP
>             FROM SYS.AWR_PDB_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_START_TIME BETWEEN 
>                                BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>              
>           SELECT MAX(SNAP_ID)
>             INTO L_END_SNAP
>             FROM SYS.AWR_PDB_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_END_TIME BETWEEN 
>                              BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>       ELSE 
>           
>           L_QRY := REPLACE(L_QRY,'#AWR_VIEW_PREFIX#', AWR_PREFIX_ROOT);
> 
>           
>           SELECT MIN(SNAP_ID)
>             INTO L_BEGIN_SNAP
>             FROM SYS.AWR_ROOT_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_START_TIME BETWEEN 
>                                BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>              
>           SELECT MAX(SNAP_ID)
>             INTO L_END_SNAP
>             FROM SYS.AWR_ROOT_ASH_SNAPSHOT
>            WHERE DBID            = L_DBID
>              AND INSTANCE_NUMBER = P_INST_ID
>              AND (END_INTERVAL_TIME   BETWEEN P_START_TIME AND P_END_TIME
>                OR BEGIN_INTERVAL_TIME BETWEEN P_START_TIME AND P_END_TIME
>                OR P_END_TIME BETWEEN 
>                              BEGIN_INTERVAL_TIME AND END_INTERVAL_TIME);
> 
>       END IF;
1095c1143
<     V_REF_PARAMS 	        DBMS_REPORT.REF_STRING_IDSPEC;
---
>     V_REF_PARAMS                DBMS_REPORT.REF_STRING_IDSPEC;
SYS.PRVT_ASH_OMX - PACKAGE BODY (RU):
41a42,43
>   
>   
54a57
>     RESOLUTION      IN VARCHAR2 := NULL,
74c77,78
<                           INSTANCE_NUMBER => INST_ID);
---
>                           INSTANCE_NUMBER => INST_ID,
>                           RESOLUTION      => RESOLUTION);
84c88,89
<                           INSTANCE_NUMBER => INST_ID);
---
>                           INSTANCE_NUMBER => INST_ID,
>                           RESOLUTION      => RESOLUTION);
96c101,102
<                           INSTANCE_NUMBER => INST_ID);
---
>                           INSTANCE_NUMBER => INST_ID,
>                           RESOLUTION      => RESOLUTION);
108c114,115
<                           AWR_INFO        => AWR_INFO);
---
>                           AWR_INFO        => AWR_INFO,
>                           RESOLUTION      => RESOLUTION);
118c125,126
<                           AWR_INFO        => AWR_INFO);
---
>                           AWR_INFO        => AWR_INFO,
>                           RESOLUTION      => RESOLUTION);
130c138,139
<                           AWR_INFO        => AWR_INFO);        
---
>                           AWR_INFO        => AWR_INFO,
>                           RESOLUTION      => RESOLUTION);        
183a193,194
>   
>   
196a208
>     RESOLUTION      IN VARCHAR2 := NULL,
215c227,228
<                         MINIMIZE_COST   => MINIMIZE_COST);
---
>                         MINIMIZE_COST   => MINIMIZE_COST,
>                         RESOLUTION      => RESOLUTION);
227c240,241
<                         MINIMIZE_COST   => MINIMIZE_COST);
---
>                         MINIMIZE_COST   => MINIMIZE_COST,
>                         RESOLUTION      => RESOLUTION);
241c255,256
<                         MINIMIZE_COST   => MINIMIZE_COST);
---
>                         MINIMIZE_COST   => MINIMIZE_COST,
>                         RESOLUTION      => RESOLUTION);
SYS.PRVT_AWR_VIEWER - PACKAGE BODY (RU):
1186,1187c1186,1187
<   ADW_RMMETRICS_COMMON CONSTANT VARCHAR2(32767) := q'[
<       with rmmetrics_data as (-- ADW workload main query
---
>   RMMETRICS_COMMON CONSTANT VARCHAR2(32767) := q'[
>       with rmmetrics_data as (-- autonomous DB workload main query
1200a1201,1202
>                cpu_usage_per_sec,
>                avg_running_stmts,
1207c1209,1211
<                    avg_cpu_utilization, 
---
>                    avg_cpu_utilization,
>                    cpu_usage_per_sec,
>                    avg_running_stmts,
1219,1221c1223,1225
<               where avg_cpu_utilization +
<                     avg_active_parallel_stmts + 
<                     avg_queued_parallel_stmts > 0) 
---
>               where avg_cpu_utilization + cpu_usage_per_sec + 
>                     avg_running_stmts +
>                     avg_active_parallel_stmts + avg_queued_parallel_stmts > 0) 
1247a1252,1253
>                             round(cpu_usage_per_sec, 2)           as "cpuUsage",
>                             round(avg_running_stmts, 2)           as "rst",
1260a1267,1268
>                          cpu_usage_per_sec,
>                          avg_running_stmts,
1422a1431
>     
1430a1440
>     
18245a18256
> 
18266,18271c18277,18291
<   FUNCTION REPORT_ADW_WORKLOAD_REALTIME(
<     START_TIME        IN DATE           DEFAULT NULL,
<     END_TIME          IN DATE           DEFAULT NULL,
<     INST_ID_LOW       IN NUMBER         DEFAULT NULL,
<     INST_ID_HIGH      IN NUMBER         DEFAULT NULL,
<     SHOW_SQL          IN NUMBER         DEFAULT 0)
---
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_RMMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME      IN DATE               DEFAULT NULL,
>     END_TIME        IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT 0)
18274,18276d18293
<     
<     L_ELAPSED        NUMBER;
<     L_CPU            NUMBER;
18279c18296,18297
<     L_REF_PARAMS     DBMS_REPORT.REF_STRING_IDSPEC;
---
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
18282,18283c18300
<     L_ORIG_ENV       DBMS_REPORT.FORMAT_PARAM_VALUES;
<     L_SET_ENV        BOOLEAN;
---
>     L_RESULT_XML XMLTYPE := NULL;
18286,18287c18303,18310
<     L_QUERY          VARCHAR2(32767) := NULL;
<     L_REPORT_SQL     CLOB;
---
>     L_IS_REALTIME     NUMBER        := IS_REALTIME;
>     L_DBID            NUMBER        := DBID;
>     L_START_TIME      DATE          := START_TIME;
>     L_END_TIME        DATE          := END_TIME;
>     L_BUCKET_COUNT    NUMBER        := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER        := BUCKET_INTERVAL;
>     L_AWR_PERIOD PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(10)  := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
18290,18292c18313
<     L_REPORT_XML     XMLTYPE := NULL;
<     L_RMMETRICS_XML  XMLTYPE := NULL;
< 
---
>     L_BUCKET_MAP PRVT_AWRV_MAPTAB;
18295,18298c18316,18317
<     L_START_TIME     DATE := START_TIME;
<     L_END_TIME       DATE := END_TIME;
<     L_INST_ID_LOW    NUMBER := INST_ID_LOW;
<     L_INST_ID_HIGH   NUMBER := INST_ID_HIGH;
---
>     L_CON_ID   NUMBER;
>     L_CON_DBID NUMBER;
18301,18302c18320,18323
<     L_BUCKET_COUNT    NUMBER;
<     L_BUCKET_INTERVAL NUMBER;
---
>     L_RESOURCE_MANAGER_ENABLED NUMBER := 0;
>     
>     
>     L_NUM_CPUS NUMBER := NULL;
18307c18328,18329
<     ADW_RMMETRICS_REALTIME  CONSTANT VARCHAR2(32767) := q'[
---
>     
>     RMMETRICS_RT CONSTANT VARCHAR2(32767) := q'[
18310c18332,18337
<            avg(avg_cpu_utilization)  avg_cpu_utilization,
---
>            case
>              when avg(avg_cpu_utilization) > 100 then 100
>              else avg(avg_cpu_utilization) 
>            end avg_cpu_utilization,
>            avg(cpu_usage_per_sec) cpu_usage_per_sec,
>            sum(avg_running_stmts) avg_running_stmts,
18340,18346c18367,18397
<                   case 
<                     when running_sessions_limit is null or
<                          running_sessions_limit = 0 then
<                       avg_cpu_utilization
<                     else
<                       (avg_running_sessions/running_sessions_limit)*100 
<                   end avg_cpu_utilization,
---
>                   (case 
>                      -- resource manager enabled, use running_sessions_limit
>                      when :resource_manager_enabled > 0 then
>                        (case
>                           -- if running_sessions_limit is not set
>                           when running_sessions_limit is null or
>                                running_sessions_limit = 0 then
>                             avg_cpu_utilization
>                           else
>                             (avg_running_sessions/running_sessions_limit)*100
>                         end)
>                      -- resource manager disabled, use system cpu limit
>                      else
>                        (case
>                           when :num_cpus > 0 then
>                             (avg_running_sessions/:num_cpus)*100
>                           -- system cpu limit not available
>                           -- use running_sessions_limit
>                           else
>                             (case
>                                when running_sessions_limit is null or
>                                     running_sessions_limit = 0 then
>                                  avg_cpu_utilization
>                                else
>                                 (avg_running_sessions/running_sessions_limit)*100
>                              end)
>                         end)
>                      end) avg_cpu_utilization,
>                   cpu_consumed_time/(intsize_csec*10) cpu_usage_per_sec,
>                   avg_running_sessions + avg_waiting_sessions
>                     as avg_running_stmts,
18349,18353c18400,18402
<              from v$rsrcmgrmetric_history
<             where end_time >= to_date(:b_start_time,:date_fmt)
<               and end_time <  to_date(:b_end_time,:date_fmt)
<               and userenv('INSTANCE') between :p_inst_id_low
<                                           and :p_inst_id_high)))
---
>              from sys.v_$rsrcmgrmetric_history
>             where end_time >= to_date(:b_start_time, :date_fmt)
>               and end_time <  to_date(:b_end_time, :date_fmt))))
18356,18357c18405,18549
<   
<   ADW_RMMETRICS_RT_HEADER   CONSTANT VARCHAR2(32767) := q'[
---
>     
>     RMMETRICS_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var is_awr                   number;
>       var p_contTab                prvt_awrv_instTab;
>       var b_start_time             varchar2(4000);
>       var b_end_time               varchar2(4000);
>       var p_bucket_interval        number;
>       var p_bucket_count           number;
>       var b_min_time               varchar2(4000);
>       var b_max_time               varchar2(4000);
>       var b_duration               number;
>       var date_fmt                 varchar2(4000);
>       var resource_manager_enabled number;
>       var num_cpus                 number;
>       begin
>         :is_awr                   := #is_awr#;
>         :p_contTab                := #p_contTab#;
>         :b_start_time             := '#b_start_time#';
>         :b_end_time               := '#b_end_time#';
>         :p_bucket_interval        := #p_bucket_interval#;
>         :p_bucket_count           := #p_bucket_count#;
>         :b_min_time               := '#b_min_time#';
>         :b_max_time               := '#b_max_time#';
>         :b_duration               := #b_duration#;
>         :date_fmt                 := '#date_fmt#';
>         :resource_manager_enabled := #resource_manager_enabled#;
>         :num_cpus                 := #num_cpus#;
>       end;
>       /]';
> 
>     
>     RMMETRICS_AWR CONSTANT VARCHAR2(32767) := q'[
>     select bucket_id,
>            consumer_group_id,
>            consumer_group_name,
>            case
>              when sum(avg_cpu_utilization) > 100 then 100
>              else sum(avg_cpu_utilization) 
>            end avg_cpu_utilization,
>            sum(cpu_usage_per_sec) cpu_usage_per_sec,
>            sum(avg_running_stmts) avg_running_stmts,
>            sum(avg_active_parallel_stmts) avg_active_parallel_stmts,
>            sum(avg_queued_parallel_stmts) avg_queued_parallel_stmts
>      from (
>         select bucket_id,
>                consumer_group_name,  
>                consumer_group_id,
>                -- avg
>                avg(avg_cpu_utilization) avg_cpu_utilization,
>                avg(cpu_usage_per_sec) cpu_usage_per_sec,
>                avg(avg_running_stmts) avg_running_stmts,
>                avg(avg_active_parallel_stmts) 
>                   avg_active_parallel_stmts,
>                avg(avg_queued_parallel_stmts) 
>                   avg_queued_parallel_stmts
>           from table(cast(:bucket_map as sys.prvt_awrv_mapTab)) b,
>                (select /*+ no_merge */ nvl(m.snap_id, c.snap_id) as snap_id,
>                        nvl(m.instance_number, c.instance_number) 
>                                                  as instance_number,
>                        m.consumer_group_id consumer_group_id,
>                        null consumer_group_name,
>                        case 
>                          when c.cpu_limit is null or
>                               c.cpu_limit = 0 then
>                            m.avg_cpu_utilization
>                          else
>                            (m.avg_running_sessions/c.cpu_limit)*100
>                          end                       as avg_cpu_utilization,
>                        m.cpu_consumed_time/(m.intsize_csec*10) cpu_usage_per_sec,
>                        m.avg_running_sessions + m.avg_waiting_sessions
>                                                    as avg_running_stmts,
>                        m.avg_active_parallel_stmts as avg_active_parallel_stmts,
>                        m.avg_queued_parallel_stmts as avg_queued_parallel_stmts
>                   from awr_root_rsrc_metric m,
>                        (SELECT /*+ no_merge */ 
>                                nvl(s.snap_id, p.snap_id) as snap_id,
>                                nvl(s.instance_number, p.instance_number) 
>                                                          as instance_number,
>                                CASE WHEN p.cpu_count IS NULL 
>                                     THEN nvl(s.num_cpus, s.num_cpu_cores)
>                                     ELSE LEAST(p.cpu_count, 
>                                                NVL(s.num_cpus, s.num_cpu_cores))
>                                END as cpu_limit
>                           FROM   
>                             (SELECT /*+ NO_MERGE */ snap_id, instance_number,
>                                     MAX(num_cpus)      num_cpus,
>                                     MAX(num_cpu_cores) num_cpu_cores
>                                FROM 
>                                  (SELECT snap_id, instance_number,
>                                          CASE
>                                            WHEN stat_name = 'NUM_CPUS' 
>                                            THEN value
>                                            ELSE NULL
>                                          END as num_cpus,
>                                          CASE
>                                            WHEN stat_name = 'NUM_CPU_CORES'
>                                            THEN value
>                                            ELSE NULL
>                                          END as num_cpu_cores
>                                     FROM awr_root_osstat
>                                    WHERE stat_name IN 
>                                            ('NUM_CPUS','NUM_CPU_CORES'))
>                                   GROUP BY snap_id, instance_number) s,
>                             (SELECT /*+ NO_MERGE */ snap_id, instance_number,
>                                     MAX(
>                                       CASE 
>                                         WHEN resource_plan IS NULL THEN NULL 
>                                         ELSE TO_NUMBER(cpu_count)
>                                       END) as cpu_count
>                                FROM 
>                                  (SELECT snap_id, instance_number,
>                                          CASE
>                                            WHEN parameter_name = 'cpu_count' 
>                                            THEN value
>                                            ELSE NULL
>                                          END cpu_count,
>                                          CASE
>                                            WHEN parameter_name = 
>                                                   'resource_manager_plan'
>                                            THEN value
>                                            ELSE NULL
>                                          END resource_plan
>                                     FROM awr_root_parameter
>                                    WHERE parameter_name IN 
>                                           ('cpu_count', 'resource_manager_plan'))
>                                   GROUP BY snap_id, instance_number) p
>                          WHERE s.snap_id = p.snap_id
>                            AND s.instance_number = p.instance_number) c
>                  where m.dbid = :m_dbid 
>                    and m.snap_id between :m_begin_snap and :m_end_snap
>                    and m.con_dbid = :l_con_dbid
>                    and m.snap_id = c.snap_id(+)
>                    and m.instance_number = c.instance_number(+)) y
>          where b.snap_id         = y.snap_id
>            and b.instance_number = y.instance_number
>          group by bucket_id, 
>                y.instance_number, 
>                y.consumer_group_id, 
>                y.consumer_group_name)
>       group by bucket_id, 
>                consumer_group_id,
>                consumer_group_name]'; 
> 
>     
>     RMMETRICS_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
18360,18361c18552,18556
<       var b_start_time      varchar2(4000);
<       var b_end_time        varchar2(4000);
---
>       var bucket_map        prvt_awrv_mapTab;
>       var m_dbid            number;
>       var m_begin_snap      number;
>       var m_end_snap        number;
>       var l_con_dbid        number;
18364,18365d18558
<       var p_inst_id_low     number;
<       var p_inst_id_high    number;
18369d18561
<       var date_fmt          varchar2(4000);
18373,18374c18565,18569
<         :b_start_time      := '#b_start_time#';
<         :b_end_time        := '#b_end_time#';
---
>         :bucket_map        := #bucket_map#;
>         :m_dbid            := #m_dbid#;
>         :m_begin_snap      := #m_begin_snap#;
>         :m_end_snap        := #m_end_snap#;
>         :l_con_dbid        := #l_con_dbid#;
18377,18378d18571
<         :p_inst_id_low     := #p_inst_id_low#;
<         :p_inst_id_high    := #p_inst_id_high#;
18382d18574
<         :date_fmt          := '#date_fmt#';
18387,18390d18578
<     
<     
<     L_ORIG_ENV := DBMS_REPORT.FORMAT_PARAM_VALUES();
<     L_SET_ENV  := DBMS_REPORT.SETUP_REPORT_ENV(L_ORIG_ENV);
18393c18581,18583
<     DBMS_REPORT.GET_TIMING_INFO(0, L_ELAPSED, L_CPU);
---
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
18396c18586
< 
---
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
18398,18421d18587
<     IF (START_TIME IS NOT NULL) THEN
<       L_REF_PARAMS('start_time') :=
<         TO_CHAR(START_TIME,DBMS_REPORT.DATE_FMT_MOD);
<     END IF;
< 
<     IF (END_TIME IS NOT NULL) THEN
<       L_REF_PARAMS('end_time') :=
<         TO_CHAR(END_TIME,DBMS_REPORT.DATE_FMT_MOD);
<     END IF;
< 
<     IF (INST_ID_LOW IS NOT NULL) THEN
<       L_REF_PARAMS('inst_id_low') := TO_CHAR(INST_ID_LOW);
<     END IF;
< 
<     IF (INST_ID_HIGH IS NOT NULL) THEN
<       L_REF_PARAMS('inst_id_high') := TO_CHAR(INST_ID_HIGH);
<     END IF;
< 
<     L_REF_PARAMS('is_realtime') := 1;
< 
<     IF (SHOW_SQL IS NOT NULL) THEN
<       L_REF_PARAMS('show_sql') := SHOW_SQL; 
<     END IF;
< 
18423,18428c18589,18590
<     IF (L_INST_ID_LOW IS NULL) THEN
<       L_INST_ID_LOW := 0;
<     END IF;
< 
<     IF (L_INST_ID_HIGH IS NULL) THEN
<       L_INST_ID_HIGH := INST_ID_MAX;
---
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
18438c18600,18606
<       L_START_TIME := L_END_TIME - 1/24;
---
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME := L_END_TIME - 1/24;
>       
>       ELSE
>         L_START_TIME := L_END_TIME - 1;
>       END IF;
18442,18444c18610,18612
<     CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
<                       (L_END_TIME - L_START_TIME)*DTOS,
<                       NULL);
---
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
18447,18456c18615
<     L_QUERY := ADW_RMMETRICS_COMMON;
<    
<     
<     L_QUERY := REPLACE(L_QUERY,'#GENERATE_BUCKETS_TAG#', GENERATE_BUCKETS_TAG2);
<     L_QUERY := REPLACE(L_QUERY,'#GENERATE_BUCKETID_TAG#', 
<                                 GENERATE_BUCKETID_TAG);
<     L_QUERY := REPLACE(L_QUERY,'#GENERATE_METRICS_BUCKETID#', 
<                                 ADW_RMMETRICS_REALTIME);
< 
<     IF (SHOW_SQL = 1) THEN
---
>     IF (IS_REALTIME = 1) THEN
18458,18459d18616
<       L_REPORT_SQL := ADW_RMMETRICS_RT_HEADER;
< 
18461c18618,18627
<       L_REPORT_SQL := L_REPORT_SQL || L_QUERY;
---
>       BEGIN
>         SELECT COUNT(VALUE)
>           INTO L_RESOURCE_MANAGER_ENABLED
>           FROM SYS.V_$SYSTEM_PARAMETER2        
>          WHERE NAME = 'resource_manager_plan'
>            AND (VALUE IS NOT NULL AND VALUE != '');
>       EXCEPTION
>         WHEN OTHERS THEN
>           L_RESOURCE_MANAGER_ENABLED := 0;
>       END;
18464,18483c18630,18650
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#is_awr#', 0);
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_contTab#', 'null');
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_start_time#',
<                                             TO_CHAR(L_START_TIME, DATE_FMT));
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_end_time#',
<                                             TO_CHAR(L_END_TIME, DATE_FMT));
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_bucket_interval#', 
<                                             L_BUCKET_INTERVAL);
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_inst_id_low#', L_INST_ID_LOW);
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_inst_id_high#', L_INST_ID_HIGH);
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_min_time#', 
<                                             TO_CHAR(L_START_TIME, DATE_FMT));
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_max_time#', 
<                                             TO_CHAR(L_END_TIME, DATE_FMT));
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_duration#',
<                               ROUND((L_END_TIME - L_START_TIME)*DTOS));
<       L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#date_fmt#', DATE_FMT);
< 
<       L_RMMETRICS_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_REPORT_SQL);
---
>       BEGIN
>         SELECT SUM(NUM_CPUS)
>           INTO L_NUM_CPUS
>           FROM (
>             SELECT HOST_NAME, SUM(NUM_CPUS) AS NUM_CPUS
>               FROM TABLE(GV$(CURSOR(
>                      SELECT I.INSTANCE_NUMBER AS INST_ID, I.HOST_NAME,
>                             NVL(OS.NUM_CPUS, OS.NUM_CPU_CORES) AS NUM_CPUS
>                        FROM SYS.V$INSTANCE I, 
>                             (SELECT MAX(DECODE(STAT_NAME, 'NUM_CPUS', 
>                                                VALUE, NULL)) AS NUM_CPUS,
>                                     MAX(DECODE(STAT_NAME, 'NUM_CPU_CORES', 
>                                                VALUE, NULL)) AS NUM_CPU_CORES
>                                FROM SYS.V$OSSTAT
>                               WHERE STAT_NAME IN ('NUM_CPUS', 'NUM_CPU_CORES')
>                             ) OS)))
>             GROUP BY HOST_NAME);
>       EXCEPTION
>         WHEN OTHERS THEN
>           L_NUM_CPUS := 0;
>       END;
18485d18651
<     ELSE
18487,18502c18653,18661
<       EXECUTE IMMEDIATE L_QUERY
<          INTO L_RMMETRICS_XML
<         USING 0, L_CG_MAP,
<               TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
<               TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
<               TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
<               TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
<               L_BUCKET_INTERVAL,
<               TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT,
<               TO_CHAR(L_END_TIME, DATE_FMT), DATE_FMT,
<               L_INST_ID_LOW, L_INST_ID_HIGH,
<               
<               L_BUCKET_INTERVAL, L_BUCKET_COUNT,
<               TO_CHAR(L_START_TIME,DATE_FMT), TO_CHAR(L_END_TIME,DATE_FMT),
<               (L_END_TIME - L_START_TIME)*DTOS;
<     END IF;
---
>       L_QRY := RMMETRICS_COMMON;
>    
>       
>       L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETS_TAG#', 
>                               GENERATE_BUCKETS_TAG2);
>       L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETID_TAG#', 
>                               GENERATE_BUCKETID_TAG);
>       L_QRY := REPLACE(L_QRY,'#GENERATE_METRICS_BUCKETID#', 
>                               RMMETRICS_RT);
18504,18505c18663,18665
<     
<     DBMS_REPORT.GET_TIMING_INFO(1, L_ELAPSED, L_CPU);
---
>       IF (SHOW_SQL = 1) THEN
>         
>         L_SQL := RMMETRICS_RT_HEADER;
18507,18513c18667,18668
<     
<     
<     L_REPORT_XML :=
<       PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
<                          DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
<                            'awrv','topsql', L_REF_PARAMS),
<                          L_ELAPSED, L_CPU);
---
>         
>         L_SQL := L_SQL || L_QRY;
18515,18519c18670,18684
<     
<     
<     IF (L_RMMETRICS_XML IS NOT NULL) THEN
<       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_RMMETRICS_XML);
<     END IF;
---
>         
>         L_SQL := REPLACE(L_SQL, '#is_awr#', 0);
>         L_SQL := REPLACE(L_SQL, '#p_contTab#', 'null');
>         L_SQL := REPLACE(L_SQL, '#b_start_time#',
>                                  TO_CHAR(L_START_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time#',
>                                  TO_CHAR(L_END_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_min_time#', TO_CHAR(L_START_TIME, 
>                                                         DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_max_time#', TO_CHAR(L_END_TIME, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                  ROUND((L_END_TIME - L_START_TIME)*DTOS));
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
18521c18686,18711
<     <<DONE>>
---
>         L_SQL := REPLACE(L_SQL, '#resource_manager_enabled#', 
>                                 L_RESOURCE_MANAGER_ENABLED);
> 
>         L_SQL := REPLACE(L_SQL, '#num_cpus#', L_NUM_CPUS);
> 
>         L_RESULT_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_SQL);
> 
>       ELSE
>         
>         EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING 0, L_CG_MAP,
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT, 
>                 L_BUCKET_INTERVAL,
>                 L_RESOURCE_MANAGER_ENABLED,
>                 L_NUM_CPUS, L_NUM_CPUS,
>                 TO_CHAR(L_START_TIME, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_END_TIME, DATE_FMT), DATE_FMT,
>                 
>                 L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME,DATE_FMT), TO_CHAR(L_END_TIME,DATE_FMT),
>                 (L_END_TIME - L_START_TIME)*DTOS;
>       END IF;
18524,18531c18714,18792
<     IF (L_REPORT_XML IS NULL) THEN
<       
<       L_REPORT_XML :=
<         PRVT_REPORT_TAGS.BUILD_REPORT_TAG(
<           DBMS_REPORT.BUILD_REPORT_REFERENCE_STRUCT(
<             'awrv','topsql',L_REF_PARAMS),
<           NULL, NULL);
<     END IF;
---
>     ELSE
> 
>       IF (L_AWR_PERIOD IS NOT NULL) THEN
>         
>         CREATE_BUCKET_SNAP_MAP(L_AWR_PERIOD, L_BUCKET_MAP, 
>                                L_BUCKET_COUNT, L_BUCKET_INTERVAL);
> 
>         L_CON_ID := SYS_CONTEXT('USERENV','CON_ID');
> 
>         CREATE_CONSUMER_GROUP_MAP(L_CON_ID, L_AWR_PERIOD, L_CG_MAP);
> 
>         
>         L_QRY := RMMETRICS_COMMON;
>    
>         
>         L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETS_TAG#', 
>                                 GENERATE_BUCKETS_TAG2);
>         L_QRY := REPLACE(L_QRY,'#GENERATE_BUCKETID_TAG#', 
>                                 GENERATE_BUCKETID_TAG);
>         L_QRY := REPLACE(L_QRY,'#GENERATE_METRICS_BUCKETID#', 
>                                 RMMETRICS_AWR);
> 
>         
>         
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := RMMETRICS_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#is_awr#', 1);
>           L_SQL := REPLACE(L_SQL, '#p_contTab#', '');
>           L_SQL := REPLACE(L_SQL, '#bucket_map#', '');
>           L_SQL := REPLACE(L_SQL, '#m_dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#m_begin_snap#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#m_end_snap#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#l_con_dbid#', L_CON_DBID);
>           L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#b_min_time#', 
>                                    TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#b_max_time#', 
>                                    TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                            L_AWR_PERIOD.M_MAX_TIME, 
>                                            L_AWR_PERIOD.M_MIN_TIME)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING 1, 
>                 L_CG_MAP, 
>                 L_BUCKET_MAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_CON_DBID,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT),
>                 TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT),
>                 ROUND(
>                   INTERVAL_TO_SECOND(
>                     L_AWR_PERIOD.M_MAX_TIME, L_AWR_PERIOD.M_MIN_TIME));
>         END IF;
>       END IF;
18533,18535d18793
<     IF (L_SET_ENV) THEN
<       
<       DBMS_REPORT.RESTORE_REPORT_ENV(L_ORIG_ENV);
18537,18539d18794
<  
<     
<     RETURN L_REPORT_XML;
18541c18796
<   END REPORT_ADW_WORKLOAD_REALTIME;
---
>     RETURN L_RESULT_XML;
18542a18798
>   END GET_RMMETRICS_XML;
18566,18571c18822,18834
<   FUNCTION REPORT_ADW_WORKLOAD_HISTORICAL(
<     START_TIME        IN DATE           DEFAULT NULL,
<     END_TIME          IN DATE           DEFAULT NULL,
<     DBID              IN NUMBER         DEFAULT NULL,
<     INST_ID           IN NUMBER         DEFAULT NULL,
<     SHOW_SQL          IN NUMBER         DEFAULT 0)
---
>   
>   
>   
>   
>   FUNCTION GET_SQL_N_PARSE_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
18574,18576d18836
<     
<     L_ELAPSED        NUMBER;
<     L_CPU            NUMBER;
18579c18839,18840
<     L_REF_PARAMS     DBMS_REPORT.REF_STRING_IDSPEC;
---
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
18582,18583c18843
<     L_ORIG_ENV       DBMS_REPORT.FORMAT_PARAM_VALUES;
<     L_SET_ENV        BOOLEAN;
---
>     L_RESULT_XML XMLTYPE := NULL;
18586,18587c18846,18853
<     L_QUERY          VARCHAR2(32767) := NULL;
<     L_REPORT_SQL     CLOB;
---
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
18590,18591c18856
<     L_REPORT_XML     XMLTYPE := NULL;
<     L_RMMETRICS_XML  XMLTYPE := NULL;
---
>     L_CON_DBID NUMBER;
18592a18858,18921
>     
>     SQL_AND_PARSE_TIME_RT CONSTANT VARCHAR2(32767) := q'[
>       with base_data as (
>         SELECT bucket_id,
>                SUM(parse_time_sec) / :p_bucket_interval AS parse_aas,
>                SUM(sql_exec_time_sec) / :p_bucket_interval AS sql_exec_aas,
>                SUM(plsql_exec_time_sec) / :p_bucket_interval AS plsql_exec_aas
>           FROM TABLE(GV$(CURSOR(
>                  SELECT bucket_id, 
>                         SUM(parse_time_usec) / 1000000    as parse_time_sec,
>                         SUM(sql_exec_time_usec) / 1000000 as sql_exec_time_sec,
>                         SUM(plsql_exec_time_usec) / 1000000 
>                                                           as plsql_exec_time_sec
>                    FROM (
>                          SELECT TRUNC(((
>                                   cast(sample_time_utc as date) - 
>                                   to_date(:b_start_time_utc, :date_fmt)) 
>                                   * 86400 ) / :p_bucket_interval) + 1 
>                                     as bucket_id,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_parse = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as parse_time_usec,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_sql_execution = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as sql_exec_time_usec,
>                                 CASE 
>                                   WHEN (session_type = 'FOREGROUND' 
>                                         AND in_plsql_execution = 'Y') 
>                                   THEN usecs_per_row 
>                                   ELSE 0 
>                                 END as plsql_exec_time_usec
>                            FROM sys.v_$active_session_history 
>                           WHERE sample_time_utc > to_timestamp(
>                                                     :b_start_time_utc,
>                                                     :date_fmt) 
>                             AND sample_time_utc <= to_timestamp(
>                                                     :b_end_time_utc,:date_fmt)
>                         )
>                   WHERE bucket_id > 0
>                   GROUP BY bucket_id
>                )))
>         GROUP BY bucket_id
>         ORDER BY bucket_id)
>       select xmlelement("stattype",
>                xmlattributes('sql' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id    as "bucket_id"),
>                   xmlforest(round(parse_aas, 2)      as "parse_aas",
>                             round(sql_exec_aas, 2)   as "sql_aas",
>                             round(plsql_exec_aas, 2) as "plsql_aas")))))
>         from base_data
>        where (parse_aas + sql_exec_aas + plsql_exec_aas) > 0]';
18595,18600c18924,18940
<     L_START_TIME     DATE := START_TIME;
<     L_END_TIME       DATE := END_TIME;
<     L_DBID           NUMBER := DBID;
<     L_INST_ID        NUMBER := INST_ID;
<     L_CON_ID         NUMBER;
<     L_CON_DBID       NUMBER;
---
>     SQL_AND_PARSE_TIME_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>     var date_fmt          varchar2(32);
>     var b_start_time_utc  varchar2(32);
>     var b_end_time_utc    varchar2(32);
>     var p_bucket_interval number;
>     var p_bucket_count    number;
>     var b_duration        number;
>     begin 
>       :date_fmt            := '#date_fmt#';
>       :b_start_time_utc    := '#b_start_time_utc#';
>       :b_end_time_utc      := '#b_end_time_utc#';
>       :p_bucket_interval   := #p_bucket_interval#;
>       :p_bucket_count      := #p_bucket_count#;
>       :b_duration          := #b_duration#;
>     end;
>     /]';
> 
18603,18606c18943,19048
<     L_BUCKET_CALC_INTERVAL   NUMBER;
<     L_BUCKET_CALC_MAX_COUNT  NUMBER;
<     L_BUCKET_MAP             PRVT_AWRV_MAPTAB;
<     L_AWR_PERIOD             PRVT_AWRV_METADATA;
---
>     SQL_AND_PARSE_TIME_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, s.stat_name, 
>                   s.value / 1000000 as value_secs 
>              FROM awr_root_con_sys_time_model s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.stat_name IN ('parse time elapsed', 
>                                   'sql execute elapsed time', 
>                                   'PL/SQL execution elapsed time')
>           ),
>         diff_stats AS 
>           (SELECT estat.instance_number, estat.snap_id, estat.stat_name, 
>                   s.begin_time_utc, s.end_time_utc,
>                   GREATEST(estat.value_secs - 
>                            (s.diff_logic * NVL(bstat.value_secs,0)),0) /
>                   ((s.end_time_utc - s.begin_time_utc)*86400)
>                   as value_per_sec
>              FROM base_stats estat, snaps s, base_stats bstat
>             WHERE estat.instance_number = s.instance_number
>               AND estat.snap_id = s.snap_id
>               AND estat.instance_number = bstat.instance_number(+)
>               AND estat.snap_id-1 = bstat.snap_id(+)
>               AND estat.stat_name = bstat.stat_name(+)
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400)      as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         final_stats AS
>           (SELECT bucket_id, stat_name, 
>                   SUM(value_per_sec * bucket_ratio) as aas
>              FROM (
>                    SELECT b.bucket_id, s.stat_name, s.value_per_sec, 
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM diff_stats s, buckets b
>                     WHERE s.value_per_sec > 0
>                       AND b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, stat_name
>           ),
>         pivoted_stats AS
>           (SELECT * FROM final_stats
>            PIVOT(SUM(aas) FOR stat_name IN 
>                              ('parse time elapsed' as parse_aas,
>                               'sql execute elapsed time' as sql_exec_aas,
>                               'PL/SQL execution elapsed time' as plsql_exec_aas)
>                 )
>           ),
>         base_data AS
>           (SELECT bucket_id, parse_aas, sql_exec_aas, plsql_exec_aas
>              FROM pivoted_stats
>            ORDER BY bucket_id)
>       select xmlelement("stattype",
>                xmlattributes('sql' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id    as "bucket_id"),
>                   xmlforest(round(parse_aas, 2)      as "parse_aas",
>                             round(sql_exec_aas, 2)   as "sql_aas",
>                             round(plsql_exec_aas, 2) as "plsql_aas")))))
>         from base_data
>        where (parse_aas + sql_exec_aas + plsql_exec_aas) > 0]';
18609c19051,19060
<     L_CG_MAP PRVT_AWRV_INSTTAB := NULL;
---
>     SQL_AND_PARSE_TIME_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
18611c19062,19073
<     L_CPU_COUNT NUMBER := NULL;
---
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
18612a19075
>   BEGIN
18614,18615c19077,19079
<     L_ERRMSG                           VARCHAR2(32767);
<     L_ERROR_XML                        XMLTYPE := NULL;
---
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
18617,18668c19081,19775
<     ADW_RMMETRICS_AWR CONSTANT VARCHAR2(32767) := q'[
<     select bucket_id,
<            consumer_group_id,
<            consumer_group_name,
<            sum(avg_cpu_utilization) 
<                   avg_cpu_utilization,
<            sum(avg_active_parallel_stmts) 
<                   avg_active_parallel_stmts,
<            sum(avg_queued_parallel_stmts) 
<                   avg_queued_parallel_stmts
<      from (
<         select bucket_id,
<                consumer_group_name,  
<                consumer_group_id,
<                -- avg
<                avg(avg_cpu_utilization) 
<                   avg_cpu_utilization,
<                avg(avg_active_parallel_stmts) 
<                   avg_active_parallel_stmts,
<                avg(avg_queued_parallel_stmts) 
<                   avg_queued_parallel_stmts
<           from table(
<                  cast(:bucket_map as 
<                       sys.prvt_awrv_mapTab)) m,
<                (select /*+ no_merge */ snap_id,
<                        instance_number,
<                        consumer_group_id,
<                        null consumer_group_name,
<                        case 
<                          when :cpu_count is null or
<                               :cpu_count = 0 then
<                            avg_cpu_utilization
<                          else
<                            (avg_running_sessions/:cpu_count)*100
<                          end avg_cpu_utilization,
<                        avg_active_parallel_stmts,
<                        avg_queued_parallel_stmts
<                   from awr_pdb_rsrc_metric
<                  where dbid = :m_dbid 
<                    and snap_id between :m_begin_snap 
<                                    and :m_end_snap
<                    and con_dbid = :l_con_dbid) y
<          where m.snap_id         = y.snap_id
<            and m.instance_number = y.instance_number
<            and y.snap_id         > :m_begin_snap
<          group by bucket_id, 
<                y.instance_number, 
<                y.consumer_group_id, 
<                y.consumer_group_name)
<       group by bucket_id, 
<                consumer_group_id,
<                consumer_group_name]'; 
---
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
>       
>       L_QRY := SQL_AND_PARSE_TIME_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := SQL_AND_PARSE_TIME_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#',
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('sql_and_parse_time', L_SQL);
> 
>       ELSE
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>  
>     
>     ELSE
>       IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := SQL_AND_PARSE_TIME_AWR;
> 
>         
>         
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := SQL_AND_PARSE_TIME_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#', ROUND(INTERVAL_TO_SECOND(
>                                    L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('sql_and_parse_time', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                 ROUND(
>                   INTERVAL_TO_SECOND(L_END_TIME_UTC, L_START_TIME_UTC));
> 
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SQL_N_PARSE_TIME_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_WAIT_TIME_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     WAIT_TIME_RT CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         inst_data AS
>           (SELECT inst_id, bucket_id, metric_name, value
>              FROM TABLE(GV$(CURSOR(
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id, metric_name,
>                            SUM(value*bucket_ratio) as value
>                       FROM (
>                             SELECT USERENV('INSTANCE') as inst_id,
>                                    buckets.bucket_id,
>                                    met.metric_name,
>                                    met.value,
>                                    (LEAST(met.end_time_utc, 
>                                           buckets.end_time_utc) - 
>                                     GREATEST(met.begin_time_utc, 
>                                              buckets.begin_time_utc)) / 
>                                     (met.end_time_utc - met.begin_time_utc) 
>                                       as bucket_ratio
>                              FROM ( 
>                                    SELECT /*+ no_merge */ USERENV('INSTANCE') 
>                                                               as inst_id,
>                                           m.begin_time-tz.time_zone 
>                                                               as begin_time_utc,
>                                           m.end_time-tz.time_zone 
>                                                               as end_time_utc,
>                                           CASE
>                                             WHEN m.metric_name = 
>                                                    'Average Active Sessions'
>                                               THEN 'DBTime'
>                                             ELSE 'CPU'
>                                           END as metric_name,
>                                           CASE 
>                                             WHEN m.metric_name = 
>                                                    'CPU Usage Per Sec' 
>                                             THEN m.value*m.intsize_csec/10000
>                                             ELSE m.value*m.intsize_csec/100
>                                           END as value
>                                      FROM sys.v_$con_sysmetric_history m,
>                                           (SELECT ROUND(
>                                                     (cast(latest_sample_time 
>                                                           as date) - 
>                                                      cast(sys_extract_utc(
>                                                             systimestamp) 
>                                                           as date))
>                                                     *900,0)/900 as time_zone
>                                              FROM sys.v_$ash_info) tz
>                                     WHERE m.group_id = 18
>                                       AND m.metric_name IN 
>                                             ('Average Active Sessions',
>                                              'CPU Usage Per Sec')
>                                       AND m.begin_time-tz.time_zone < 
>                                           to_date(:b_end_time_utc, :date_fmt)
>                                       AND m.end_time-tz.time_zone >= 
>                                           to_date(:b_start_time_utc, :date_fmt)
>                                   ) met,    
>                                   ( 
>                                    SELECT /*+ no_merge */ level as bucket_id,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           ((level -1) * :p_bucket_interval 
>                                            / 86400) as begin_time_utc,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           (level * :p_bucket_interval / 86400) 
>                                                     as end_time_utc
>                                      FROM sys.v_$instance 
>                                           -- note: DUAL not allowed inside GV$
>                                    CONNECT BY level <= 
>                                               (to_date(:b_end_time_utc,
>                                                        :date_fmt) - 
>                                                to_date(:b_start_time_utc, 
>                                                        :date_fmt)) 
>                                               * 86400 / :p_bucket_interval
>                                   ) buckets
>                             WHERE buckets.begin_time_utc < met.end_time_utc
>                               AND buckets.end_time_utc > met.begin_time_utc
>                            )
>                     GROUP BY bucket_id, metric_name
>                     UNION ALL
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id,
>                            metric_name,
>                            SUM(value) as value
>                       FROM (
>                             SELECT TRUNC(((cast(sample_time_utc as date) - 
>                                                 to_date(:b_start_time_utc, 
>                                                         :date_fmt)) * 86400) / 
>                                    :p_bucket_interval) + 1 AS bucket_id,
>                                    DECODE(session_state, 'WAITING', wait_class, 
>                                                          'ASH_CPU') 
>                                                            AS metric_name,
>                                    CASE 
>                                      WHEN session_type = 'FOREGROUND' 
>                                      THEN usecs_per_row/1000000 
>                                      ELSE 0 
>                                    END AS value
>                               FROM sys.v_$active_session_history
>                              WHERE sample_time_utc >= 
>                                    to_timestamp(:b_start_time_utc, :date_fmt)
>                                AND sample_time_utc < 
>                                    to_timestamp(:b_end_time_utc, :date_fmt)
>                            )
>                     WHERE bucket_id > 0
>                     GROUP BY bucket_id, metric_name
>           )))),
>         db_data AS 
>           (SELECT bucket_id, metric_name, 
>                   SUM(value) as value
>              FROM inst_data
>            GROUP BY bucket_id, metric_name
>           ),
>         wait_for_cpu AS
>           (SELECT bucket_id, 'wait for CPU' as metric_name, 
>                   GREATEST(SUM(DECODE(metric_name, 'ASH_CPU', value, 
>                                       -value)), 0)    AS value
>              FROM db_data
>             WHERE metric_name IN ('CPU', 'ASH_CPU')
>            GROUP BY bucket_id
>           ),
>         final_data AS
>           (SELECT bucket_id, metric_name,
>                   value / :p_bucket_interval    AS value
>              FROM db_data
>             WHERE metric_name <> 'ASH_CPU'
>               AND value > 0
>            UNION ALL
>            SELECT bucket_id, metric_name, 
>                   value /:p_bucket_interval     AS value
>              FROM wait_for_cpu
>             WHERE value > 0
>           ),
>         base_data AS
>           (SELECT * FROM final_data
>            ORDER BY bucket_id, metric_name)
>       select xmlelement("stattype",
>                xmlattributes('wait_time' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")
>              ))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     WAIT_TIME_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var date_fmt          varchar2(32);
>       var b_start_time_utc  varchar2(32);
>       var b_end_time_utc    varchar2(32);
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_duration        number;
>       begin 
>         :date_fmt            := '#date_fmt#';
>         :b_start_time_utc    := '#b_start_time_utc#';
>         :b_end_time_utc      := '#b_end_time_utc#';
>         :p_bucket_interval   := #p_bucket_interval#;
>         :p_bucket_count      := #p_bucket_count#;
>         :b_duration          := #b_duration#;
>       end;
>       /]';
> 
>     
>     WAIT_TIME_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT e.instance_number, e.snap_id, e.wait_class, 
>                   SUM(e.time_waited_micro_fg)/1000000 as value
>              FROM awr_root_con_system_event e
>             WHERE e.dbid = :dbid
>               AND e.snap_id >= :begin_snap_id
>               AND e.snap_id <= :end_snap_id
>               AND e.wait_class <> 'Idle'
>            GROUP BY e.instance_number, e.snap_id, e.wait_class  
>            UNION ALL
>            SELECT s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN s.stat_name = 'DB time'
>                     THEN 'DBTime' 
>                     ELSE 'CPU'
>                   END as wait_class,
>                   s.value/1000000 as value
>              FROM awr_root_con_sys_time_model s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.stat_name IN ('DB time', 'DB CPU')
>           ),
>         agg_stats AS
>           (SELECT /*+ no_merge */ instance_number, snap_id, wait_class, 
>                   SUM(value) as value
>              FROM base_stats
>             WHERE value > 0
>            GROUP BY instance_number, snap_id, wait_class
>           ),
>         diff_stats AS 
>           (SELECT estat.instance_number, estat.snap_id, estat.wait_class, 
>                   s.begin_time_utc, s.end_time_utc,
>                   GREATEST(estat.value - 
>                            (s.diff_logic * NVL(bstat.value,0)),0) /
>                   ((s.end_time_utc - s.begin_time_utc)*86400)
>                   as value
>              FROM agg_stats estat, snaps s, agg_stats bstat
>             WHERE estat.instance_number = s.instance_number
>               AND estat.snap_id = s.snap_id
>               AND estat.instance_number = bstat.instance_number(+)
>               AND estat.snap_id-1 = bstat.snap_id(+)
>               AND estat.wait_class = bstat.wait_class(+)
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400) as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         db_stats AS
>           (SELECT bucket_id, wait_class, 
>                   SUM(value * bucket_ratio) as value
>              FROM (
>                    SELECT b.bucket_id, s.wait_class, s.value,
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM diff_stats s, buckets b
>                     WHERE b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, wait_class
>           ),
>         wait_for_cpu AS
>           (SELECT bucket_id, 'wait for CPU' as wait_class,
>                   GREATEST(SUM(DECODE(wait_class, 'DBTime', value, -value)), 
>                            0) as value
>              FROM db_stats
>            GROUP BY bucket_id
>           ),
>         final_stats AS 
>           (SELECT bucket_id, wait_class, value
>              FROM db_stats
>            UNION ALL
>            SELECT bucket_id, wait_class, value
>              FROM wait_for_cpu
>           ),
>        base_data AS
>          (SELECT bucket_id, wait_class, value
>             FROM final_stats
>           ORDER BY 1,2)
>       select xmlelement("stattype",
>                xmlattributes('wait_time' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("wait_class",
>                               xmlattributes(wait_class      as "name",
>                                             round(value, 2) as "value")))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     WAIT_TIME_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
> 
>       L_QRY := WAIT_TIME_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := WAIT_TIME_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#', 
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('wait_time', L_SQL);
> 
>       ELSE
> 
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           L_BUCKET_INTERVAL,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>     
>     
>     ELSE
>      IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := WAIT_TIME_AWR;
> 
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := WAIT_TIME_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                      L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('wait_time', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT),
>                 ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>         END IF;
> 
>       END IF;
18669a19777,20464
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_WAIT_TIME_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SYSMETRICS_XML(
>     IS_REALTIME     IN NUMBER             DEFAULT 1,
>     DBID            IN NUMBER             DEFAULT NULL,
>     START_TIME_UTC  IN DATE               DEFAULT NULL,
>     END_TIME_UTC    IN DATE               DEFAULT NULL,
>     BUCKET_COUNT    IN NUMBER             DEFAULT 128,
>     BUCKET_INTERVAL IN NUMBER             DEFAULT NULL,
>     AWR_PERIOD      IN PRVT_AWRV_METADATA DEFAULT NULL,
>     SHOW_SQL        IN NUMBER             DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
> 
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     L_IS_REALTIME     NUMBER             := IS_REALTIME;
>     L_DBID            NUMBER             := DBID;
>     L_START_TIME_UTC  DATE               := START_TIME_UTC;
>     L_END_TIME_UTC    DATE               := END_TIME_UTC;
>     L_BUCKET_COUNT    NUMBER             := BUCKET_COUNT;
>     L_BUCKET_INTERVAL NUMBER             := BUCKET_INTERVAL;
>     L_AWR_PERIOD      PRVT_AWRV_METADATA := AWR_PERIOD;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)       := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_CON_DBID NUMBER;
> 
>     
>     SYSMETRIC_RT CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         inst_data AS
>           (SELECT inst_id, bucket_id, metric_name, value
>              FROM TABLE(GV$(CURSOR(
>                     SELECT USERENV('INSTANCE') as inst_id,
>                            bucket_id, metric_name,
>                            SUM(value*bucket_ratio) as value
>                       FROM (
>                             SELECT USERENV('INSTANCE') as inst_id,
>                                    buckets.bucket_id,
>                                    met.metric_name,
>                                    met.value,
>                                    (LEAST(met.end_time_utc, 
>                                           buckets.end_time_utc) - 
>                                     GREATEST(met.begin_time_utc, 
>                                              buckets.begin_time_utc)) / 
>                                     (met.end_time_utc - met.begin_time_utc) 
>                                       as bucket_ratio
>                              FROM ( 
>                                    SELECT /*+ no_merge */ USERENV('INSTANCE') 
>                                                               as inst_id,
>                                           m.begin_time-tz.time_zone 
>                                                               as begin_time_utc,
>                                           m.end_time-tz.time_zone 
>                                                               as end_time_utc,
>                                           m.metric_name,
>                                           CASE 
>                                             WHEN m.metric_name = 
>                                                    'CPU Usage Per Sec' 
>                                             THEN m.value/100
>                                             ELSE m.value
>                                           END as value
>                                      FROM sys.v_$con_sysmetric_history m,
>                                           (SELECT ROUND(
>                                                     (cast(latest_sample_time 
>                                                           as date) - 
>                                                      cast(sys_extract_utc(
>                                                             systimestamp) 
>                                                           as date))
>                                                     *900,0)/900 as time_zone
>                                              FROM sys.v_$ash_info) tz
>                                     WHERE m.group_id = 18
>                                       AND m.metric_name IN 
>                                             ('Average Active Sessions',
>                                              'CPU Usage Per Sec',
>                                              'Executions Per Sec',
>                                              'User Calls Per Sec', 
>                                              'Total Parse Count Per Sec',
>                                              'User Commits Per Sec', 
>                                              'User Rollbacks Per Sec', 
>                                              'Session Count',
>                                              'Current Logons Count', 
>                                              'Logons Per Sec',
>                                              'Logons Per Txn',
>                                              'Redo Generated Per Sec',
>                                              'Redo Generated Per Txn',
>                                              'User Transaction Per Sec',
>                                              'Network Traffic Volume Per Sec',
>                                              'Hard Parse Count Per Sec',
>                                              'Parse Failure Count Per Sec',
>                                              'Current Open Cursors Count')
>                                       AND m.begin_time-tz.time_zone < 
>                                           to_date(:b_end_time_utc, :date_fmt)
>                                       AND m.end_time-tz.time_zone >= 
>                                           to_date(:b_start_time_utc, :date_fmt)
>                                   ) met,    
>                                   ( 
>                                    SELECT /*+ no_merge */ level as bucket_id,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           ((level -1) * :p_bucket_interval 
>                                            / 86400) as begin_time_utc,
>                                           to_date(:b_start_time_utc,:date_fmt) +
>                                           (level * :p_bucket_interval / 86400) 
>                                                     as end_time_utc
>                                      FROM sys.v_$instance 
>                                           -- note: DUAL not allowed inside GV$
>                                    CONNECT BY level <= 
>                                               (to_date(:b_end_time_utc,
>                                                        :date_fmt) - 
>                                                to_date(:b_start_time_utc, 
>                                                        :date_fmt)) 
>                                               * 86400 / :p_bucket_interval
>                                   ) buckets
>                             WHERE buckets.begin_time_utc < met.end_time_utc
>                               AND buckets.end_time_utc > met.begin_time_utc
>                            )
>                     GROUP BY bucket_id, metric_name)))),
>         db_data AS 
>           (SELECT bucket_id, metric_name, 
>                   SUM(value) as value
>              FROM inst_data
>            GROUP BY bucket_id, metric_name
>           ),
>         final_data AS
>           (SELECT bucket_id, metric_name,
>                   value AS value
>              FROM db_data
>             WHERE value > 0
>           ),
>         base_data AS
>           (SELECT * FROM final_data
>            ORDER BY bucket_id, metric_name)
>       select xmlelement("stattype",
>                xmlattributes('sysmetric' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:p_bucket_interval as "bucket_interval",
>                                :p_bucket_count    as "bucket_count",
>                                :b_start_time_utc  as "start_time_utc",
>                                :b_end_time_utc    as "end_time_utc",
>                                :b_duration        as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")
>              ))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     SYSMETRIC_RT_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var date_fmt          varchar2(32);
>       var b_start_time_utc  varchar2(32);
>       var b_end_time_utc    varchar2(32);
>       var p_bucket_interval number;
>       var p_bucket_count    number;
>       var b_duration        number;
>       begin 
>         :date_fmt            := '#date_fmt#';
>         :b_start_time_utc    := '#b_start_time_utc#';
>         :b_end_time_utc      := '#b_end_time_utc#';
>         :p_bucket_interval   := #p_bucket_interval#;
>         :p_bucket_count      := #p_bucket_count#;
>         :b_duration          := #b_duration#;
>       end;
>       /]';
> 
>     
>     SYSMETRIC_AWR CONSTANT VARCHAR2(32767) := q'[
>       WITH 
>         snaps AS
>           (SELECT /*+ no_merge */ s.instance_number, s.snap_id, 
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN CAST((p.open_time_tz at time zone 'UTC') AS DATE)
>                     ELSE CAST((s.begin_interval_time_tz at time zone 'UTC') 
>                               AS DATE)
>                   END as begin_time_utc,
>                   CAST((s.end_interval_time_tz at time zone 'UTC') AS DATE) 
>                       as end_time_utc,
>                   CASE 
>                     WHEN p.open_time_tz > s.begin_interval_time_tz 
>                     THEN 0 
>                     ELSE 1 
>                   END as diff_logic
>              FROM awr_root_snapshot s, awr_root_pdb_in_snap p
>             WHERE s.dbid = :dbid
>               AND p.dbid = :dbid
>               AND s.instance_number = p.instance_number
>               AND s.snap_id = p.snap_id
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND p.snap_id >= :begin_snap_id
>               AND p.snap_id <= :end_snap_id
>           ),
>         base_stats AS
>           (SELECT s.instance_number, s.snap_id,
>                   s.metric_name,
>                   CASE 
>                     WHEN s.metric_name = 
>                            'CPU Usage Per Sec' 
>                     THEN s.average/100
>                     ELSE s.average
>                   END as value
>              FROM awr_root_con_sysmetric_summ s
>             WHERE s.dbid = :dbid
>               AND s.snap_id >= :begin_snap_id
>               AND s.snap_id <= :end_snap_id
>               AND s.metric_name IN ('Average Active Sessions',
>                                     'CPU Usage Per Sec',
>                                     'Executions Per Sec',
>                                     'User Calls Per Sec', 
>                                     'Total Parse Count Per Sec',
>                                     'User Commits Per Sec', 
>                                     'User Rollbacks Per Sec', 
>                                     'Session Count',
>                                     'Current Logons Count', 
>                                     'Logons Per Sec',
>                                     'Logons Per Txn',
>                                     'Redo Generated Per Sec',
>                                     'Redo Generated Per Txn',
>                                     'User Transaction Per Sec',
>                                     'Network Traffic Volume Per Sec',
>                                     'Hard Parse Count Per Sec',
>                                     'Parse Failure Count Per Sec',
>                                     'Current Open Cursors Count')
>           ),
>         agg_stats AS
>           (SELECT /*+ no_merge */ instance_number, snap_id, metric_name, 
>                   SUM(value) as value
>              FROM base_stats
>             WHERE value > 0
>            GROUP BY instance_number, snap_id, metric_name
>           ),
>         snap_stats AS 
>           (SELECT a.instance_number, a.snap_id, a.metric_name, a.value,  
>                   s.begin_time_utc, s.end_time_utc
>              FROM agg_stats a, snaps s
>             WHERE a.instance_number = s.instance_number
>               AND a.snap_id = s.snap_id
>           ),
>         buckets AS
>           (SELECT level as bucket_id,
>                   to_date(:begin_time_utc, :date_format) + 
>                   ((level -1) * :bucket_interval_secs/86400) as begin_time_utc,
>                   to_date(:begin_time_utc, :date_format) + 
>                   (level * :bucket_interval_secs/86400) as end_time_utc
>              FROM sys.dual
>            CONNECT BY level <= (to_date(:end_time_utc, :date_format) - 
>                                 to_date(:begin_time_utc, :date_format)) 
>                                * 86400 / :bucket_interval_secs
>           ),
>         db_stats AS
>           (SELECT bucket_id, metric_name, 
>                   SUM(value * bucket_ratio) as value
>              FROM (
>                    SELECT b.bucket_id, s.metric_name, s.value,
>                           (LEAST(s.end_time_utc, b.end_time_utc) - 
>                            GREATEST(s.begin_time_utc, b.begin_time_utc))
>                           / (b.end_time_utc - b.begin_time_utc) as bucket_ratio
>                      FROM snap_stats s, buckets b
>                     WHERE b.end_time_utc > b.begin_time_utc
>                       AND s.begin_time_utc < b.end_time_utc
>                       AND s.end_time_utc > b.begin_time_utc
>                   )
>            GROUP BY bucket_id, metric_name
>           ),
>         base_data AS 
>           (SELECT bucket_id, metric_name, value
>              FROM db_stats
>            ORDER BY 1, 2)
>       select xmlelement("stattype",
>                xmlattributes('sysmetric' as "name"),
>                xmlelement("buckets",
>                  xmlattributes(:bucket_interval_secs as "bucket_interval",
>                                :bucket_count         as "bucket_count",
>                                :begin_time_utc       as "start_time_utc",
>                                :end_time_utc         as "end_time_utc",
>                                :duration             as "duration"),
>                  xmlagg(xmlelement("bucket",
>                           xmlattributes(bucket_id as "bucket_id"),
>                           xmlagg(
>                             xmlelement("metric",
>                               xmlattributes(metric_name     as "name",
>                                             round(value, 2) as "value")))))))
>         from base_data
>        where value > 0 
>        group by bucket_id]';
> 
>     SYSMETRIC_AWR_HEADER CONSTANT VARCHAR2(32767) := q'[
>       var dbid                 number;
>       var begin_snap_id        number;
>       var end_snap_id          number;
>       var begin_time_utc       varchar2(4000);
>       var end_time_utc         varchar2(4000);
>       var date_format          varchar2(32);
>       var bucket_interval_secs number;
>       var bucket_count         number;
>       var duration             number;
> 
>       begin
>         :dbid                 := #dbid#;
>         :begin_snap_id        := #begin_snap_id#;
>         :end_snap_id          := #end_snap_id#;
>         :begin_time_utc       := '#begin_time_utc#';
>         :end_time_utc         := '#end_time_utc#';
>         :date_format          := '#date_format#';
>         :bucket_interval_secs := #bucket_interval_secs#;
>         :bucket_count         := #bucket_count#;
>         :duration             := #duration#;
>     end;
>     /]';
> 
>   BEGIN
> 
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
> 
>     
>     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
> 
>     IF (DBID IS NULL) THEN
>       L_DBID := L_CON_DBID;
>     END IF;
> 
>     
>     IF (END_TIME_UTC IS NULL) THEN
>       L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE);
>     END IF;
> 
>     
>     IF (START_TIME_UTC IS NULL) THEN
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME_UTC := L_END_TIME_UTC - 1/24;
>       
>       ELSE
>         L_START_TIME_UTC := L_END_TIME_UTC - 1;
>       END IF;
>     END IF;
> 
>     
>     IF (BUCKET_COUNT IS NULL) THEN
>       L_BUCKET_COUNT := 60;
>     END IF;
> 
>     
>     IF (IS_REALTIME = 1) THEN
> 
>       L_QRY := SYSMETRIC_RT;
>     
>       
>       IF (SHOW_SQL = 1) THEN
> 
>         L_SQL := SYSMETRIC_RT_HEADER;
> 
>         
>         L_SQL := REPLACE(L_SQL, '#date_fmt#', DATE_FMT);
>         L_SQL := REPLACE(L_SQL, '#b_start_time_utc#',
>                                  TO_CHAR(L_START_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#b_end_time_utc#',
>                                  TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>         L_SQL := REPLACE(L_SQL, '#p_bucket_count#', L_BUCKET_COUNT);
>         L_SQL := REPLACE(L_SQL, '#p_bucket_interval#', L_BUCKET_INTERVAL);
>         L_SQL := REPLACE(L_SQL, '#b_duration#', 
>                                  ROUND(L_END_TIME_UTC-L_START_TIME_UTC)*DTOS);
> 
>         
>         L_SQL := L_SQL || L_QRY;
> 
>         
>         L_RESULT_XML := I_SHOW_SQL_XML('sysmetric', L_SQL);
> 
>       ELSE
> 
>         
>         EXECUTE IMMEDIATE L_QRY
>                      INTO L_RESULT_XML
>                     USING TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT), DATE_FMT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT), DATE_FMT,
>                           L_BUCKET_INTERVAL,
>                           
>                           L_BUCKET_INTERVAL, L_BUCKET_COUNT,
>                           TO_CHAR(L_START_TIME_UTC,DATE_FMT),
>                           TO_CHAR(L_END_TIME_UTC,DATE_FMT),
>                           ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>       END IF;
>     
>     
>     ELSE
>      IF (L_AWR_PERIOD IS NOT NULL) THEN
> 
>         
>         L_QRY := SYSMETRIC_AWR;
> 
>         IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>           L_AWR_VIEW_PREFIX := 
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_AWR_PERIOD.M_MIN_TIME);
> 
>           DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_QRY, L_AWR_VIEW_PREFIX);
>         END IF;
> 
>         IF (SHOW_SQL = 1) THEN
>           
>           L_SQL := SYSMETRIC_AWR_HEADER;
> 
>           
>           L_SQL := L_SQL || L_QRY;
> 
>           
>           L_SQL := REPLACE(L_SQL, '#dbid#', L_AWR_PERIOD.M_DBID);
>           L_SQL := REPLACE(L_SQL, '#begin_snap_id#', L_AWR_PERIOD.M_BEGIN_SNAP);
>           L_SQL := REPLACE(L_SQL, '#end_snap_id#', L_AWR_PERIOD.M_END_SNAP);
>           L_SQL := REPLACE(L_SQL, '#begin_time_utc#', 
>                                    TO_CHAR(L_START_TIME_UTC, DATE_FMT)); 
>           L_SQL := REPLACE(L_SQL, '#end_time_utc#', 
>                                    TO_CHAR(L_END_TIME_UTC, DATE_FMT));
>           L_SQL := REPLACE(L_SQL, '#date_format#', DATE_FMT);
>           L_SQL := REPLACE(L_SQL, '#bucket_count#', L_BUCKET_COUNT);
>           L_SQL := REPLACE(L_SQL, '#bucket_interval_secs#', 
>                                    L_BUCKET_INTERVAL);
>           L_SQL := REPLACE(L_SQL, '#duration#',
>                                    ROUND(INTERVAL_TO_SECOND(
>                                      L_END_TIME_UTC, L_START_TIME_UTC)));
> 
>           L_RESULT_XML := I_SHOW_SQL_XML('sysmetric', L_SQL);
> 
>         ELSE
>           EXECUTE IMMEDIATE L_QRY
>            INTO L_RESULT_XML
>           USING L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 L_AWR_PERIOD.M_DBID,
>                 L_AWR_PERIOD.M_BEGIN_SNAP,
>                 L_AWR_PERIOD.M_END_SNAP,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_INTERVAL,
>                 L_BUCKET_COUNT,
>                 TO_CHAR(L_START_TIME_UTC, DATE_FMT),
>                 TO_CHAR(L_END_TIME_UTC, DATE_FMT),
>                 ROUND((L_END_TIME_UTC - L_START_TIME_UTC)*DTOS);
>         END IF;
> 
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SYSMETRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_STORAGE_METRICS_XML(
>     SERVICE_TYPE IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL     IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
>     
>     L_QRY VARCHAR2(32767) := NULL;
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML XMLTYPE := NULL;
> 
>     
>     STORAGE_SERVERLESS CONSTANT VARCHAR2(32767) := q'[
>       select xmlelement("stattype",
>                xmlattributes(
>                  'storage'         as "name",
>                  max(c.max_size)   as "total",
>                  max(c.total_size) as "used",
>                  decode(max(c.max_size), 0, 0,
>                         (max(c.total_size)/max(c.max_size))*100) 
>                                    as "utilization"))
>         from sys.v_$containers c
>        where c.con_id > 2
>          and c.name <> 'PAASSEED']';
> 
>     
>     STORAGE_DEDICATED CONSTANT VARCHAR2(32767) := q'[
>       select xmlelement("stattype",
>                xmlattributes(
>                  'storage'         as "name",
>                  max(c.max_size)   as "total",
>                  max(c.total_size) as "used",
>                  decode(max(c.max_size), 0, 0,
>                         (max(c.total_size)/max(c.max_size))*100) 
>                                    as "utilization"),
>                xmlelement("tablespaces",
>                  xmlagg(
>                    xmlelement("tbs",
>                      xmlattributes(
>                        m.tablespace_name as "name",
>                        t.contents        as "type",
>                        ROUND((m.tablespace_size)*t.block_size, 3) total_space,
>                        ROUND((m.used_space)*t.block_size, 3) used_space,
>                        ROUND(m.used_percent, 2) used_pct)))))
>         from cdb_tablespace_usage_metrics m, 
>              cdb_tablespaces t,
>              sys.v_$containers c
>        where t.tablespace_name = m.tablespace_name
>          and c.con_id > 2
>          and c.name <> 'PAASSEED'
>          and m.con_id = c.con_id
>          and t.con_id = m.con_id]';
> 
>   BEGIN
> 
>     IF (SERVICE_TYPE IN (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D, 
>                          DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D)) THEN
>       L_QRY := STORAGE_DEDICATED;
>     ELSIF (SERVICE_TYPE IN (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S, 
>                             DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S)) THEN
>       L_QRY := STORAGE_SERVERLESS;
>     ELSE
>       L_QRY := STORAGE_DEDICATED;
>     END IF;
>    
>     
>     IF (SHOW_SQL = 1) THEN
> 
>       
>       L_SQL := L_QRY;
> 
>       
>       L_RESULT_XML := I_SHOW_SQL_XML('storage', L_SQL);
> 
>     ELSE
> 
>       
>       EXECUTE IMMEDIATE L_QRY
>                    INTO L_RESULT_XML;
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_STORAGE_METRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION GET_SESSION_METRICS_XML(
>     SHOW_SQL        IN NUMBER   DEFAULT NULL)
>   RETURN XMLTYPE
>   IS
>   
>     
>     L_SQL CLOB;
> 
>     
>     L_RESULT_XML        XMLTYPE := NULL;
>     L_FAILED_LOGONS_XML XMLTYPE := NULL;
> 
>     
>     NUM_CONNECTIONS_RT CONSTANT VARCHAR2(32767) := q'[
>       SELECT xmlelement("stattype",
>                xmlattributes('session' as "name"),
>                xmlelement("num_connections", count(*)))
>         FROM sys.gv_$session s
>        WHERE UPPER(s.service_name) not in 
>              (SELECT p.name FROM sys.v_$pdbs p WHERE p.con_id=s.con_id) 
>          AND UPPER(s.service_name) not in ('SYS$BACKGROUND','SYS$USERS') 
>          AND s.type='USER'
>          AND s.sid not in 
>              (SELECT ps.sid FROM sys.gv_$px_session ps)]';
> 
>     
>     NUM_FAILED_LOGONS_RT CONSTANT VARCHAR2(32767) := q'[
>       SELECT xmlelement("failed_logons", count(*))
>         FROM cdb_unified_audit_trail
>        WHERE action_name = 'LOGON'
>          AND return_code != 0]';
> 
>   BEGIN
>      
>     
>     IF (SHOW_SQL = 1) THEN
> 
>       L_SQL := NUM_CONNECTIONS_RT || NUM_FAILED_LOGONS_RT;
> 
>       
>       L_RESULT_XML := I_SHOW_SQL_XML('session', L_SQL);
> 
>     ELSE
> 
>       
>       EXECUTE IMMEDIATE NUM_CONNECTIONS_RT
>                    INTO L_RESULT_XML;
> 
>       EXECUTE IMMEDIATE NUM_FAILED_LOGONS_RT
>                    INTO L_FAILED_LOGONS_XML;
> 
>       IF (L_FAILED_LOGONS_XML IS NOT NULL) THEN
>         L_RESULT_XML := L_RESULT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                     L_FAILED_LOGONS_XML);
>       END IF;
> 
>     END IF;
> 
>     RETURN L_RESULT_XML;
> 
>   END GET_SESSION_METRICS_XML;
> 
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
18671,18700c20466,20643
<   ADW_RMMETRICS_AWR_SQL_HEADER   CONSTANT VARCHAR2(32767) := q'[
<       var is_awr            number;
<       var p_contTab         prvt_awrv_instTab;
<       var bucket_map        prvt_awrv_mapTab;
<       var cpu_count         number;
<       var m_dbid            number;
<       var m_begin_snap      number;
<       var m_end_snap        number;
<       var l_con_dbid        number;
<       var p_bucket_interval number;
<       var p_bucket_count    number;
<       var b_min_time        varchar2(4000);
<       var b_max_time        varchar2(4000);
<       var b_duration        number;
<       begin
<         :is_awr            := #is_awr#;
<         :p_contTab         := #p_contTab#;
<         :bucket_map        := #bucket_map#;
<         :cpu_count         := #cpu_count#;
<         :m_dbid            := #m_dbid#;
<         :m_begin_snap      := #m_begin_snap#;
<         :m_end_snap        := #m_end_snap#;
<         :l_con_dbid        := #l_con_dbid#;
<         :p_bucket_interval := #p_bucket_interval#;
<         :p_bucket_count    := #p_bucket_count#;
<         :b_min_time        := '#b_min_time#';
<         :b_max_time        := '#b_max_time#';
<         :b_duration        := #b_duration#;
<       end;
<       /]';
---
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   FUNCTION REPORT_WORKLOAD(
>     SERVICE_TYPE   IN VARCHAR2 DEFAULT NULL,
>     IS_REALTIME    IN NUMBER   DEFAULT 1,
>     DBID           IN NUMBER   DEFAULT NULL,
>     START_TIME     IN DATE     DEFAULT NULL,
>     END_TIME       IN DATE     DEFAULT NULL,
>     REPORT_LEVEL   IN VARCHAR2 DEFAULT NULL,
>     SHOW_SQL       IN NUMBER   DEFAULT 0)
>   RETURN XMLTYPE
>   IS
>     
>     L_ELAPSED NUMBER;
>     L_CPU     NUMBER;
> 
>     
>     L_REF_PARAMS DBMS_REPORT.REF_STRING_IDSPEC;
> 
>     
>     L_ORIG_ENV DBMS_REPORT.FORMAT_PARAM_VALUES;
>     L_SET_ENV  BOOLEAN;
> 
>     
>     L_REPORT_XML          XMLTYPE := NULL;
>     L_RM_METRICS_XML      XMLTYPE := NULL;
>     L_SYS_METRICS_XML     XMLTYPE := NULL;
>     L_SQL_TIME_XML        XMLTYPE := NULL;
>     L_WAIT_TIME_XML       XMLTYPE := NULL;
>     L_STORAGE_METRICS_XML XMLTYPE := NULL;
>     L_SESSION_METRICS_XML XMLTYPE := NULL;
> 
>     
>     L_SERVICE_TYPE   VARCHAR2(32767) := SERVICE_TYPE;
>     L_IS_REALTIME    NUMBER          := IS_REALTIME;
>     L_DBID           NUMBER          := DBID;
>     L_START_TIME     DATE            := START_TIME;
>     L_END_TIME       DATE            := END_TIME;
>     L_REPORT_LEVEL   VARCHAR2(32767) := REPORT_LEVEL;
>     L_TZ             VARCHAR2(10)    := NULL;
>     L_START_TIME_UTC DATE            := NULL;
>     L_END_TIME_UTC   DATE            := NULL;
>     L_BEGIN_SNAP_ID  NUMBER          := NULL;
>     L_END_SNAP_ID    NUMBER          := NULL;
> 
>     
>     L_BUCKET_COUNT    NUMBER;
>     L_BUCKET_INTERVAL NUMBER;
> 
>     
>     L_AWR_PERIOD PRVT_AWRV_METADATA;
> 
>     L_SNAP_QRY        VARCHAR2(32767) := NULL;
>     L_AWR_VIEW_PREFIX VARCHAR2(20)    := DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT;
> 
>     
>     L_ERRMSG    VARCHAR2(32767);
>     L_ERROR_XML XMLTYPE := NULL;
> 
>     
>     L_RSRCMGR_DETAIL   NUMBER;
>     L_SYSMETRIC_DETAIL NUMBER;
>     L_SQL_TIME_DETAIL  NUMBER;
>     L_WAIT_TIME_DETAIL NUMBER;
>     L_STORAGE_DETAIL   NUMBER;
>     L_SESSION_DETAIL   NUMBER;
> 
>     
>     
>     
>     FUNCTION I_PARSE_REPORT_LEVEL(
>       P_REPORT_LEVEL     IN  VARCHAR2,
>       P_RSRCMGR_DETAIL   OUT NUMBER,
>       P_SYSMETRIC_DETAIL OUT NUMBER,
>       P_SQL_TIME_DETAIL  OUT NUMBER,
>       P_WAIT_TIME_DETAIL OUT NUMBER,
>       P_STORAGE_DETAIL   OUT NUMBER,
>       P_SESSION_DETAIL   OUT NUMBER)
>     RETURN BOOLEAN
>     IS
>       L_REPORT_LEVEL VARCHAR2(32767) := 
>         REPLACE(LOWER(P_REPORT_LEVEL), ' ', NULL);
>       L_POS          NUMBER := 1;
>       L_SETVAL       NUMBER;
>     BEGIN
>       
>       P_RSRCMGR_DETAIL   := 1; 
>       P_SYSMETRIC_DETAIL := 1; 
>       P_SQL_TIME_DETAIL  := 1; 
>       P_WAIT_TIME_DETAIL := 1; 
>       P_STORAGE_DETAIL   := 1; 
>       P_SESSION_DETAIL   := 1; 
> 
>        
>       IF (L_REPORT_LEVEL IS NULL) THEN
>         RETURN TRUE;
>       END IF;
> 
>       
>       L_POS := 1;
> 
>       
>       IF (SUBSTR(L_REPORT_LEVEL, L_POS, 3) = 'all') THEN
>         
>         
>         L_POS := L_POS + 3;
>       
>       ELSIF (SUBSTR(L_REPORT_LEVEL, L_POS, 4) = 'none') THEN
>         P_RSRCMGR_DETAIL := 0;
>         P_SYSMETRIC_DETAIL := 0;
>         P_SQL_TIME_DETAIL := 0;
>         P_WAIT_TIME_DETAIL := 0;
>         P_STORAGE_DETAIL := 0;
>         P_SESSION_DETAIL := 0;
>         L_POS := L_POS + 4;
>       END IF;
> 
>       
>       WHILE (L_POS < LENGTH(L_REPORT_LEVEL))
>       LOOP
>         IF (SUBSTR(L_REPORT_LEVEL, L_POS, 1) = '-') THEN
>           L_SETVAL   := 0;
>           L_POS      := L_POS + 1;
>         ELSE
>           L_SETVAL   := 1;
>           IF (SUBSTR(L_REPORT_LEVEL, L_POS, 1) = '+') THEN
>             L_POS := L_POS + 1;
>           END IF;
>         END IF;
> 
>         CASE
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'rsrcmgr') THEN
>             P_RSRCMGR_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 9) = 'sysmetric') THEN
>             P_SYSMETRIC_DETAIL := L_SETVAL;
>             L_POS := L_POS + 9;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 3) = 'sql') THEN
>             P_SQL_TIME_DETAIL := L_SETVAL;
>             L_POS := L_POS + 3;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 4) = 'wait') THEN
>             P_WAIT_TIME_DETAIL := L_SETVAL;
>             L_POS := L_POS + 4;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'storage') THEN
>             P_STORAGE_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
> 
>           
>           WHEN (SUBSTR(L_REPORT_LEVEL, L_POS, 7) = 'session') THEN
>             P_SESSION_DETAIL := L_SETVAL;
>             L_POS := L_POS + 7;
>             
>           ELSE
>             
>             RETURN FALSE;
>         END CASE;
>       END LOOP;
18701a20645,20648
>       
>       RETURN TRUE;
>       
>     END I_PARSE_REPORT_LEVEL;
18714a20662,20673
>     IF (SERVICE_TYPE IS NOT NULL) THEN
>       L_REF_PARAMS('service_type') := SERVICE_TYPE;
>     END IF;
> 
>     IF (IS_REALTIME IS NOT NULL) THEN
>       L_REF_PARAMS('is_realtime') := IS_REALTIME;
>     END IF;
> 
>     IF (DBID IS NOT NULL) THEN
>       L_REF_PARAMS('dbid') := DBID;
>     END IF;
> 
18725,18730c20684,20685
<     IF (DBID IS NOT NULL) THEN
<       L_REF_PARAMS('dbid') := TO_CHAR(DBID);
<     END IF;
< 
<     IF (INST_ID IS NOT NULL) THEN
<       L_REF_PARAMS('inst_id') := TO_CHAR(INST_ID);
---
>     IF (REPORT_LEVEL IS NOT NULL) THEN
>       L_REF_PARAMS('report_level') := REPORT_LEVEL;
18733,18734d20687
<     L_REF_PARAMS('is_realtime') := 0;
< 
18737a20691,20697
>    
>     
>     
>     
>     IF (IS_REALTIME IS NULL) THEN
>       L_IS_REALTIME := 1;
>     END IF;
18739c20699,20702
<     L_CON_DBID := SYS_CONTEXT('USERENV','CON_DBID');
---
>     
>     IF (DBID IS NULL) THEN
>       L_DBID := SYS_CONTEXT('USERENV','CON_DBID');
>     END IF;
18742,18743c20705,20706
<     IF (L_DBID IS NULL) THEN
<       L_DBID := L_CON_DBID;
---
>     IF (REPORT_LEVEL IS NULL) THEN
>       L_REPORT_LEVEL := 'all';
18753c20716,20722
<       L_START_TIME := L_END_TIME - 1;
---
>       
>       IF (L_IS_REALTIME = 1) THEN
>         L_START_TIME := L_END_TIME - 1/24;
>       
>       ELSE
>         L_START_TIME := L_END_TIME - 1;
>       END IF;
18757,18761c20726,20731
<     
<     L_AWR_PERIOD := PRVT_AWRV_METADATA(
<                         P_START_TIME => L_START_TIME, 
<                         P_END_TIME => L_END_TIME,
<                         P_DBID => L_DBID);
---
>     L_TZ := DBMS_SQLTUNE_UTIL2.GET_TZ_OFFSET();
>     L_END_TIME_UTC := CAST(SYS_EXTRACT_UTC(
>                             TO_TIMESTAMP_TZ(
>                               TO_CHAR(L_END_TIME, 'yyyy-mm-dd hh24:mi:ss') 
>                               || L_TZ,
>                               'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE);
18763,18766d20732
<     
<     IF (L_AWR_PERIOD.M_BEGIN_SNAP IS NULL OR
<         L_AWR_PERIOD.M_BEGIN_SNAP = L_AWR_PERIOD.M_END_SNAP) 
<     THEN
18768,18776c20734,20739
<       L_ERRMSG := '[' || L_AWR_PERIOD.M_DBID || ']' ||
<                   '[' || L_AWR_PERIOD.M_INST_ID_LOW || '.' ||
<                          L_AWR_PERIOD.M_INST_ID_HIGH || ']' ||
<                   '[' || L_AWR_PERIOD.M_BEGIN_SNAP || '.' || 
<                          L_AWR_PERIOD.M_END_SNAP || ']' ||
<                   '[' || TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, 
<                                  DBMS_REPORT.DATE_FMT) || '-' ||
<                          TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, 
<                                  DBMS_REPORT.DATE_FMT) || ']';
---
>     
>     L_START_TIME_UTC := CAST(SYS_EXTRACT_UTC(
>                               TO_TIMESTAMP_TZ(
>                                 TO_CHAR(L_START_TIME, 'yyyy-mm-dd hh24:mi:ss') 
>                                 || L_TZ,
>                                 'yyyy-mm-dd hh24:mi:ssTZH:TZM')) AS DATE);
18777a20741,20746
>     
>     IF (L_IS_REALTIME = 1) THEN
>       CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
>                         (L_END_TIME - L_START_TIME)*DTOS,
>                         G_METRIC_SOURCE_HISTORY);
>     ELSE
18779c20748,20750
<       L_AWR_PERIOD := NULL;
---
>       CALCULATE_BUCKETS(L_BUCKET_COUNT, L_BUCKET_INTERVAL, 
>                         (L_END_TIME - L_START_TIME)*DTOS,
>                         NULL);
18782,18785c20753,20760
<       L_ERROR_XML := ERROR_XML('report_adw_workload_historical',
<                                -20800,
<                                'Insufficient awr data', 
<                                L_ERRMSG);
---
>       L_SNAP_QRY := q'[
>         SELECT MIN(snap_id)-1, MAX(snap_id)
>           FROM awr_root_snapshot
>          WHERE dbid = :l_dbid
>            AND cast((end_interval_time_tz at time zone 'UTC') as DATE)
>                 > to_date(:l_start_time_utc, :date_fmt)
>            AND cast((begin_interval_time_tz at time zone 'UTC') as DATE)
>                 < to_date(:l_end_time_utc, :date_fmt)]';
18787,18792c20762,20764
<     ELSE
< 
<       
<       L_BUCKET_CALC_MAX_COUNT := 128;
<       CREATE_BUCKET_SNAP_MAP(L_AWR_PERIOD, L_BUCKET_MAP, 
<                              L_BUCKET_CALC_MAX_COUNT, L_BUCKET_CALC_INTERVAL);
---
>       IF (SYS_CONTEXT('USERENV','CON_ID') > 2) THEN
>         L_AWR_VIEW_PREFIX := 
>           DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(L_START_TIME);
18794c20766,20768
<       L_CON_ID := SYS_CONTEXT('USERENV','CON_ID');
---
>         DBMS_SQLTUNE_UTIL1.REPLACE_AWR_VIEW_PREFIX(L_SNAP_QRY, 
>                                                    L_AWR_VIEW_PREFIX);
>       END IF;
18796c20770,20772
<       CREATE_CONSUMER_GROUP_MAP(L_CON_ID, L_AWR_PERIOD, L_CG_MAP);
---
>       IF (L_AWR_VIEW_PREFIX = DBMS_SQLTUNE_UTIL1.AWR_VIEW_ROOT) THEN
>         L_DBID := SYS_CONTEXT('USERENV','DBID');
>       END IF;
18798d20773
<       
18800,18803c20775,20779
<         SELECT VALUE
<           INTO L_CPU_COUNT   
<           FROM V$SYSTEM_PARAMETER2                 
<          WHERE NAME = 'cpu_count';
---
>         EXECUTE IMMEDIATE L_SNAP_QRY
>         INTO L_BEGIN_SNAP_ID, L_END_SNAP_ID
>         USING L_DBID, 
>               TO_CHAR(L_START_TIME_UTC, DATE_FMT), DATE_FMT,
>               TO_CHAR(L_END_TIME_UTC, DATE_FMT), DATE_FMT;
18805,18806c20781,20783
<         WHEN OTHERS THEN
<           L_CPU_COUNT := NULL;
---
>         WHEN NO_DATA_FOUND THEN
>           L_BEGIN_SNAP_ID := NULL;
>           L_END_SNAP_ID := NULL;
18810,18811d20786
<       L_QUERY := ADW_RMMETRICS_COMMON;
<    
18813,18818c20788,20795
<       L_QUERY := REPLACE(L_QUERY,'#GENERATE_BUCKETS_TAG#', 
<                                   GENERATE_BUCKETS_TAG2);
<       L_QUERY := REPLACE(L_QUERY,'#GENERATE_BUCKETID_TAG#', 
<                                   GENERATE_BUCKETID_TAG);
<       L_QUERY := REPLACE(L_QUERY,'#GENERATE_METRICS_BUCKETID#', 
<                                   ADW_RMMETRICS_AWR);
---
>       L_AWR_PERIOD := PRVT_AWRV_METADATA(P_START_TIME => L_START_TIME, 
>                                          P_END_TIME => L_END_TIME,
>                                          P_DBID => L_DBID);
> 
>       L_AWR_PERIOD.M_BEGIN_SNAP := L_BEGIN_SNAP_ID;
>       L_AWR_PERIOD.M_END_SNAP := L_END_SNAP_ID;
>       L_AWR_PERIOD.M_MIN_TIME := L_START_TIME;
>       L_AWR_PERIOD.M_MAX_TIME := L_END_TIME;
18820,18822c20797,20800
<       IF (SHOW_SQL = 1) THEN
<         
<         L_REPORT_SQL := ADW_RMMETRICS_AWR_SQL_HEADER;
---
>       
>       IF (L_AWR_PERIOD.M_BEGIN_SNAP IS NULL OR
>           L_AWR_PERIOD.M_BEGIN_SNAP = L_AWR_PERIOD.M_END_SNAP)
>       THEN
18823a20802,20810
>         L_ERRMSG := '[' || L_AWR_PERIOD.M_DBID || ']' ||
>                     '[' || L_AWR_PERIOD.M_INST_ID_LOW || '.' ||
>                            L_AWR_PERIOD.M_INST_ID_HIGH || ']' ||
>                     '[' || L_AWR_PERIOD.M_BEGIN_SNAP || '.' || 
>                            L_AWR_PERIOD.M_END_SNAP || ']' ||
>                     '[' || TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, 
>                                    DBMS_REPORT.DATE_FMT) || '-' ||
>                            TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, 
>                                    DBMS_REPORT.DATE_FMT) || ']';
18825c20812
<         L_REPORT_SQL := L_REPORT_SQL || L_QUERY;
---
>         L_AWR_PERIOD := NULL;
18828,18852c20815,20818
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#is_awr#', 1);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_contTab#', '');
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#bucket_map#', '');
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#cpu_count#', L_CPU_COUNT);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#m_dbid#', L_AWR_PERIOD.M_DBID);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#m_begin_snap#', 
<                                               L_AWR_PERIOD.M_BEGIN_SNAP);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#m_end_snap#', 
<                                               L_AWR_PERIOD.M_END_SNAP);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#l_con_dbid#', L_CON_DBID);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_bucket_count#', 
<                                               L_BUCKET_CALC_MAX_COUNT);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#p_bucket_interval#', 
<                                               L_BUCKET_CALC_INTERVAL);
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_min_time#', 
<                                 TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT));
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_max_time#', 
<                                 TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT));
<         L_REPORT_SQL := REPLACE(L_REPORT_SQL, '#b_duration#',
<                                 ROUND(INTERVAL_TO_SECOND(
<                                   L_AWR_PERIOD.M_MAX_TIME, 
<                                   L_AWR_PERIOD.M_MIN_TIME)));
< 
<         L_RMMETRICS_XML := I_SHOW_SQL_XML('rsrcmgrmetric', L_REPORT_SQL);
< 
---
>         L_ERROR_XML := ERROR_XML('report_workload',
>                                  -20800,
>                                  'Insufficient awr data', 
>                                  L_ERRMSG);
18855,18872c20821,20822
<         EXECUTE IMMEDIATE L_QUERY
<          INTO L_RMMETRICS_XML
<         USING 1, 
<               L_CG_MAP, 
<               L_BUCKET_MAP,
<               L_CPU_COUNT, L_CPU_COUNT, L_CPU_COUNT,
<               L_AWR_PERIOD.M_DBID,
<               L_AWR_PERIOD.M_BEGIN_SNAP,
<               L_AWR_PERIOD.M_END_SNAP,
<               L_CON_DBID,
<               L_AWR_PERIOD.M_BEGIN_SNAP,
<               L_BUCKET_CALC_INTERVAL,
<               L_BUCKET_CALC_MAX_COUNT,
<               TO_CHAR(L_AWR_PERIOD.M_MIN_TIME, DATE_FMT),
<               TO_CHAR(L_AWR_PERIOD.M_MAX_TIME, DATE_FMT),
<               ROUND(
<                 INTERVAL_TO_SECOND(
<                   L_AWR_PERIOD.M_MAX_TIME, L_AWR_PERIOD.M_MIN_TIME));
---
>         L_ERRMSG := NULL;
>         L_ERROR_XML := NULL;
18878a20829,20901
>     IF (NOT I_PARSE_REPORT_LEVEL(L_REPORT_LEVEL, L_RSRCMGR_DETAIL, 
>                                  L_SYSMETRIC_DETAIL, L_SQL_TIME_DETAIL,
>                                  L_WAIT_TIME_DETAIL, L_STORAGE_DETAIL,
>                                  L_SESSION_DETAIL)) THEN
>       SYS.DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(SYS_ERR_PARAM, 'report_level');
>     END IF;
> 
>     
>     IF (L_RSRCMGR_DETAIL = 1) THEN
>       L_RM_METRICS_XML := GET_RMMETRICS_XML(L_IS_REALTIME, 
>                                             L_DBID,
>                                             L_START_TIME,
>                                             L_END_TIME,
>                                             L_BUCKET_COUNT,
>                                             L_BUCKET_INTERVAL,
>                                             L_AWR_PERIOD,
>                                             SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_SYSMETRIC_DETAIL = 1) THEN        
>         L_SYS_METRICS_XML := GET_SYSMETRICS_XML(L_IS_REALTIME,
>                                                 L_DBID,
>                                                 L_START_TIME_UTC,
>                                                 L_END_TIME_UTC,
>                                                 L_BUCKET_COUNT,
>                                                 L_BUCKET_INTERVAL,
>                                                 L_AWR_PERIOD,
>                                                 SHOW_SQL);
>     END IF;
> 
>     
>     
>     
>     
>     
>     IF (L_SQL_TIME_DETAIL = 1) THEN
>       L_SQL_TIME_XML := GET_SQL_N_PARSE_TIME_XML(L_IS_REALTIME,
>                                                  L_DBID,
>                                                  L_START_TIME_UTC,
>                                                  L_END_TIME_UTC,
>                                                  L_BUCKET_COUNT,
>                                                  L_BUCKET_INTERVAL,
>                                                  L_AWR_PERIOD,
>                                                  SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_WAIT_TIME_DETAIL = 1) THEN
>       L_WAIT_TIME_XML := GET_WAIT_TIME_XML(L_IS_REALTIME,
>                                            L_DBID,
>                                            L_START_TIME_UTC,
>                                            L_END_TIME_UTC,
>                                            L_BUCKET_COUNT,
>                                            L_BUCKET_INTERVAL,
>                                            L_AWR_PERIOD,
>                                            SHOW_SQL);
>     END IF;
> 
>     
>     IF (L_STORAGE_DETAIL = 1) THEN
>       L_STORAGE_METRICS_XML := GET_STORAGE_METRICS_XML(L_SERVICE_TYPE,
>                                                        SHOW_SQL);
>     END IF;
> 
>     
>     
>     
>     IF (L_SESSION_DETAIL = 1) THEN
>       L_SESSION_METRICS_XML := GET_SESSION_METRICS_XML(SHOW_SQL);
>     END IF;
> 
>     
18890,18891d20912
<     IF (L_ERROR_XML IS NOT NULL) THEN
<       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_ERROR_XML);
18893,18897c20914,20937
<     ELSE
<       
<       IF (L_RMMETRICS_XML IS NOT NULL) THEN
<         L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_RMMETRICS_XML);
<       END IF;
---
>     IF (L_RM_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_RM_METRICS_XML);
>     END IF;
> 
>     IF (L_SYS_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_SYS_METRICS_XML);
>     END IF;
> 
>     IF (L_SQL_TIME_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_SQL_TIME_XML);
>     END IF;
> 
>     IF (L_WAIT_TIME_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, L_WAIT_TIME_XML);
>     END IF;
> 
>     IF (L_STORAGE_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_STORAGE_METRICS_XML);
>     END IF;
>     
>     IF (L_SESSION_METRICS_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_SESSION_METRICS_XML);
18900c20940,20943
<     <<DONE>>    
---
>     IF (L_ERROR_XML IS NOT NULL) THEN
>       L_REPORT_XML := L_REPORT_XML.APPENDCHILDXML(XML_ROOT, 
>                                                   L_ERROR_XML);
>     END IF;
18901a20945,20946
>     <<DONE>>
>     
18920c20965,20966
<   END REPORT_ADW_WORKLOAD_HISTORICAL;
---
>   END REPORT_WORKLOAD;
> 
SYS.DBMS_FEATURE_IMC - PROCEDURE (RU):
13a14
>     cell_level_value            number;
18a20
>     cell_level_value            := 0;
68c70
<     -- all instances
---
>     -- all instances, excluding instances where base level mode is enabled
70,71c72,77
<        'select nvl(max(value),0) from gv$parameter where ' ||
<        'name = ''inmemory_size'''
---
>        'select nvl(max(A.value),0) from ' ||
>          '(select value, inst_id from gv$parameter where ' ||
>            'name=''inmemory_size'') A, ' ||
>          '(select value, inst_id from gv$parameter where ' ||
>            'name=''inmemory_force'') B ' ||
>        'where A.inst_id = B.inst_id and upper(B.value) != ''BASE_LEVEL'''
73a80,84
>     execute immediate
>        'select count(*) from gv$parameter where ' ||
>          'upper(value) = ''CELLMEMORY_LEVEL'''
>     into cell_level_value;
> 
88c99,101
<                   to_char(num_tab_part_cc);
---
>                   to_char(num_tab_part_cc) ||
>         ', ' || 'CellMemory Level: ' ||
>                   to_char(cell_level_value);
89a103
>     -- Do we want to report feature use for cell level
91,92c105,107
<           AND (inmemory_size_value > 0))
<     OR  (num_tab_cc + num_tab_part_cc > 0))
---
>          AND (inmemory_size_value > 0))
>     OR  (num_tab_cc + num_tab_part_cc > 0)
>     OR  (cell_level_value > 0))
SYS.PRVT_AWRV_METADATA - TYPE BODY (RU):
288,290c288,294
<         IF (M_RESOLVED_DB_TYPE 
<           IN (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, 
<                 DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP))
---
> 
>         IF (M_RESOLVED_DB_TYPE IN
>               (DBMS_SQLTUNE_UTIL2.DB_TYPE_PDB, 
>                DBMS_SQLTUNE_UTIL2.DB_TYPE_IMP)
>             AND
>             DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(P_START_TIME) = 
>               DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB)
432c436,438
<     IF (SYS.DBMS_SQLTUNE_UTIL0.CDB_IS_PDB(L_CON_NAME, L_CON_ID)) THEN  
---
>     IF (SYS.DBMS_SQLTUNE_UTIL0.CDB_IS_PDB(L_CON_NAME, L_CON_ID) AND
>         DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(P_START_TIME) = 
>           DBMS_SQLTUNE_UTIL1.AWR_VIEW_PDB) THEN  
SYS.WRI$_REPT_ASH_OMX - TYPE BODY (RU):
25a26
>     L_RESOLUTION        VARCHAR2(2000)  := 'medium';
86a88,91
>       L_RESOLUTION := SYS.DBMS_REPORT.GET_PARAM(L_PARAMS,'resolution',
>                                                 NULLABLE=>TRUE);
> 
>       
99a105
>                         RESOLUTION      => L_RESOLUTION,
155a162,165
>       
>       L_RESOLUTION := SYS.DBMS_REPORT.GET_PARAM(L_PARAMS,'resolution',
>                                                 NULLABLE=>TRUE);
> 
168a179
>                         RESOLUTION      => L_RESOLUTION,
SYS.WRI$_REPT_AWRV - TYPE BODY (RU):
63a64
>     L_SERVICE_TYPE     VARCHAR2(32);
534d534
< 
550,551c550
<       P_INST_ID := TO_NUMBER(
<                      DBMS_REPORT.GET_PARAM(PARAMS,'inst_id',NULLABLE=>TRUE));
---
>       P_DBID := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'dbid',NULLABLE=>TRUE));
554c553,554
<       P_DBID := TO_NUMBER(DBMS_REPORT.GET_PARAM(PARAMS,'dbid',NULLABLE=>TRUE));
---
>       P_INST_ID := TO_NUMBER(
>                        DBMS_REPORT.GET_PARAM(PARAMS,'inst_id',NULLABLE=>TRUE));
562,566d561
<       P_INCLUDE_SQLS := TO_NUMBER(
<                           DBMS_REPORT.GET_PARAM(PARAMS,'include_sqls', 
<                                                 NULLABLE=>TRUE));
< 
<       
569a565,566
>       L_SERVICE_TYPE := DBMS_SQLTUNE_UTIL2.GET_CLOUD_SERVICE_TYPE();
> 
572,588c569,588
<       IF (DBMS_SQLTUNE_UTIL2.IS_ADW() AND SYS_CONTEXT('USERENV', 'CON_ID') > 2) 
<       THEN
<         IF (P_IS_REALTIME = 0) THEN
<           REPORT_XML := PRVT_AWR_VIEWER.REPORT_ADW_WORKLOAD_HISTORICAL(
<                           START_TIME        => P_START_TIME,
<                           END_TIME          => P_END_TIME,
<                           DBID              => P_DBID,
<                           INST_ID           => P_INST_ID,
<                           SHOW_SQL          => P_SHOW_SQL);
<         ELSE
<           REPORT_XML := PRVT_AWR_VIEWER.REPORT_ADW_WORKLOAD_REALTIME(
<                           START_TIME        => P_START_TIME,
<                           END_TIME          => P_END_TIME,
<                           INST_ID_LOW       => P_INST_ID,
<                           INST_ID_HIGH      => P_INST_ID,
<                           SHOW_SQL          => P_SHOW_SQL);
<         END IF;
---
>       IF (PRVT_EMX.IS_OMX() OR
>           (L_SERVICE_TYPE IN 
>             (DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ADW_D,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_S,
>              DBMS_SQLTUNE_UTIL2.CLOUD_SERVICE_TYPE_ATP_D)
>            AND SYS_CONTEXT('USERENV', 'CON_ID') > 2)) THEN
> 
>         
>         P_REPORT_LEVEL := DBMS_REPORT.GET_PARAM(PARAMS,'report_level',
>                                                 NULLABLE=>TRUE);
> 
>         REPORT_XML := PRVT_AWR_VIEWER.REPORT_WORKLOAD(
>                         SERVICE_TYPE => L_SERVICE_TYPE,
>                         IS_REALTIME  => P_IS_REALTIME,
>                         START_TIME   => P_START_TIME,
>                         END_TIME     => P_END_TIME,
>                         DBID         => P_DBID,
>                         REPORT_LEVEL => P_REPORT_LEVEL,
>                         SHOW_SQL     => P_SHOW_SQL);
591a592
> 
593,594c594,596
<         
<         
---
>         P_INCLUDE_SQLS := TO_NUMBER(
>                             DBMS_REPORT.GET_PARAM(PARAMS,'include_sqls', 
>                                                   NULLABLE=>TRUE));
SYS.WRI$_REPT_PERF - TYPE BODY (RU):
39a40
>     P_IS_OMX               NUMBER;
125a127,129
>     P_IS_OMX := CASE WHEN SYS.PRVT_EMX.IS_OMX() THEN 1 ELSE 0 END;
> 
>     
140a145
>                       IS_OMX              => P_IS_OMX,
SYS.WRI$_REPT_SESSION - TYPE BODY (RU):
148c148
< 						   P_INST_ID=>V_INST_ID,
---
>                                                    P_INST_ID=>V_INST_ID,
SYS.DBA_WORKLOAD_CAPTURES - VIEW (RU):
33c33
<  , encryption_verifier
---
>  , r.encryption_verifier
SYS.INT$DBA_JSON_DATAGUIDES - VIEW (RU):
1,5c1,43
< SELECT OBJECT_ID, OBJECT_TYPE#, OWNER, TABLE_NAME, COLUMN_NAME,
<        sys.dg$getDgQuoteName(OWNER, TABLE_NAME, COLUMN_NAME,
<                          dbms_json.format_flat, dbms_json.pretty)
< FROM INT$DBA_JSON_COLUMNS
< WHERE sys.dg$hasDGIndex(OWNER, TABLE_NAME, COLUMN_NAME) > 0
---
> SELECT obj.obj#  "OBJECT_ID",
>        obj.type# "OBJECT_TYPE#",
>        usr.name  "OWNER",
>        obj.name  "TABLE_NAME",
>        col.name  "COLUMN_NAME",
>        sys.dg$getDgQuoteName(usr.name, obj.name, col.name,
>            dbms_json.format_flat, dbms_json.pretty) "DATAGUIDE"
> FROM sys.cdef$ CDEF,
>      sys."_CURRENT_EDITION_OBJ" OBJ,
>      sys.col$ COL,
>      sys.ccol$ CCOL,
>      sys.user$ USR
> WHERE cdef.type# = 1
>   AND bitand(cdef.defer, 126976) > 0
>   AND cdef.obj# = obj.obj#
>   AND cdef.con# = ccol.con#
>   AND ccol.obj# = obj.obj#
>   AND col.col#  = ccol.col#
>   AND col.obj#  = obj.obj#
>   AND usr.user# = obj.owner#
>   AND col.type# IN (1,9,23,112,113,114) /* show only supported column types */
>   AND bitand(col.property, 32) = 0      /* not hidden column */
>   AND bitand(obj.flags, 128) = 0        /* not in recycle bin */
>   AND obj.type# = 2                     /* only tables */
>   AND sys.dg$hasDGIndex(obj.owner#, obj.obj#, col.name) > 0
> UNION ALL
> SELECT obj.obj#  "OBJECT_ID",
>        obj.type# "OBJECT_TYPE#",
>        usr.name  "OWNER",
>        obj.name  "TABLE_NAME",
>        col.name  "COLUMN_NAME",
>        sys.dg$getDgQuoteName(usr.name, obj.name, col.name,
>            dbms_json.format_flat, dbms_json.pretty)  "DATAGUIDE"
> FROM sys."_CURRENT_EDITION_OBJ" OBJ,
>      sys.col$ COL,
>      sys.user$ USR
> WHERE col.obj#  = obj.obj#
>   AND usr.user# = obj.owner#
>   AND col.type# = 119                   /* show only JSON type columns */
>   AND bitand(col.property, 32) = 0      /* not hidden column */
>   AND bitand(obj.flags, 128) = 0        /* not in recycle bin */
>   AND obj.type# = 2                     /* only tables */
>   AND sys.dg$hasDGIndex(obj.owner#, obj.obj#, col.name) > 0
SYS.INT$DBA_JSON_DG_COLS - VIEW (RU):
1,5c1,4
< SELECT OBJECT_ID, OBJECT_TYPE#, OWNER, TABLE_NAME, COLUMN_NAME,
<        JT.JPATH AS PATH, JT.JTYPE AS TYPE, JT.TLENGTH AS LENGTH
< FROM INT$DBA_JSON_COLUMNS,
<      TABLE(SYS.dg$getFlatDg(OWNER, TABLE_NAME, COLUMN_NAME)) JT
< WHERE SYS.dg$hasDGIndex(OWNER, TABLE_NAME, COLUMN_NAME) > 0
---
> SELECT dg.OBJECT_ID, dg.OBJECT_TYPE#, dg.OWNER, dg.TABLE_NAME, dg.COLUMN_NAME,
>        jt.JPATH AS PATH, jt.JTYPE AS TYPE, jt.TLENGTH AS LENGTH
> FROM INT$DBA_JSON_DATAGUIDES dg,
>      TABLE(SYS.dg$getFlatDg(dg.dataguide)) JT

Leave a Reply

Your email address will not be published.