PL/SQL Packages and Types Reference 10g Release 1 (10.1) Part Number B10802-01 |
|
|
View PDF |
The DBMS_UTILITY package provides various utility subprograms.
This chapter contains the following topics:
DBMS_UTILITY
runs with the privileges of the calling user for the NAME_RESOLVE Procedure, the COMPILE_SCHEMA Procedure, and the ANALYZE_SCHEMA Procedure. This is necessary so that the SQL works correctly.
The package does not run as SYS
. The privileges are checked using DBMS_DDL
.
TYPE dblink_array IS TABLE OF VARCHAR2(128) INDEX BY BINARY_INTEGER;
Lists of database links should be stored here.
TYPE index_table_type IS TABLE OF BINARY_INTEGER INDEX BY BINARY_INTEGER;
The order in which objects should be generated is returned here.
TYPE instance_record IS RECORD ( inst_number NUMBER, inst_name VARCHAR2(60)); TYPE instance_table IS TABLE OF instance_record INDEX BY BINARY_INTEGER;
The list of active instance number and instance name.
The starting index of instance_table
is 1; instance_table
is dense.
TYPE lname_array IS TABLE OF VARCHAR2(4000) index by BINARY_INTEGER;
Lists of Long NAME
should be stored here, it includes fully qualified attribute names.
TYPE name_array IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
Lists of NAME
should be stored here.
TYPE number_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
The order in which objects should be generated is returned here for users.
TYPE uncl_array IS TABLE OF VARCHAR2(227) INDEX BY BINARY_INTEGER;
Lists of "USER
"."NAME
"."COLUMN
"@LINK
should be stored here.
Obsolete with Oracle Database Release 10g:
Subprogram | Description |
---|---|
Analyzes all the tables, clusters, and indexes in a database [see also Deprecated Subprograms] | |
Returns the active instance | |
Analyzes the given tables and indexes | |
Analyzes all the tables, clusters, and indexes in a schema [see also Deprecated Subprograms] | |
Canonicalizes a given string | |
Converts a comma-delimited list of names into a PL/SQL table of names | |
Compiles all procedures, functions, packages, and triggers in the specified schema | |
Creates an error table to be used in the | |
Returns the current connected instance number | |
Gets the block number part of a data block address | |
Gets the file number part of a data block address | |
Returns version information for the database | |
Executes the DDL statement in | |
Formats the backtrace from the point of the current error to the exception handler where the error has been caught | |
Formats the current error stack | |
Formats the current call stack | |
Returns the current CPU time in 100th's of a second | |
Shows the dependencies on the object passed in. | |
Computes a hash value for the given string | |
Gets the value of specified init.ora parameter | |
Finds out the current time in 100th's of a second | |
Finds out if this database is running in cluster database mode | |
Creates a data block address given a file number and a block number | |
Resolves the given name | |
Calls the parser to parse the given name | |
Returns a string that uniquely identifies the version of Oracle and the operating system | |
Converts a PL/SQL table of names into a comma-delimited list of names | |
Converts a PL/SQL table of names into a comma-delimited list of names |
Note: This subprogam is obsolete with release Oracle Database Release 10g. It is retained in documentation for reasons of backward compatibility. For current functionality, see "DBMS_STATS". |
This procedure runs the ANALYZE
command on all the tables, clusters, and indexes in a database. Use this procedure to collect nonoptimizer statistics. For optimizer statistics, use the DBMS_STATS.GATHER_DATABASE_STATS
procedure.
DBMS_UTILITY.ANALYZE_DATABASE ( method VARCHAR2, estimate_rows NUMBER DEFAULT NULL, estimate_percent NUMBER DEFAULT NULL, method_opt VARCHAR2 DEFAULT NULL);
Exception | Description |
---|---|
|
Insufficient privileges for some object in this database. |
Use this procedure to collect nonoptimizer statistics. For optimizer statistics, use the DBMS_STATS
.GATHER_TABLE_STATS
or DBMS_STATS
.GATHER_INDEX_STATS
procedure.
This procedure returns the active instance.
DBMS_UTILITY.ACTIVE_INSTANCES ( instance_table OUT INSTANCE_TABLE, instance_count OUT NUMBER);
Procedure | Description |
---|---|
|
Contains a list of the active instance numbers and names. When no instance is up, the list is empty. |
|
Number of active instances. |
This procedure is equivalent to SQL:
"ANALYZE TABLE|INDEX [<schema>.]<object_name> PARTITION <pname> [<command_type>] [<command_opt>] [<sample_clause>]
DBMS_UTILITY.ANALYZE_PART_OBJECT ( schema IN VARCHAR2 DEFAULT NULL, object_name IN VARCHAR2 DEFAULT NULL, object_type IN CHAR DEFAULT 'T', command_type IN CHAR DEFAULT 'E', command_opt IN VARCHAR2 DEFAULT NULL, sample_clause IN VARCHAR2 DEFAULT 'sample 5 percent ');
For each partition of the object, run in parallel using job queues.
Note: This subprogam is obsolete with Oracle Database Release 10g. It is retained in documentation for reasons of backward compatibility. For current functionality, see "DBMS_STATS". |
This procedure runs the ANALYZE
command on all the tables, clusters, and indexes in a schema. Use this procedure to collect nonoptimizer statistics. For optimizer statistics, use the DBMS_STATS.GATHER_SCHEMA_STATS
procedure.
DBMS_UTILITY.ANALYZE_SCHEMA ( schema VARCHAR2, method VARCHAR2, estimate_rows NUMBER DEFAULT NULL, estimate_percent NUMBER DEFAULT NULL, method_opt VARCHAR2 DEFAULT NULL);
Exception | Description |
---|---|
|
Insufficient privileges for some object in this schema. |
This procedure canonicalizes the given string. The procedure handles a single reserved or key word (such as 'table'), and strips off white spaces for a single identifier so that ' table ' becomes TABLE.
DBMS_UTILITY.CANONICALIZE( name IN VARCHAR2, canon_name OUT VARCHAR2, canon_len IN BINARY_INTEGER);
Parameter | Description |
---|---|
|
The string to be canonicalized. |
|
The canonicalized string |
|
The length of the string (in bytes) to canonicalize. |
Returns the first canon_len
bytes in canon_name
name
is NULL, canon_name
becomes NULL.name
is not a dotted name, and if name
begins and ends with a double quote, remove both quotes. Alternatively, convert to upper case with NLS_UPPER. Note that this case does not include a name with special characters, such as a space, but is not doubly quoted.These procedures converts a comma-delimited list of names into a PL/SQL table of names. The second version supports fully-qualified attribute names.
DBMS_UTILITY.COMMA_TO_TABLE ( list IN VARCHAR2, tablen OUT BINARY_INTEGER, tab OUT uncl_array); DBMS_UTILITY.COMMA_TO_TABLE ( list IN VARCHAR2, tablen OUT BINARY_INTEGER, tab OUT lname_array);
Parameter | Description |
---|---|
|
Comma separated list of tables. |
|
Number of tables in the PL/SQL table. |
|
PL/SQL table which contains list of table names. |
A PL/SQL table is returned, with values 1..n
and n+1
is
null
.
The list
must be a non-empty comma-delimited list: Anything other than a comma-delimited list is rejected. Commas inside double quotes do not count.
Entries in the comma-delimited list cannot include multibyte characters such as hyphens (-).
The values in tab
are cut from the original list, with no transformations.
This procedure compiles all procedures, functions, packages, and triggers in the specified schema. After calling this procedure, you should select from view ALL_OBJECTS
for items with status of INVALID
to see if all objects were successfully compiled.
To see the errors associated with INVALID
objects, you may use the Enterprise Manager command:
SHOW ERRORS <type> <schema>.<name>
DBMS_UTILITY.COMPILE_SCHEMA ( schema VARCHAR2, compile_all BOOLEAN DEFAULT TRUE);
Parameter | Description |
---|---|
|
Name of the schema. |
Exception | Description |
---|---|
|
Insufficient privileges for some object in this schema. |
This procedure creates an error table to be used in the EXCEPTION
clause of the ALTER
TYPE
statement.
DBMS_UTILITY.CREATE_ALTER_TYPE_ERROR_TABLE( schema_name IN VARCHAR2, table_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The name of the schema. |
|
The name of the table created. |
An error is returned if the table already exists.
This function returns the current connected instance number. It returns NULL
when connected instance is down.
DBMS_UTILITY.CURRENT_INSTANCE RETURN NUMBER;
This function gets the block number part of a data block address.
DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK ( dba NUMBER) RETURN NUMBER;
Parameter | Description |
---|---|
|
Data block address. |
pragma restrict_references(data_block_address_block, WNDS, RNDS, WNPS, RNPS);
Returns | Description |
---|---|
|
Block offset of the block. |
This function should not be used with datablocks which belong to bigfile tablespaces.
This function gets the file number part of a data block address.
DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE ( dba NUMBER) RETURN NUMBER;
Parameter | Description |
---|---|
|
Data block address. |
pragma restrict_references (data_block_address_file, WNDS, RNDS, WNPS, RNPS);
Returns | Description |
---|---|
|
File that contains the block. |
This function should not be used with datablocks which belong to bigfile tablespaces.
This procedure returns version information for the database.
DBMS_UTILITY.DB_VERSION ( version OUT VARCHAR2, compatibility OUT VARCHAR2);
This procedure executes the DDL statement in parse_string
.
DBMS_UTILITY.EXEC_DDL_STATEMENT ( parse_string IN VARCHAR2);
Parameter | Description |
---|---|
|
DDL statement to be executed. |
This procedure displays the call stack at the point where an exception was raised, even if the procedure is called from an exception handler in an outer scope. The output is similar to the output of the SQLERRM function, but not subject to the same size limitation.
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE RETURN VARCHAR2;
The backtrace string. A NULL
string is returned if no error is currently being handled.
CREATE OR REPLACE PROCEDURE Log_Errors ( i_buff in varchar2 ) IS g_start_pos integer := 1; g_end_pos integer; FUNCTION Output_One_Line RETURN BOOLEAN IS BEGIN g_end_pos := Instr ( i_buff, Chr(10), g_start_pos ); CASE g_end_pos > 0 WHEN true THEN DBMS_OUTPUT.PUT_LINE ( Substr ( i_buff, g_start_pos, g_end_pos-g_start_pos ) ); g_start_pos := g_end_pos+1; RETURN TRUE; WHEN FALSE THEN DBMS_OUTPUT.PUT_LINE ( Substr ( i_buff, g_start_pos, (Length(i_buff)-g_start_pos)+1 ) ); RETURN FALSE; END CASE; END Output_One_Line; BEGIN WHILE Output_One_Line() LOOP NULL; END LOOP; END Log_Errors; / Set Doc Off Set Feedback off Set Echo Off CREATE OR REPLACE PROCEDURE P0 IS e_01476 EXCEPTION; pragma exception_init ( e_01476, -1476 ); BEGIN RAISE e_01476; END P0; / Show Errors CREATE OR REPLACE PROCEDURE P1 IS BEGIN P0(); END P1; / SHOW ERRORS CREATE OR REPLACE PROCEDURE P2 IS BEGIN P1(); END P2; / SHOW ERRORS CREATE OR REPLACE PROCEDURE P3 IS BEGIN P2(); END P3; / SHOW ERRORS CREATE OR REPLACE PROCEDURE P4 IS BEGIN P3(); END P4; / CREATE OR REPLACE PROCEDURE P5 IS BEGIN P4(); END P5; / SHOW ERRORS CREATE OR REPLACE PROCEDURE Top_Naive IS BEGIN P5(); END Top_Naive; / SHOW ERRORS CREATE OR REPLACE PROCEDURE Top_With_Logging IS -- NOTE: SqlErrm in principle gives the same info as Format_Error_Stack. -- But SqlErrm is subject to some length limits, -- while Format_Error_Stack is not. BEGIN P5(); EXCEPTION WHEN OTHERS THEN Log_Errors ( 'Error_Stack...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_STACK() ); Log_Errors ( 'Error_Backtrace...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() ); DBMS_OUTPUT.PUT_LINE ( '----------' ); END Top_With_Logging; / SHOW ERRORS -------------------------------------------------------------------------------- Set ServerOutput On call Top_Naive() /* ERROR at line 1: ORA-01476: divisor is equal to zero ORA-06512: at "U.P0", line 4 ORA-06512: at "U.P1", line 3 ORA-06512: at "U.P2", line 3 ORA-06512: at "U.P3", line 3 ORA-06512: at "U.P4", line 2 ORA-06512: at "U.P5", line 2 ORA-06512: at "U.TOP_NAIVE", line 3 */ ; Set ServerOutput On call Top_With_Logging() /* Error_Stack... ORA-01476: divisor is equal to zero Error_Backtrace... ORA-06512: at "U.P0", line 4 ORA-06512: at "U.P1", line 3 ORA-06512: at "U.P2", line 3 ORA-06512: at "U.P3", line 3 ORA-06512: at "U.P4", line 2 ORA-06512: at "U.P5", line 2 ORA-06512: at "U.TOP_WITH_LOGGING", line 6 ---------- */ ; /* ORA-06512: Cause: Backtrace message as the stack is unwound by unhandled exceptions. Action: Fix the problem causing the exception or write an exception handler for this condition. Or you may need to contact your application administrator or database administrator. */
This function formats the current error stack. This can be used in exception handlers to look at the full error stack.
DBMS_UTILITY.FORMAT_ERROR_STACK RETURN VARCHAR2;
This returns the error stack, up to 2000 bytes.
See FORMAT_ERROR_BACKTRACE Function.
This function formats the current call stack. This can be used on any stored procedure or trigger to access the call stack. This can be useful for debugging.
DBMS_UTILITY.FORMAT_CALL_STACK RETURN VARCHAR2;
pragma restrict_references(format_call_stack,WNDS);
This returns the call stack, up to 2000 bytes.
This function returns the current CPU time in 100th's of a second. The returned CPU time is the number of 100th's of a second from some arbitrary epoch.
DBMS_UTILITY.GET_CPU_TIME RETURN NUMBER;
Time is the number of 100th's of a second from some arbitrary epoch.
This procedure shows the dependencies on the object passed in.
DBMS_UTILITY.GET_DEPENDENCY type IN VARCHAR2, schema IN VARCHAR2, name IN VARCHAR2);
Parameter | Description |
---|---|
|
The type of the object, for example if the object is a table give the type as ' |
|
The schema name of the object. |
|
The name of the object. |
This function computes a hash value for the given string.
DBMS_UTILITY.GET_HASH_VALUE ( name VARCHAR2, base NUMBER, hash_size NUMBER) RETURN NUMBER;
Parameter | Description |
---|---|
|
String to be hashed. |
|
Base value for the returned hash value to start at. |
|
Desired size of the hash table. |
pragma restrict_references(get_hash_value, WNDS, RNDS, WNPS, RNPS);
A hash value based on the input string. For example, to get a hash value on a string where the hash value should be between 1000 and 3047, use 1000 as the base value and 2048 as the hash_size
value. Using a power of 2 for the hash_size
parameter works best.
This function gets the value of specified init.ora
parameter.
DBMS_UTILITY.GET_PARAMETER_VALUE ( parnam IN VARCHAR2, intval IN OUT BINARY_INTEGER, strval IN OUT VARCHAR2) RETURN BINARY_INTEGER;
Parameter | Description |
---|---|
|
Parameter name. |
|
Value of an integer parameter or the value length of a string parameter. |
|
Value of a string parameter. |
Returns | Description |
---|---|
|
0 if parameter is an integer/boolean parameter 1 if parameter is a string/file parameter |
When using DBMS_UTILITY.GET_PARAMETER_VALUE
, only the first parameter setting of /dir1
is returned when init.ora
is set as follows:
utl_file_dir = /dir1 utl_file_dir = /dir2
However, the full comma-delimited string is returned if you are using:
utl_file_dir = /dir1, /dir2
DECLARE parnam VARCHAR2(256); intval BINARY_INTEGER; strval VARCHAR2(256); partyp BINARY_INTEGER; BEGIN partyp := dbms_utility.get_parameter_value('max_dump_file_size', intval, strval); dbms_output.put('parameter value is: '); IF partyp = 1 THEN dbms_output.put_line(strval); ELSE dbms_output.put_line(intval); END IF; IF partyp = 1 THEN dbms_output.put('parameter value length is: '); dbms_output.put_line(intval); END IF; dbms_output.put('parameter type is: '); IF partyp = 1 THEN dbms_output.put_line('string'); ELSE dbms_output.put_line('integer'); END IF; END;
This function finds out the current time in 100th's of a second. It is primarily useful for determining elapsed time.
DBMS_UTILITY.GET_TIME RETURN NUMBER;
Time is the number of 100th's of a second from some arbitrary epoch.
This function finds out if this database is running in cluster database mode.
DBMS_UTILITY.IS_CLUSTER_DATABASE RETURN BOOLEAN;
This function returns TRUE
if this instance was started in cluster database mode; FALSE
otherwise.
This function creates a data block address given a file number and a block number. A data block address is the internal structure used to identify a block in the database. This function is useful when accessing certain fixed tables that contain data block addresses.
DBMS_UTILITY.MAKE_DATA_BLOCK_ADDRESS ( file NUMBER, block NUMBER) RETURN NUMBER;
Parameter | Description |
---|---|
|
File that contains the block. |
|
Offset of the block within the file in terms of block increments. |
pragma restrict_references (make_data_block_address, WNDS, RNDS, WNPS, RNPS);
Returns | Description |
---|---|
|
Data block address. |
This procedure resolves the given name, including synonym translation and authorization checking as necessary.
DBMS_UTILITY.NAME_RESOLVE ( name IN VARCHAR2, context IN NUMBER, schema OUT VARCHAR2, part1 OUT VARCHAR2, part2 OUT VARCHAR2, dblink OUT VARCHAR2, part1_type OUT NUMBER, object_number OUT NUMBER);
All errors are handled by raising exceptions. A wide variety of exceptions are possible, based on the various syntax error that are possible when specifying object names.
This procedure calls the parser to parse the given name as "a [. b [. c ]][@ dblink ]". It strips double quotes, or converts to uppercase if there are no quotes. It ignores comments of all sorts, and does no semantic analysis. Missing values are left as NULL
.
DBMS_UTILITY.NAME_TOKENIZE ( name IN VARCHAR2, a OUT VARCHAR2, b OUT VARCHAR2, c OUT VARCHAR2, dblink OUT VARCHAR2, nextpos OUT BINARY_INTEGER);
For each of a
, b
, c
, dblink
, tell where the following token starts in anext
, bnext
, cnext
, dnext
respectively.
This function returns a string that identifies the operating system and the TWO
TASK
PROTOCOL
version of the database. For example, "VAX/VMX-7
.1
.0
.0
"
The maximum length is port-specific.
DBMS_UTILITY.PORT_STRING RETURN VARCHAR2;
pragma restrict_references(port_string, WNDS, RNDS, WNPS, RNPS);
These procedures converts a PL/SQL table of names into a comma-delimited list of names. This takes a PL/SQL table, 1..n
, terminated with n+1
null
. The second version supports fully-qualified attribute names.
DBMS_UTILITY.TABLE_TO_COMMA ( tab IN UNCL_ARRAY, tablen OUT BINARY_INTEGER, list OUT VARCHAR2); DBMS_UTILITY.TABLE_TO_COMMA ( tab IN lname_array, tablen OUT BINARY_INTEGER, list OUT VARCHAR2);
Parameter | Description |
---|---|
|
PL/SQL table which contains list of table names. |
|
Number of tables in the PL/SQL table. |
|
Comma separated list of tables. |
Returns a comma-delimited list and the number of elements found in the table.
This procedure makes invalid database objects valid.
DBMS_UTILITY.VALIDATE( object_id NUMBER);
Parameter | Description |
---|---|
|
The ID number of object to be validated. This is the same as the value of the |
No errors are raised if the object does not exist or is already valid or is an object that cannot be validated.