Coat
Coat

Reputation: 717

Creating a Circular Reference Based On Table

I have a database with separate tables for national tax rates and county tax rates and I'd like to create objects to represent these that look something like...

create type county as object
(
  my_nation nation,
  local_taxRate number
);

create type counties as table of county;

create type nation as object
(
  national_taxRate number
  my_counties counties
);

This is impossible though since it creates a circular definition. Is there someway to handle this problem?

Upvotes: 1

Views: 190

Answers (1)

krokodilko
krokodilko

Reputation: 36107

According to the documentation:
http://docs.oracle.com/cd/E11882_01/appdev.112/e11822/adobjmng.htm#ADOBJ7651

Types that depend on each other for their definitions, either directly or through intermediate types, are called mutually dependent. For example, you might want to define object types employee and department in such a way that one attribute of employee is the department the employee belongs to and one attribute of department is the employee who manages the department.

If you visualize a diagram with arrows showing the relationships among a set of mutually dependent types, the connections form a loop. To define such a circular dependency, you must use REFs for at least one segment of the circle.

You need to use REF somewhere in the definition, for example:

create type nation /* empty type placeholder */
/

create type county as object
(
  my_nation REF nation,
  local_taxRate number
);
/

create type counties as table of county
/

/* redefinition of "empty" nation */
create type nation as object
(
  national_taxRate number,
  my_counties counties
)
/

Upvotes: 1

Related Questions