REF is
a datatype in Oracle. It establishes a column object as a pointer to data in
another object table. The REF column itself does not hold the data. For example
CREATE TYPE dept_type AS
OBJECT (deptname VARCHAR2(24), deptnumber NUMBER);
CREATE TABLE dept_table OF
dept_type;
CREATE TABLE
emp (empname VARCHAR2(50), empnumber NUMBER, empdept REF
dept_type);
In the
relational table named emp, the column empdept is a REF column. It points to an
object of type dept_type
Types versus tables
When a
REF column is defined, it identifies an object type -- not a particular object
table. It is possible for a database to contain more than one object table
based on a single object type definition. Thus, the REF column definition
itself does not identify the target table(s)
Pointer resolution
When
the table holding the REF column is initialized, the values placed in the REF
column will be pointers to rows in the specific table or tables that have the desired
data. Later at runtime, when users look at the REF column, they will see the
pointed-to data (not the pointers).
How Developer displays REFs at design time
At
design time, when you ask to see a table that contains a REF column, the REF
column displays in its expanded form. That is, it shows the attributes in the
object type pointed to by the original REF definition.
In the
above example, the empdept REF column would show as holding two components or
attribute columns: deptname and deptnumber. These were the two attributes in
the object type (dept_type) identified in the REF definition.
Just as
with a regular column object, you can select any or all of the referred-to
components/attribute columns to become data items in the application. However,
in contrast to regular column objects, you can also select the REF name itself
to become a manipulatable item within your application. That is, you can use
the REF in your PL/SQL coding. By default, the REF becomes part of the null
canvas
How you can display REF data to your users
As an
application designer, you have a choice in how the runtime user will see the
referenced data (the resolved REF):
·
data
displayed in the data block in which the REF exists (sometimes called the
look-up method)
·
data
displayed in the data block pointed to by the REF (the master-detail method)
The
first choice (displaying the data as part of the data block in which the REF
exists) is the simplest. You select the desired REF components as items into
your data block, and at runtime Developer and Oracle Database Server will
resolve the references and place the actual referred-to data in the display
items. The user need see only the one block.
The
other choice (displaying the data in the pointed-to data block) requires
setting up a master-detail link. This is very similar to setting up a
master-detail link for two blocks having a primary-key foreign-key
relationship. In this case, the REF creates the link between the two blocks.
The user will see both blocks, but will see the REF data only in the
referred-to block.
The
Oracle Forms Data Block Wizard can be used to set up this master-detail
relationship.