Oracle9i Supplied PL/SQL Packages and Types Reference Release 2 (9.2) Part Number A96612-01 |
|
UTL_REF , 2 of 2
Subprogram | Description |
---|---|
Selects an object given a reference. |
|
Locks an object given a reference. |
|
Updates an object given a reference. |
|
Deletes an object given a reference. |
This procedure selects an object given its reference. The selected object is retrieved from the database and its value is put into the PL/SQL variable 'object'. The semantic of this subprogram is similar to the following SQL statement:
SELECT VALUE(t) INTO object FROM object_table t WHERE REF(t) = reference;
Unlike the above SQL statement, this subprogram does not require you to specify the object table name where the object resides.
UTL_REF.SELECT_OBJECT ( reference IN REF "<typename>", object IN OUT "<typename>");
May be raised.
This procedure locks an object given a reference. In addition, this procedure lets the program select the locked object. The semantic of this subprogram is similar to the following SQL statement:
SELECT VALUE(t) INTO object FROM object_table t WHERE REF(t) = reference FOR UPDATE;
Unlike the above SQL statement, this subprogram does not require you to specify the object table name where the object resides. It is not necessary to lock an object before updating/deleting it.
UTL_REF.LOCK_OBJECT ( reference IN REF "<typename>"); UTL_REF.LOCK_OBJECT ( reference IN REF "<typename>", object IN OUT "<typename>");
Parameter | Description |
---|---|
reference |
Reference of the object to lock. |
object |
The PL/SQL variable that stores the locked object. This variable should be of the same object type as the locked object. |
May be raised.
This procedure updates an object given a reference. The referenced object is updated with the value contained in the PL/SQL variable 'object'. The semantic of this subprogram is similar to the following SQL statement:
UPDATE object_table t SET VALUE(t) = object WHERE REF(t) = reference;
Unlike the above SQL statement, this subprogram does not require you to specify the object table name where the object resides.
UTL_REF.UPDATE_OBJECT ( reference IN REF "<typename>", object IN "<typename>");
May be raised.
This procedure deletes an object given a reference. The semantic of this subprogram is similar to the following SQL statement:
DELETE FROM object_table WHERE REF(t) = reference;
Unlike the above SQL statement, this subprogram does not require you to specify the object table name where the object resides.
UTL_REF.DELETE_OBJECT ( reference IN REF "<typename>");
Parameter | Description |
---|---|
reference |
Reference of the object to delete. |
May be raised.
The following example illustrates usage of the UTL_REF
package to implement this scenario: if an employee of a company changes their address, their manager should be notified.
... declarations of Address_t
and others...
CREATE OR REPLACE TYPE Person_t ( name VARCHAR2(64), gender CHAR(1), address Address_t, MEMBER PROCEDURE setAddress(addr IN Address_t) ); CREATE OR REPLACE TYPE BODY Person_t ( MEMBER PROCEDURE setAddress(addr IN Address_t) IS BEGIN address := addr; END; ); CREATE OR REPLACE TYPE Employee_t (
Under Person_t
: Simulate implementation of inheritance using a REF
to Person_t
and delegation of setAddress
to it.
thePerson REF Person_t, empno NUMBER(5), deptREF Department_t, mgrREF Employee_t, reminders StringArray_t, MEMBER PROCEDURE setAddress(addr IN Address_t), MEMBER procedure addReminder(reminder VARCHAR2); ); CREATE TYPE BODY Employee_t ( MEMBER PROCEDURE setAddress(addr IN Address_t) IS myMgr Employee_t; meAsPerson Person_t; BEGIN
Update the address by delegating the responsibility to thePerson
. Lock the Person object from the reference, and also select it:
UTL_REF.LOCK_OBJECT(thePerson, meAsPerson); meAsPerson.setAddress(addr);
Delegate to thePerson
:
UTL_REF.UPDATE_OBJECT(thePerson, meAsPerson); if mgr is NOT NULL THEN
Give the manager a reminder:
UTL_REF.LOCK_OBJECT(mgr); UTL_REF.SELECT_OBJECT(mgr, myMgr); myMgr.addReminder ('Update address in the employee directory for' || thePerson.name || ', new address: ' || addr.asString); UTL_REF.UPDATE_OBJECT(mgr, myMgr); END IF; EXCEPTION WHEN OTHERS THEN errnum := SQLCODE; errmsg := SUBSTR(SQLERRM, 1, 200);
|
Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|