Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
51
Добавлен:
16.04.2013
Размер:
5.97 Mб
Скачать

Sharing Objects through the REF Modifier

When you call a method using an instance of a subtype, the actual method that is executed depends on the exact declarations in the type hierarchy. If the subtype overrides the method that it inherits from its supertype, the call uses the subtype's implementation. Or, if the subtype does not override the method, the call uses the supertype's implementation. This capability is known as dynamic method dispatch.

Sharing Objects through the REF Modifier

It is inefficient to pass copies of large objects from subprogram to subprogram. It makes more sense to pass a pointer instead. A ref is a pointer to an object.

Sharing means that data is not replicated unnecessarily. When a shared object is updated, the change occurs in only one place, and any ref can retrieve the updated values instantly.

CREATE TYPE Home AS OBJECT (

address

VARCHAR2(35),

owner

VARCHAR2(25),

age

INTEGER,

style

VARCHAR(15),

floor plan

BLOB,

price

REAL(9,2),

...

 

);

/

CREATE TABLE homes OF Home;

By revising object type Person, you can model families, where several people share the same home. You use the type modifier REF to declare refs, which hold pointers to objects.

CREATE TYPE Person AS OBJECT (

first_name

VARCHAR2(10),

last_name

VARCHAR2(15),

birthday

DATE,

home_address

REF Home, -- can be shared by family

phone_number

VARCHAR2(15),

ss_number

INTEGER,

mother

REF Person, -- family members refer to each other

father

REF Person,

...

 

);

 

Notice how references from persons to homes and between persons model real-world relationships.

You can declare refs as variables, parameters, fields, or attributes. You can use refs as input or output variables in SQL data manipulation statements.

You cannot navigate through refs. Given an expression such as x.attribute, where x is a ref, PL/SQL cannot navigate to the table in which the referenced object is stored. For example, the following assignment is not allowed:

DECLARE

 

p_ref

REF Person;

phone_no VARCHAR2(15); BEGIN

phone_no := p_ref.phone_number; -- not allowed

12-16 PL/SQL User's Guide and Reference

Соседние файлы в папке Oracle 10g