Oracle DBMS_SQLTUNE_UTIL2
Version 21c

General Information
Library Note Morgan's Library Page Header
Which has the higher priority in your organization: Deploying a new database or securing the ones you already have? Looking for a website, and resources, dedicated solely to securing Oracle databases? Check out DBSecWorx.
Purpose This package is for shared utility functions that need to be part of an INVOKER rights package. Like the other dbms_sqltune_util# packages, it should NOT be documented. If a function only needs to be accessible from the dbms_sqltune/sqldiag/etc feature layer, do not put it here, but rather in the infrastructure layer (prvssqlf). This layer is for code that should be globally accessible, even from the internal package.
AUTHID CURRENT_USER
Constants
Name Data Type Value
General
DB_TYPE_ROOT VARCHAR2(4) 'ROOT'
DB_TYPE_PDB VARCHAR2(3) 'PDB'
DB_TYPE_IMP VARCHAR2(8) 'IMPORTED'
STR_NO VARCHAR2(3) 'no'
STR_YES VARCHAR2(3) 'yes'
Dependencies
ANYDATA DBMS_SPM PRVTEMX_ADMIN
AWR_PDB_DATABASE_INSTANCE DBMS_SPM_INTERNAL PRVTEMX_CELL
AWR_PDB_PDB_INSTANCE DBMS_SQLDIAG PRVTEMX_PERF
DATABASE_PROPERTIES DBMS_SQLPA PRVT_ADVISOR
DBMS_ADVISOR DBMS_SQLTUNE PRVT_AWRV_METADATA
DBMS_ASH_INTERNAL DBMS_SQLTUNE_INTERNAL PRVT_AWR_VIEWER
DBMS_ASSERT DBMS_SQLTUNE_LIB PRVT_SQLADV_INFRA
DBMS_AUTO_REPORT DBMS_SQLTUNE_UTIL1 SQLPROF_ATTR
DBMS_AUTO_REPORT_INTERNAL DBMS_STANDARD SQL_BIND
DBMS_PERF DBMS_SYS_ERROR SQL_BINDS
DBMS_REPORT DBMS_UTILITY SQL_BIND_SET
DBMS_SMB DBMS_XPLAN SYSTEM_PRIVILEGE_MAP
DBMS_SMB_INTERNAL PLITBLM WRI$_REPT_AWRV
Documented No
Exceptions
Error Code Reason
ORA-13768 Snapshot ID must be between <beginning snap_id> and <max_possible_valid_snap_id>;
First Available 10.1
Security Model Owned by SYS with EXECUTE granted to PUBLIC
Source {ORACLE_HOME}/rdbms/admin/dbmssqlu.sql
Subprograms
 
CHECK_PRIV
Does a callout into the kernel to check for the given system privilege. It returns TRUE or FALSE if the current user has the privilege enabled. dbms_sqltune_util2.check_priv(priv IN VARCHAR2) RETURN BOOLEAN;
conn / as sysdba
BEGIN
  IF dbms_sqltune_util2.check_priv('SYSDBA') THEN
    dbms_output.put_line('T');
  ELSE
    dbms_output.put_line('F');
  END IF;
END;
/
 
CHOOSEAWRFORPDB (new 21c)
Determines the location/prefix of the AWR view to use for the database dbms_sqltune_util2.chooseAWRforPDB(beginTime IN DATE) RETURN VARCHAR2;
SELECT dbms_sqltune_util2.chooseAWRforPDB(SYSDATE)
FROM dual;

DBMS_SQLTUNE_UTIL2.CHOOSEAWRFORPDB(SYSDATE)
-------------------------------------------
AWR_PDB


SELECT DECODE(owner#, 0, 'PUBLIC', 1, 'SYS', 'OTHER') AS OWNER,
       name AS OBJECT_NAME,
       DECODE(type#, 4, 'SYNONYM', 5, 'VIEW', 'OTHER') AS TYPE
FROM obj$
SAMPLE(5)
WHERE name LIKE 'AWR_PDB%'
ORDER BY 1,3,2;

OWNER   OBJECT_NAME                   TYPE
------- ----------------------------- -------
PUBLIC  AWR_PDB_ASH_SNAPSHOT          SYNONYM
PUBLIC  AWR_PDB_CELL_GLOBAL           SYNONYM
PUBLIC  AWR_PDB_CON_SYSMETRIC_HIST    SYNONYM
PUBLIC  AWR_PDB_CR_BLOCK_SERVER       SYNONYM
PUBLIC  AWR_PDB_DATAFILE              SYNONYM
PUBLIC  AWR_PDB_DISPATCHER            SYNONYM
PUBLIC  AWR_PDB_LOG                   SYNONYM
PUBLIC  AWR_PDB_PARAMETER             SYNONYM
PUBLIC  AWR_PDB_PERSISTENT_QMN_CACHE  SYNONYM
PUBLIC  AWR_PDB_RULE_SET              SYNONYM
PUBLIC  AWR_PDB_SQLSTAT               SYNONYM
PUBLIC  AWR_PDB_THREAD                SYNONYM
SYS     AWR_PDB_CELL_CONFIG_DETAIL    VIEW
SYS     AWR_PDB_IC_CLIENT_STATS       VIEW
SYS     AWR_PDB_LATCH_CHILDREN        VIEW
SYS     AWR_PDB_LMS_STATS             VIEW
SYS     AWR_PDB_MVPARAMETER           VIEW
SYS     AWR_PDB_PERSISTENT_QUEUES     VIEW
SYS     AWR_PDB_RSRC_METRIC           VIEW
SYS     AWR_PDB_SYSSTAT               VIEW
SYS     AWR_PDB_TOPLEVELCALL_NAME     VIEW
 
GET_CLOUD_SERVICE_TYPE (new 21c)
Returns _cloud_service_type parameter for cloud service type

Interestingly, NONE was returned from 21.1 running in the OCI cloud
dbms_sqltune_util2.get_cloud_service_type RETURN VARCHAR2;

Valid return values
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';
SELECT dbms_sqltune_util2.get_cloud_service_type
FROM dual;

GET_CLOUD_SERVICE_TYPE
----------------------
NONE
 
GET_SQLSET_USERBINDS
Used by dbms_sqltune.unpack_sqlsets_bulk: Gets the list of binds of a given SQL statement from a table and converts the list of binds into a varray as required by sqlset_row. dbms_sqltune_util2.get_sqlset_userbinds(
get_sqlset_userbinds(
sql_id          IN VARCHAR2,
plan_hash_value IN NUMBER,
sqlset_name     IN VARCHAR2,
sqlset_owner    IN VARCHAR2,
table_name      IN VARCHAR2)
RETURN sys.sql_binds;
TBD
 
GET_TIMING_INFO
Returns elapsed and CPU timing information for a section of PL/SQL code dbms_sqltune_util2.get_timing_info(
phase   IN     BINARY_INTEGER,
elapsed IN OUT NUMBER,
cpu     IN OUT NUMBER);
TBD
 
GET_TZ_OFFSET (new 21c)
Returns the timezone offset from systimestamp dbms_sqltune_util2.get_tz_offset RETURN VARCHAR2;
SELECT dbms_sqltune_util2.get_tz_offset
FROM dual;

GET_TZ_OFFSET
-------------
0:0
 
IS_IMPORTED_CDB
Checks whether the dbid is imported CDB or not dbms_sqltune_util2.is_imported_cdb(p_dbid IN NUMBER) RETURN VARCHAR22;
SELECT dbid
FROM v$database;

      DBID
----------
 549318987


SELECT dbms_sqltune_util2.is_imported_cdb(549318987)
FROM dual;

DBMS_SQLTUNE_UTIL2.IS_IMPORTED_CDB(549318987)
---------------------------------------------
no
 
IS_IMPORTED_PDB
hecks whether the dbid is imported PDB or not dbms_sqltune_util2.is_imported_pdb(p_dbid IN NUMBER) RETURN VARCHAR22;
SELECT dbid, name
FROM v$containers
ORDER BY 2;

DBID       NAME
---------- ----------
549318987  CDB$ROOT
700560205  PDB$SEED
542716466  PDBDEV
2341452460 PDBTEST


SELECT dbms_sqltune_util2.is_imported_pdb(700560205)
FROM dual;

DBMS_SQLTUNE_UTIL2.IS_IMPORTED_CDB(700560205)
---------------------------------------------
no
 
IS_PDB (new 21c)
Returns TRUE if the current database is a PDB

Returns FALSE in CDB$ROOT
dbms_sqltune_util2.is_pdb RETURN BOOLEAN;
BEGIN
  IF dbms_sqltune_util2.is_pdb THEN
    dbms_output.put_line('T');
  ELSE
    dbms_output.put_line('F');
  END IF;
END;
/
F

PL/SQL procedure successfully completed.
 
IS_RAS_USER
Returns TRUE or FALSE based if the current user is a Real Application Security User (RAS) user. This function is used by create_tuning_task, schedule_tuning_task and create_analysis_task. dbms_sqltune_util2.is_ras_user RETURN BOOLEAN;
BEGIN
  IF dbms_sqltune_util2.is_ras_user THEN
    dbms_output.put_line('Using Real Application Security');
  ELSE
    dbms_output.put_line('Not Using Real Application Security');
  END IF;
END;
/
 
IS_SYSTEM_DATA_LOCKED (new 21c)
Returns YES if a LOCKDOWN PROFILE is enabled, else NO dbms_sqltune_util2.is_system_data_locked RETURN VARCHAR2;
SELECT dbms_sqltune_util2.is_system_data_locked
FROM dual;

IS_SYSTEM_DATA_LOCKED
----------------------
NO
 
RESOLVE_DATABASE_TYPE
Resolves the type of database that corresponds to the dbid given as parameter. It is used by get_awr_view_location function to determine the location of AWR views. dbms_sqltune_util2.resolve_database_type(dbid IN NUMBER) RETURN VARCHAR2;
SELECT dbid
FROM v$database;

      DBID
----------
 549318987


SELECT dbms_sqltune_util2.resolve_database_type(549318987)
FROM dual;

DBMS_SQLTUNE_UTIL2.RESOLVE_DATABASE_TYPE(549318987)
----------------------------------------------------
ROOT
 
RESOLVE_USERNAME
When passed a NULL name, this function returns the current schema owner. Otherwise, it returns the name passed in, after validating it. dbms_sqltune_util2.resolve_username(
user_name IN VARCHAR2,
validate  IN BOOLEAN := TRUE,
con_id    IN NUMBER  := NULL)
RETURN VARCHAR2;
conn uwclass/uwclass@pdbdev

DECLARE
 retVal VARCHAR2(30);
BEGIN
  retVal := dbms_sqltune_util2.resolve_username(USER);
  dbms_output.put_line(retVal);
END;
/
 
SQL_BINDS_NTAB_TO_VARRAY
Converts the sql binds data from the nested table stored in the staging table on an unpack/pack to the varray type used in the SQLSET_ROW dbms_sqltune_util2.sql_binds_ntab_to_varray(binds_ntab IN sys.sql_bind_set)
RETURN sys.sql_binds;
TBD
 
SQL_BINDS_VARRAY_TO_NTAB
Converts the sql binds data from a VARRAY as it exists in SQLSET_ROW into a nested table that can be stored in the staging table dbms_sqltune_util2.sql_binds_varray_to_ntab(binds_varray IN sys.sql_binds)
RETURN sys.sql_bind_set;
TBD
 
VALIDATE_SNAPSHOT
Checks whether a snapshot id interval is valid. It raises an error if passed an invalid interval. dbms_sqltune_util2.validate_snapshot(
begin_snap IN NUMBER,
end_snap   IN NUMBER,
incl_bid   IN BOOLEAN := FALSE);
SELECT TO_CHAR(s.startup_time,' DD MON "at" HH24:MI:SS') INSTART_FMT,
di.instance_name INST_NAME, di.db_name DB_NAME, s.snap_id SNAP_ID,
TO_CHAR(s.end_interval_time,'DD MON YYYY HH24:MI') SNAPDAT, s.snap_level LVL
FROM dba_hist_snapshot s, dba_hist_database_instance di
WHERE di.dbid = s.dbid
AND di.instance_number = s.instance_number
AND di.startup_time = s.startup_time
ORDER BY snap_id;

exec dbms_sqltune_util2.validate_snapshot(2376, 2391);

SELECT max(snap_id)+100
FROM dba_hist_snapshot;

exec dbms_sqltune_util2.validate_snapshot(2376, 9999);
 
VARR_TO_HINTS_XML
Converts sqlprof_attr object type to XML format dbms_sqltune_util2.varr_to_hints_xml(varr IN sqlprof_attr) RETURN CLOB;
TBD

Related Topics
Built-in Functions
Built-in Packages
DBMS_AUTO_SQLTUNE
DBMS_SQLDIAG
DBMS_SQLPA
DBMS_SQLSET
DBMS_SQLTUNE
DBMS_SQLTUNE_UTIL0
DBMS_SQLTUNE_UTIL1
PRVTEMX_PERF
What's New In 19c
What's New In 20c-21c

Morgan's Library Page Footer
This site is maintained by Dan Morgan. Last Updated: This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2019 Daniel A. Morgan All Rights Reserved
  DBSecWorx