rem rem $Header: dbmsutil.sql,v 1.58 1995/12/21 14:38:47 ssamu Exp $ rem Rem Copyright (c) 1991, 1996 by Oracle Corporation Rem NAME Rem dbmsutil.sql - packages of various utility procedures Rem DESCRIPTION Rem This file contains various packages: Rem dbms_transaction - transaction commands Rem dbms_session - alter session commands Rem dbms_ddl - ddl commands Rem dbms_utility - helpful utilities Rem dbms_application_info - application information registration Rem dbms_system - database system level commands Rem dbms_space - segment space analysis Rem RETURNS Rem Rem NOTES Rem The procedural option is needed to use these facilities. Rem Rem All of the packages below run with the privileges of calling user, Rem rather than the package owner ('sys'). Rem Rem Procedure 'dbms_ddl.alter_compile' and 'dbms_ddl.analyze_object Rem commit the current transaction, perform the compilation, and Rem then commit again. Rem Rem The dbms_utility package is run-as-caller (psdicd.c) only for Rem its name_resolve, compile_schema and analyze_schema Rem procedures. This package is not run-as-caller Rem w.r.t. SQL (psdpgi.c) so that the SQL works correctly (runs as Rem SYS). The privileges are checked via dbms_ddl. Rem Rem MODIFIED (MM/DD/YY) Rem mmonajje 08/13/96 - Fixing bug 244014; Adding RESTRICT_REFERENCES pr Rem ssamu 12/21/95 - fix another typo Rem ssamu 12/21/95 - fix typo Rem ssamu 10/19/95 - add pragma for data_block_address_file Rem rtaranto 08/04/95 - merge changes from branch 1.50.720.2 Rem rtaranto 07/12/95 - Add dbms_utility.get_hash_value Rem hrizvi 04/03/95 - merge changes from branch 1.50.725.2 Rem jarnett 01/03/95 - add procedure purge_lost_db_entry Rem bhirano 12/23/94 - merge changes from branch 1.50.720.1 Rem hjakobss 10/12/94 - analyze_schema support for histograms Rem hrizvi 02/03/95 - add dist_txn_sync to dbms_system Rem bhirano 12/23/94 - merge changes from branch 1.41.710.6 Rem jloaiza 09/06/94 - dbms_registration -> dbms_application_info Rem atsukerm 06/20/94 - adding DBMS_SPACE package Rem jloaiza 06/08/94 - change name to dbms_registration Rem jloaiza 04/07/94 - add dbms_application Rem dsdaniel 04/07/94 - merge changes from branch 1.41.710.4 Rem wmaimone 04/07/94 - merge changes from branch 1.41.710.5 Rem adowning 03/29/94 - merge changes from branch 1.41.710.3 Rem wmaimone 02/07/94 - add set close_cached_open_cursors to dbms_sessio Rem dsdaniel 02/04/94 - dbms_util.port_string icd Rem adowning 02/02/94 - split file into public / private binary files Rem rjenkins 11/17/93 - merge changes from branch 1.41.710.2 Rem rjenkins 10/20/93 - merge changes from branch 1.41.710.1 Rem rjenkins 10/28/93 - make comma_to_table more consistent Rem rjenkins 10/12/93 - adding comma_to_table Rem rjenkins 09/03/93 - adding name_parse Rem hjakobss 07/15/93 - bug 170473 Rem hjakobss 07/13/93 - bug 169577 Rem dsdaniel 03/12/93 - local_tid, step_id functions for replication Rem mmoore 01/11/93 - merge changes from branch 1.37.312.1 Rem mmoore 01/05/93 - #(145287) add another exception for discrete mode Rem mmoore 12/11/92 - disable set_role in stored procs Rem rkooi 11/24/92 - fixes per Peter Rem rkooi 11/21/92 - get rid of error argument to name_resolve Rem tpystyne 11/20/92 - fix compile_all and analyze_schema Rem rkooi 11/16/92 - fix set_label Rem rkooi 11/16/92 - fix comments Rem rkooi 11/13/92 - add name_res procedure Rem tpystyne 11/07/92 - make analyze parameters optional Rem mmoore 11/04/92 - add new analyze options Rem ghallmar 11/03/92 - add dbms_transaction.purge_mixed Rem rkooi 10/30/92 - get rid of caller_id and unique_stmt_id Rem rkooi 10/26/92 - owner -> schema for SQL2 Rem rkooi 10/25/92 - bug 135880 Rem mmoore 10/13/92 - #(131686) change messages 2074,4092,0034 Rem rkooi 10/02/92 - compile_all fix Rem mmoore 10/02/92 - change pls_integer to binary_integer Rem tpystyne 10/01/92 - fix Bob's mistakes Rem tpystyne 09/28/92 - disallow commit/rollback force in rpc and trigge Rem mmoore 09/25/92 - #(130566) don't allow set_nls or set_role in trig Rem tpystyne 09/23/92 - rename analyze to analyze_object Rem rkooi 08/24/92 - handle delimited id's in alter_compile Rem tpystyne 08/06/92 - add analyze_schema Rem epeeler 07/29/92 - add function to get time Rem rkooi 06/25/92 - workaround pl/sql bug with 'in' in SQL Rem rkooi 06/03/92 - add 'get unique session id' Rem jcohen 05/28/92 - add = to alter session set label Rem jloaiza 05/12/92 - add discrete Rem rkooi 04/22/92 - put in checks for execute_sql for triggs, stored Rem mmoore 04/14/92 - move begin_oltp to package transaction Rem rkooi 04/06/92 - merge changes from branch 1.4.300.1 Rem rkooi 04/01/92 - Creation - split/recombined from other files Rem mroberts 02/21/92 - call alter_compile, not sql_ddl Rem rkooi 02/06/92 - testing Rem rkooi 02/03/92 - compilation errors Rem rkooi 01/16/92 - Creation REM ******************************************************************** REM THESE PACKAGES MUST NOT BE MODIFIED BY THE CUSTOMER. DOING SO REM COULD CAUSE INTERNAL ERRORS AND SECURITY VIOLATIONS IN THE REM RDBMS. SPECIFICALLY, THE PSD* AND EXECUTE_SQL ROUTINES MUST NOT BE REM CALLED DIRECTLY BY ANY CLIENT AND MUST REMAIN PRIVATE TO THE PACKAGE BODY. REM ******************************************************************** create or replace package dbms_transaction is ------------ -- OVERVIEW -- -- This package provides access to SQL transaction statements from -- stored procedures. -- It also provids functions for monitoring transaction activities -- (transaction ids and ordering of steps of transactions ) ---------------------------- -- PROCEDURES AND FUNCTIONS -- procedure read_only; -- Equivalent to SQL "SET TRANSACTION READ ONLY" procedure read_write; -- Equivalent to SQL "SET TRANSACTION READ WRITE" procedure advise_rollback; -- Equivalent to SQL "ALTER SESSION ADVISE ROLLBACK" procedure advise_nothing; -- Equivalent to SQL "ALTER SESSION ADVISE NOTHING" procedure advise_commit; -- Equivalent to SQL "ALTER SESSION ADVISE COMMIT" procedure use_rollback_segment(rb_name varchar2); -- Equivalent to SQL "SET TRANSACTION USE ROLLBACK SEGMENT " -- Input arguments: -- rb_name -- Name of rollback segment to use. procedure commit_comment(cmnt varchar2); -- Equivalent to SQL "COMMIT COMMENT " -- Input arguments: -- cmnt -- Comment to assoicate with this comment. procedure commit_force(xid varchar2, scn varchar2 default null); -- Equivalent to SQL "COMMIT FORCE , " -- Input arguments: -- xid -- Local or global transaction id. -- scn -- System change number. procedure commit; pragma interface (C, commit); -- 1 (see psdicd.c) -- Equivalent to SQL "COMMIT". Here for completeness. This is -- already implemented as part of PL/SQL. procedure savepoint(savept varchar2); pragma interface (C, savepoint); -- 2 (see psdicd.c) -- Equivalent to SQL "SAVEPOINT ". Here for -- completeness. This is already implemented as part of PL/SQL. -- Input arguments: -- savept -- Savepoint identifier. procedure rollback; pragma interface (C, rollback); -- 3 (see psdicd.c) -- Equivalent to SQL "ROLLBACK". Here for completeness. This is -- already implemented as part of PL/SQL. procedure rollback_savepoint(savept varchar2); pragma interface (C, rollback_savepoint); -- 4 (see psdicd.c) -- Equivalent to SQL "ROLLBACK TO SAVEPOINT ". Here for -- completeness. This is already implemented as part of PL/SQL. -- Input arguments: -- savept -- Savepoint identifier. procedure rollback_force(xid varchar2); -- Equivalent to SQL "ROLLBACK FORCE " -- Input arguments: -- xid -- Local or global transaction id. procedure begin_discrete_transaction; pragma interface (C, begin_discrete_transaction); -- 5 (see psdicd.c) -- Set "discrete transaction mode" for this transaction. -- Exceptions: -- ORA-08175 will be generated if a transaction attempts an operation -- which cannot be performed as a discrete transaction. If this -- exception is encountered, rollback and retry the transaction. -- ORA-08176 will be generated if a transaction encounters data changed -- by an operation that does not generate rollback data : create index, -- direct load or discrete transaction. If this exception is -- encountered, retry the operation that received the exception. -- DISCRETE_TRANSACTION_FAILED exception; pragma exception_init(DISCRETE_TRANSACTION_FAILED, -8175); CONSISTENT_READ_FAILURE exception; pragma exception_init(CONSISTENT_READ_FAILURE, -8176); procedure purge_mixed(xid varchar2); -- When indoubt transactions are forced to commit or rollback (instead of -- letting automatic recovery resolve their outcomes), there is a -- possibility that a transaction can have a mixed outcome: some sites -- commit, and others rollback. Such inconsistency cannot be resolved -- automatically by ORACLE; however, ORACLE will flag entries in -- DBA_2PC_PENDING by setting the MIXED column to a value of 'yes'. -- ORACLE will never automatically delete information about a mixed -- outcome transaction. When the application or DBA is sure all -- inconsistencies that might have arisen as a result of the mixed -- transaction have been resolved, this procedure can be used to -- delete the information about a given mixed outcome transaction. -- Input arguments: -- xid -- This must be set to the value of the LOCAL_TRAN_ID column in -- the DBA_2PC_PENDING table. procedure purge_lost_db_entry(xid varchar2); -- When a failure occurs during commit processing, automatic recovery will -- consistently resolve the results at all sites involved in the -- transaction. However, if the remote database is destroyed or -- recreated before recovery completes, then the entries used to -- control recovery in DBA_2PC_PENDING and associated tables will never -- be removed, and recovery will periodically retry. Procedure -- purge_lost_db_entry allows removal of such transactions from the -- local site. -- WARNING: purge_lost_db_entry should ONLY be used when the other -- database is lost or has been recreated. Any other use may leave the -- other database in an unrecoverable or inconsistent state. -- Before automatic recovery runs, the transaction may show -- up in DBA_2PC_PENDING as state "collecting", "committed", or -- "prepared". If the DBA has forced an in-doubt transaction to have -- a particular result by using "commit force" or "rollback force", -- then states "forced commit" or "forced rollback" may also appear. -- Automatic recovery will normally delete entries in any of these -- states. The only exception is when recovery finds a forced -- transaction which is in a state inconsistent with other sites in the -- transaction; in this case, the entry will be left in the table -- and the MIXED column will have a value 'yes'. -- However, under certain conditions, it may not be possible for -- automatic recovery to run. For example, a remote database may have -- been permanently lost. Even if it is recreated, it will get a new -- database id, so that recovery cannot identify it (a possible symptom -- is ORA-02062). In this case, the DBA may use the procedure -- purge_lost_db_entry to clean up the entries in any state other -- than "prepared". The DBA does not need to be in any particular -- hurry to resolve these entries, since they will not be holding any -- database resources. -- The following table indicates what the various states indicate about -- the transaction and what the DBA actions should be: -- State State of State of Normal Alternative -- Column Global Local DBA DBA -- Transaction Transaction Action Action -- ---------- ------------ ------------ ------ --------------- -- collecting rolled back rolled back none purge_lost_db_entry (1) -- committed committed committed none purge_lost_db_entry (1) -- prepared unknown prepared none force commit or rollback -- forced unknown committed none purge_lost_db_entry (1) -- commit -- forced unknown rolled back none purge_lost_db_entry (1) -- rollback -- forced mixed committed (2) -- commit -- (mixed) -- forced mixed rolled back (2) -- rollback -- (mixed) -- Note 1: Use only if significant reconfiguration has occurred so that -- automatic recovery cannot resolve the transaction. Examples are -- total loss of the remote database, reconfiguration in software -- resulting in loss of two-phase commit capability, or loss of -- information from an external transaction coordinator such as a TP -- Monitor. -- Note 2: Examine and take any manual action to remove inconsistencies, -- then use the procedure purge_mixed. -- Input arguments: -- xid -- This must be set to the value of the LOCAL_TRAN_ID column in -- the DBA_2PC_PENDING table. FUNCTION local_transaction_id(create_transaction BOOLEAN := FALSE) RETURN VARCHAR2; -- Return local (to instance) unique identfier for current transaction -- Return null if there is no current transction. -- Input parameters: -- create_transaction -- If true , start a transaciton if one is not currently -- active. -- FUNCTION step_id RETURN NUMBER; -- Return local (to local transaction ) unique positive integer that orders -- The DML operations of a transaction. -- Input parmaeters: end; / drop public synonym dbms_transaction / create public synonym dbms_transaction for sys.dbms_transaction / grant execute on dbms_transaction to public / create or replace package dbms_session is ------------ -- OVERVIEW -- -- This package provides access to SQL "alter session" statements, and -- other session information from, stored procedures. ---------------------------- -- PROCEDURES AND FUNCTIONS -- procedure set_role(role_cmd varchar2); -- Equivalent to SQL "SET ROLE ...". -- Input arguments: -- role_cmd -- This text is appended to "set role " and then executed as SQL. procedure set_sql_trace(sql_trace boolean); -- Equivalent to SQL "ALTER SESSION SET SQL_TRACE ..." -- Input arguments: -- sql_trace -- TRUE or FALSE. Turns tracing on or off. procedure set_nls(param varchar2, value varchar2); -- Equivalent to SQL "ALTER SESSION SET = " -- Input arguments: -- param -- The NLS parameter. The parameter name must begin with 'NLS'. -- value -- The value to set the parameter to. If the parameter is a -- text literal then it will need embedded single-quotes. For -- example "set_nls('nls_date_format','''DD-MON-YY''')" procedure close_database_link(dblink varchar2); -- Equivalent to SQL "ALTER SESSION CLOSE DATABASE LINK " -- Input arguments: -- name -- The name of the database link to close. procedure set_label(lbl varchar2); -- Equivalent to SQL "ALTER SESSION SET LABEL