All Products
Search
Document Center

PolarDB:DBMS_UTILITY

Last Updated:Mar 28, 2026

The DBMS_UTILITY package provides utility subprograms for gathering database statistics, managing names, inspecting call stacks, and retrieving system information. PolarDB for PostgreSQL (Compatible with Oracle) supports a subset of the functions and stored procedures available in Oracle's DBMS_UTILITY package.

Supported subprograms

Function or stored procedureTypeReturn typeDescription
ANALYZE_DATABASE(method [, estimate_rows [, estimate_percent [, method_opt ]]])Stored procedureN/AAnalyzes all tables in all schemas within the current database.
ANALYZE_PART_OBJECT(schema, object_name [, object_type [, command_type [, command_opt [, sample_clause ]]]])Stored procedureN/AAnalyzes a single partitioned table.
ANALYZE_SCHEMA(schema, method [, estimate_rows [, estimate_percent [, method_opt ]]])Stored procedureN/AAnalyzes all tables in a specified schema.
CANONICALIZE(name, canon_name OUT, canon_len)Stored procedureN/ACanonicalizes a string by normalizing its case and stripping extra characters.
COMMA_TO_TABLE(list, tablen OUT, tab OUT)Stored procedureN/AConverts a comma-delimited list of names into a table of names.
DB_VERSION(version OUT, compatibility OUT)Stored procedureN/AReturns the database version.
EXEC_DDL_STATEMENT(parse_string)Stored procedureN/ARuns a DDL statement.
FORMAT_CALL_STACKFunctionTEXTReturns the current call stack in a readable format.
FORMAT_ERROR_STACKFunctionTEXTReturns the call stack at the point where an error was raised.
FORMAT_ERROR_BACKTRACEFunctionTEXTReturns the call stack at the point where an error was raised.
GET_CPU_TIMEFunctionNUMBERReturns the current CPU time in hundredths of a second.
GET_DEPENDENCY(type, schema, name)Stored procedureN/ALists objects that depend on a specified object.
GET_HASH_VALUE(name, base, hash_size)FunctionNUMBERComputes a hash value for a string.
GET_PARAMETER_VALUE(parnam, intval OUT, strval OUT)Stored procedureBINARY_INTEGERReturns the value of a database initialization parameter.
GET_TIMEFunctionNUMBERReturns the current time in hundredths of a second.
NAME_TOKENIZE(name, a OUT, b OUT, c OUT, dblink OUT, nextpos OUT)Stored procedureN/AParses a dotted name into its component parts.
TABLE_TO_COMMA(tab, tablen OUT, list OUT)Stored procedureN/AConverts a table of names into a comma-delimited list.
PolarDB for PostgreSQL (Compatible with Oracle) supports only the subprograms listed above. Oracle's full DBMS_UTILITY package contains additional subprograms not available in this cluster.

Public variables

VariableData typeValueDescription
inv_error_on_restrictionsPLS_INTEGER1Used by the INVALIDATE stored procedure.
lname_arrayTABLEStores lists of long names.
uncl_arrayTABLEStores lists of users and names.

LNAME_ARRAY

LNAME_ARRAY stores lists of long names, including fully qualified names.

TYPE lname_array IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;

UNCL_ARRAY

UNCL_ARRAY stores lists of users and names.

TYPE uncl_array IS TABLE OF VARCHAR2(227) INDEX BY BINARY_INTEGER;

ANALYZE_DATABASE, ANALYZE_SCHEMA, and ANALYZE_PART_OBJECT

These three stored procedures gather distribution statistics on database tables. When executed, Postgres samples the data in a table and records the results in the pg_statistics system table.

The three procedures differ in scope:

  • ANALYZE_DATABASE analyzes all tables in all schemas within the current database.

  • ANALYZE_SCHEMA analyzes all tables in a specified schema.

  • ANALYZE_PART_OBJECT analyzes a single table.

Syntax

ANALYZE_DATABASE(method VARCHAR2 [, estimate_rows NUMBER
  [, estimate_percent NUMBER [, method_opt VARCHAR2 ]]])

ANALYZE_SCHEMA(schema VARCHAR2, method VARCHAR2
  [, estimate_rows NUMBER [, estimate_percent NUMBER
  [, method_opt VARCHAR2 ]]])

ANALYZE_PART_OBJECT(schema VARCHAR2, object_name VARCHAR2
  [, object_type CHAR [, command_type CHAR
  [, command_opt VARCHAR2 [, sample_clause ]]]])

Parameters — ANALYZE_DATABASE and ANALYZE_SCHEMA

ParameterDescription
methodControls whether statistics are gathered or removed. COMPUTE and ESTIMATE are identical: both run the Postgres ANALYZE statement. DELETE removes the relevant rows from pg_statistics.
estimate_rowsThe number of rows on which estimated statistics are based. Required if you specify ESTIMATE, but ignored in practice; included for compatibility.
estimate_percentThe percentage of rows on which estimated statistics are based. Required if you specify ESTIMATE, but ignored in practice; included for compatibility.
method_optThe object types to analyze. Accepted combinations: FOR TABLE, FOR ALL [INDEXED] COLUMNS [SIZE n], FOR ALL INDEXES. Ignored in practice; included for compatibility.

Parameters — ANALYZE_PART_OBJECT

ParameterDescription
schemaThe schema that contains the object to analyze.
object_nameThe name of the partitioned object to analyze.
object_typeThe object type: T for table, I for index. Ignored in practice; included for compatibility.
command_typeThe analysis function to run: E (estimated statistics), C (exact statistics), V (validates partition structure and integrity). Ignored in practice; included for compatibility.
command_optWhen command_type is C or E, accepted combinations are: FOR TABLE, FOR ALL COLUMNS, FOR ALL LOCAL INDEXES. When command_type is V and object_type is T, CASCADE is accepted. Ignored in practice; included for compatibility.
sample_clauseWhen command_type is E, specifies the sample size: SAMPLE n { ROWS | PERCENT }. Ignored in practice; included for compatibility.

CANONICALIZE

CANONICALIZE normalizes a name string according to the following rules:

  • If the string is not enclosed in double quotation marks, its characters must form a valid identifier; if not, an exception is raised.

  • If the string is not enclosed in double quotation marks and contains no periods, all alphabetic characters are capitalized and leading/trailing spaces are removed.

  • If the string is enclosed in double quotation marks and contains no periods, the double quotation marks are stripped.

  • If the string contains periods and no portion is double-quoted, each segment is capitalized and enclosed in double quotation marks.

  • If the string contains periods and some segments are double-quoted, double-quoted segments are returned unchanged (including the quotation marks), and unquoted segments are capitalized and enclosed in double quotation marks.

Syntax

CANONICALIZE(name VARCHAR2, canon_name OUT VARCHAR2,
  canon_len BINARY_INTEGER)

Parameters

ParameterDescription
nameThe input string to canonicalize.
canon_nameThe canonicalized output string.
canon_lenThe number of bytes to process, starting from the first character.

Examples

All examples use this wrapper procedure:

CREATE OR REPLACE PROCEDURE canonicalize (
    p_name      VARCHAR2,
    p_length    BINARY_INTEGER DEFAULT 30
)
IS
    v_canon     VARCHAR2(100);
BEGIN
    DBMS_UTILITY.CANONICALIZE(p_name, v_canon, p_length);
    DBMS_OUTPUT.PUT_LINE('Canonicalized name ==>' || v_canon || '<==');
    DBMS_OUTPUT.PUT_LINE('Length: ' || LENGTH(v_canon));
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
        DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END;

Quoted identifier with special characters — quotes stripped:

EXEC canonicalize('"_+142%"');
Canonicalized name ==>_+142%<==
Length: 6

COMMA_TO_TABLE

COMMA_TO_TABLE converts a comma-delimited list of names into a table of names. Each entry in the list becomes a table entry. Names must be formatted as valid identifiers.

Syntax

COMMA_TO_TABLE(list VARCHAR2, tablen OUT BINARY_INTEGER,
  tab OUT { LNAME_ARRAY | UNCL_ARRAY })

Parameters

ParameterDescription
listThe comma-delimited input list of names.
tablenThe number of entries in the list.
tabThe output table that receives the names. Use LNAME_ARRAY for long names or UNCL_ARRAY for user and name pairs.

Example

CREATE OR REPLACE PROCEDURE comma_to_table (
    p_list      VARCHAR2
)
IS
    r_lname     DBMS_UTILITY.LNAME_ARRAY;
    v_length    BINARY_INTEGER;
BEGIN
    DBMS_UTILITY.COMMA_TO_TABLE(p_list, v_length, r_lname);
    FOR i IN 1..v_length LOOP
        DBMS_OUTPUT.PUT_LINE(r_lname(i));
    END LOOP;
END;
EXEC comma_to_table('polardb.dept, polardb.emp, polardb.jobhist');
polardb.dept
 polardb.emp
 polardb.jobhist

DB_VERSION

DB_VERSION returns the engine version and compatibility string for the current database instance.

Syntax

DB_VERSION(version OUT VARCHAR2, compatibility OUT VARCHAR2)

Parameters

ParameterDescription
versionThe engine version of the instance.
compatibilityThe compatibility string. Its meaning is defined by the implementation.

Example

DECLARE
    v_version       VARCHAR2(150);
    v_compat        VARCHAR2(150);
BEGIN
    DBMS_UTILITY.DB_VERSION(v_version, v_compat);
    DBMS_OUTPUT.PUT_LINE('Version: '       || v_version);
    DBMS_OUTPUT.PUT_LINE('Compatibility: ' || v_compat);
END;
Version: PostgreSQL 11.15 (POLARDB Database Compatible with Oracle 11.15.25)
Compatibility: PostgreSQL 11.15 (POLARDB Database Compatible with Oracle 11.15.25)

EXEC_DDL_STATEMENT

EXEC_DDL_STATEMENT runs a DDL statement passed as a string.

Syntax

EXEC_DDL_STATEMENT(parse_string VARCHAR2)

Parameters

ParameterDescription
parse_stringThe DDL statement to run.

Example

BEGIN
    DBMS_UTILITY.EXEC_DDL_STATEMENT(
        'CREATE TABLE job (' ||
          'jobno NUMBER(3),' ||
          'jname VARCHAR2(9))'
    );
END;
If parse_string is not a valid DDL statement, PolarDB for PostgreSQL (Compatible with Oracle) raises an error: Oracle databases accept an invalid parse_string without raising an error.
EXEC dbms_utility.exec_ddl_statement('select rownum from dual');
ERROR:  'parse_string' must be a valid DDL statement

FORMAT_CALL_STACK

FORMAT_CALL_STACK returns the current call stack as a formatted text string. Call it from within a stored procedure, function, or package to inspect the active call chain at any point during execution.

Syntax

DBMS_UTILITY.FORMAT_CALL_STACK RETURN TEXT

FORMAT_ERROR_BACKTRACE

FORMAT_ERROR_BACKTRACE returns the call stack at the point where an error was raised, as a formatted text string. Call it from within an exception handler to trace the origin of an error through nested subprogram calls.

Syntax

DBMS_UTILITY.FORMAT_ERROR_BACKTRACE RETURN TEXT

FORMAT_ERROR_STACK

FORMAT_ERROR_STACK returns the call stack at the point where an error was raised, as a formatted text string.

Syntax

DBMS_UTILITY.FORMAT_ERROR_STACK RETURN TEXT
PolarDB for PostgreSQL (Compatible with Oracle) implements FORMAT_ERROR_STACK differently from Oracle. In Oracle, FORMAT_ERROR_STACK returns strings containing SQLCODE and SQLERRM information. In PolarDB for PostgreSQL (Compatible with Oracle), FORMAT_ERROR_STACK behaves the same as FORMAT_ERROR_BACKTRACE.

GET_CPU_TIME

GET_CPU_TIME returns the current CPU time in hundredths of a second, measured from an arbitrary reference point. Use the difference between two calls to measure CPU consumption for a specific operation.

Syntax

DBMS_UTILITY.GET_CPU_TIME RETURN NUMBER

Parameters

ParameterDescription
cputimeThe number of hundredths of a second of CPU time elapsed.

Example

SELECT DBMS_UTILITY.GET_CPU_TIME FROM DUAL;
get_cpu_time
--------------
          603

The value 603 means 6.03 hundredths of a second, or 0.0603 seconds of CPU time.

GET_DEPENDENCY

GET_DEPENDENCY lists all objects that depend on a specified object and outputs the results using DBMS_OUTPUT.

Usage notes

  • GET_DEPENDENCY does not show dependencies for functions or stored procedures.

Syntax

GET_DEPENDENCY(type VARCHAR2, schema VARCHAR2, name VARCHAR2)

Parameters

ParameterDescription
typeThe type of the object. Valid values: INDEX, PACKAGE, PACKAGE BODY, SEQUENCE, TABLE, TRIGGER, TYPE, VIEW.
schemaThe schema that contains the object.
nameThe name of the object for which to retrieve dependencies.

Example

BEGIN
    DBMS_UTILITY.GET_DEPENDENCY('TABLE', 'public', 'EMP');
END;
DEPENDENCIES ON public.EMP
------------------------------------------------------------------
*TABLE public.EMP()
*   CONSTRAINT c public.emp()
*   CONSTRAINT f public.emp()
*   CONSTRAINT p public.emp()
*   TYPE public.emp()
*   CONSTRAINT c public.emp()
*   CONSTRAINT f public.jobhist()
*   VIEW .empname_view()

GET_HASH_VALUE

GET_HASH_VALUE computes a hash value for a string within a specified range.

Syntax

hash NUMBER GET_HASH_VALUE(name VARCHAR2, base NUMBER, hash_size NUMBER)

Parameters

ParameterDescription
nameThe input string to hash.
baseThe starting value of the hash range.
hash_sizeThe number of distinct hash values in the range.
hashThe computed hash value.

Example

The following example builds a hash table from the ename column of the emp table, generating up to 1,024 hash values starting from 100.

DECLARE
    v_hash          NUMBER;
    TYPE hash_tab IS TABLE OF NUMBER INDEX BY VARCHAR2(10);
    r_hash          HASH_TAB;
    CURSOR emp_cur IS SELECT ename FROM emp;
BEGIN
    FOR r_emp IN emp_cur LOOP
        r_hash(r_emp.ename) :=
            DBMS_UTILITY.GET_HASH_VALUE(r_emp.ename, 100, 1024);
    END LOOP;
    FOR r_emp IN emp_cur LOOP
        DBMS_OUTPUT.PUT_LINE(RPAD(r_emp.ename, 10) || ' ' ||
            r_hash(r_emp.ename));
    END LOOP;
END;
SMITH      377
ALLEN      740
WARD       718
JONES      131
MARTIN     176
BLAKE      568
CLARK      621
SCOTT      1097
KING       235
TURNER     850
ADAMS      156
JAMES      942
FORD       775
MILLER     148

GET_PARAMETER_VALUE

GET_PARAMETER_VALUE returns the current value of a database initialization parameter. Parameters are listed in the pg_settings system view.

Syntax

status BINARY_INTEGER GET_PARAMETER_VALUE(parnam VARCHAR2,
  intval OUT INTEGER, strval OUT VARCHAR2)

Parameters

ParameterDescription
parnamThe name of the initialization parameter. Parameters are listed in the pg_settings system view.
intvalFor integer parameters, the parameter value. For string parameters, the length of strval.
strvalThe value of string parameters.
statusReturns 0 if the parameter value is INTEGER or BOOLEAN. Returns 1 if the parameter value is a string.

Example

DECLARE
    v_intval        INTEGER;
    v_strval        VARCHAR2(80);
BEGIN
    DBMS_UTILITY.GET_PARAMETER_VALUE('client_encoding', v_intval, v_strval);
    DBMS_OUTPUT.PUT_LINE('client_encoding' || ': ' || v_strval);
END;
client_encoding: UTF8

GET_TIME

GET_TIME returns the current time in hundredths of a second. The absolute value is not meaningful on its own — use the difference between two calls to measure elapsed time.

Syntax

DBMS_UTILITY.GET_TIME RETURN NUMBER

Parameters

ParameterDescription
timeThe number of hundredths of a second elapsed since the program started.

Example

SELECT DBMS_UTILITY.GET_TIME FROM DUAL;
 get_time
----------
  1555860

NAME_TOKENIZE

NAME_TOKENIZE parses a dotted name into its component parts. Unquoted components are capitalized; double quotation marks are stripped from quoted components.

Syntax

NAME_TOKENIZE(name VARCHAR2, a OUT VARCHAR2, b OUT VARCHAR2,
  c OUT VARCHAR2, dblink OUT VARCHAR2, nextpos OUT BINARY_INTEGER)

Parameters

ParameterDescription
nameThe input string, in the format a[.b[.c]][@dblink].
aThe leftmost component.
bThe second component, if present.
cThe third component, if present.
dblinkThe database link name, if present.
nextposThe position of the last character parsed in the input string.

Examples

All examples use this wrapper procedure:

CREATE OR REPLACE PROCEDURE name_tokenize (
    p_name          VARCHAR2
)
IS
    v_a             VARCHAR2(30);
    v_b             VARCHAR2(30);
    v_c             VARCHAR2(30);
    v_dblink        VARCHAR2(30);
    v_nextpos       BINARY_INTEGER;
BEGIN
    DBMS_UTILITY.NAME_TOKENIZE(p_name, v_a, v_b, v_c, v_dblink, v_nextpos);
    DBMS_OUTPUT.PUT_LINE('name   : ' || p_name);
    DBMS_OUTPUT.PUT_LINE('a      : ' || v_a);
    DBMS_OUTPUT.PUT_LINE('b      : ' || v_b);
    DBMS_OUTPUT.PUT_LINE('c      : ' || v_c);
    DBMS_OUTPUT.PUT_LINE('dblink : ' || v_dblink);
    DBMS_OUTPUT.PUT_LINE('nextpos: ' || v_nextpos);
END;

Single unquoted name — capitalized:

BEGIN
    name_tokenize('emp');
END;
name   : emp
a      : EMP
b      :
c      :
dblink :
nextpos: 3

Two-part name — both components capitalized:

BEGIN
    name_tokenize('polardb.list_emp');
END;
name   : polardb.list_emp
a      : polardb
b      : LIST_EMP
c      :
dblink :
nextpos: 16

Three-part name with mixed quoting — quoted parts preserved, unquoted part capitalized:

BEGIN
    name_tokenize('"polardb"."Emp_Admin".update_emp_sal');
END;
name   : "polardb"."Emp_Admin".update_emp_sal
a      : polardb
b      : Emp_Admin
c      : UPDATE_EMP_SAL
dblink :
nextpos: 36

Name with database link:

BEGIN
    name_tokenize('polardb.emp@polardb_dblink');
END;
name   : polardb.emp@polardb_dblink
a      : polardb
b      : EMP
c      :
dblink : polardb_DBLINK
nextpos: 26

TABLE_TO_COMMA

TABLE_TO_COMMA converts a table of names into a comma-delimited list. Each table entry becomes a list entry. Names must be formatted as valid identifiers.

Syntax

TABLE_TO_COMMA(tab { LNAME_ARRAY | UNCL_ARRAY },
  tablen OUT BINARY_INTEGER, list OUT VARCHAR2)

Parameters

ParameterDescription
tabThe input table of names. Use LNAME_ARRAY for long names or UNCL_ARRAY for user and name pairs.
tablenThe number of entries in the output list.
listThe comma-delimited output list of names.

Example

The following example converts a comma-separated list into a table using COMMA_TO_TABLE, then converts it back to a comma-separated list using TABLE_TO_COMMA.

CREATE OR REPLACE PROCEDURE table_to_comma (
    p_list      VARCHAR2
)
IS
    r_lname     DBMS_UTILITY.LNAME_ARRAY;
    v_length    BINARY_INTEGER;
    v_listlen   BINARY_INTEGER;
    v_list      VARCHAR2(80);
BEGIN
    DBMS_UTILITY.COMMA_TO_TABLE(p_list, v_length, r_lname);
    DBMS_OUTPUT.PUT_LINE('Table Entries');
    DBMS_OUTPUT.PUT_LINE('-------------');
    FOR i IN 1..v_length LOOP
        DBMS_OUTPUT.PUT_LINE(r_lname(i));
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('-------------');
    DBMS_UTILITY.TABLE_TO_COMMA(r_lname, v_listlen, v_list);
    DBMS_OUTPUT.PUT_LINE('Comma-Delimited List: ' || v_list);
END;
EXEC table_to_comma('polardb.dept, polardb.emp, polardb.jobhist');
Table Entries
-------------
polardb.dept
 polardb.emp
 polardb.jobhist
-------------
Comma-Delimited List: polardb.dept, polardb.emp, polardb.jobhist