Reputation: 3305
I have two tables called Parent
and Child
. I am using oracle to create these tables. Child table inherits from parent. How to create this inherited child table in oracle without creating types.
I want relevant oracle statement for following PostgreSQL create tables.
Create Table Parent
(
.....
)
Create Table Child
(
.....
)INHERITS (Parent);
Upvotes: 2
Views: 10059
Reputation: 633
yes it seems to work as in postgres table inheritance with the solution mentioned above, e.g.
DROP TABLE PEOPLE1;
DROP TABLE PEOPLE2;
DROP TYPE CHILD1;
DROP TYPE CHILD2;
CREATE OR REPLACE TYPE commun AS OBJECT (c1 integer, C2 date) NOT FINAL
/
CREATE OR REPLACE TYPE CHILD1 UNDER PARENT (c3 varchar2(20), c4 number(8,2))
/
CREATE OR REPLACE TYPE CHILD2 UNDER PARENT (c5 number(5,2), c6 varchar2(10))
/
CREATE TABLE PEOPLE1 OF CHILD1;
CREATE TABLE PEOPLE2 OF CHILD2;
insert into people1 values (1, sysdate, 'ABCDE', 3.14);
insert into people1 values (2, sysdate, 'FGGHJK', 2.24);
insert into people2 values (3, sysdate, 1.14, 'test');
insert into people2 values (4, sysdate, 8.24 , 'test1');
desc people1
desc people2
select * from people1;
select * from people2;
Upvotes: 0
Reputation: 50017
Oracle does not support inheritance by tables - it uses TYPEs (objects) instead. The way to do something like this in Oracle would be to declare the Parent TYPE and the Child TYPE, then create a table to contain instances of PARENT - something like:
CREATE OR REPLACE TYPE PARENT AS OBJECT (...);
CREATE OR REPLACE TYPE CHILD UNDER PARENT (...);
CREATE TABLE PEOPLE OF PARENT;
Since CHILD is a sub-type of PARENT it should be possible to store CHILD instances in the PEOPLE table.
Share and enjoy.
Upvotes: 9