OddCommand24
OddCommand24

Reputation: 441

Include/refer attributes of a table in an object in Oracle?

I have table of Restaurants:

Create table Restaurants(
resID number,
resName varchar(20)
resLocation varchar(25));

I want to create an object 'ResObject' and in it, and add attributes of 'resID' and 'resName' from the 'Restaurants' table. Is there a way to refer a table's attribute in an object? I know about Object tables and inheritance, but they work on objects, not from table to objects. Any help would be great.

Upvotes: 0

Views: 31

Answers (1)

MT0
MT0

Reputation: 168106

It sounds like you want to use inheritance and object-derived tables:

CREATE TYPE BasicRestaurant AS OBJECT(
  resid       NUMBER,
  resname     VARCHAR2(20)
) NOT INSTANTIABLE NOT FINAL;

CREATE TYPE Restaurant UNDER BasicRestaurant(
  reslocation VARCHAR2(25)
);

CREATE TYPE ResObject UNDER BasicRestaurant(
  value NUMBER
);

Then you can create the tables:

CREATE TABLE Restaurants OF Restaurant;
CREATE TABLE ResObjects OF ResObject;

And the ResObject data-type and the ResObjects table will have the same data-type for the columns they share with the Restaurants table.

db<>fiddle here

Upvotes: 1

Related Questions