ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling
complimentary technical Workshops on Database Security for the first 30
Oracle Database customers located anywhere in North America, EMEA, LATAM, or
APAC that send an email to
asra_us@oracle.com. Request a Workshop for
your organization today.
Purpose
API supporting reference (REF) based operations. Unlike SQL, UTL_REF procedures enable writing generic type methods without knowing the object table name.
DECLARE
refvar person_t;
objout address_t;
BEGIN
utl_ref.lock_object(refvar, objout);
END;
/
CREATE OR REPLACE TYPE person_t AS OBJECT (
person_id NUMBER(5),
first_name VARCHAR2(30),
last_name VARCHAR2(30),
address address_t,
MEMBER PROCEDURE setAddress(addr IN address_t));
/
CREATE OR REPLACE TYPE BODY person_t IS
MEMBER PROCEDURE setAddress(addr address_t) IS
BEGIN
address := addr;
END;
END;
/
-- Under person_t: Simulate implementation of inheritance using a REF to person_t and delegation of setAddress to it.
CREATE OR REPLACE TYPE employee_t AS OBJECT (
thePerson REF person_t,
empno NUMBER(5),
deptREF department_t,
mgrREF person_t, -- was employee_t
MEMBER PROCEDURE setAddress(addr IN address_t));
/
CREATE OR REPLACE TYPE BODY Employee_t IS
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:
-- 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
NULL;
-- errmsg := SUBStr(SQLERRM, 1, 200);
END;
END;
/