Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

sql - Create Children and Parent of a Person

I have the following Type Address and PhoneNumber:

CREATE TYPE Adress AS Object (Street varchar2(50), PostalC number, Ville varchar2(50));
CREATE TYPE PhoneNumber AS Object (Ind varchar2(3), PhNumber varchar2(20));

If a person can have many children and a child can have only 2 persons as parents what are the modification I need to have in my Person type below :

CREATE TYPE Person;
CREATE TYPE Person AS Object (
FirstName varchar2(50), LastName varchar2(50), Adr Address , Father REF Person, Mother REF Person);

Is to correct to have a self reference (Father and Mother) to the same type?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Is to correct to have a self reference (Father and Mother) to the same type?

Yes, they are all person.

If a person can have many children and a child can have only 2 persons as parents what are the modification I need to have in my Person type below:

See the answer to your previous question:

CREATE TYPE person;

CREATE TYPE person_table AS TABLE OF REF person;

CREATE TYPE person AS OBJECT(
  id        NUMBER(12,0),
  FirstName VARCHAR2(50),
  LastName  VARCHAR2(50),
  Adr       Address,
  Father    REF Person,
  Mother    REF Person,
  Children  person_table
);

db<>fiddle here

a child can have only 2 persons as parents

A child can only have 2 people as biological parents; however, it is pretty common these days for parents to separate and enter new relationships and a child may have many step-parents or the parents could give birth via surrogacy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...