4

Here is an image:

https://i.stack.imgur.com/AjHwH.png

This is how far I gone into coding:

CREATE TYPE appointment_list_type AS TABLE OF REF appointment_type;
/

CREATE OR REPLACE TYPE person_type AS OBJECT (
personID NUMBER,
Surname varchar2(10),
Forname varchar2(10),
dateOfBirth date,
AddressLine1 varchar2(30),
AddressLine2 varchar2(30),
Town varchar2(10),
contacTel1 varchar2(10),
contacTel2 varchar2(10)) NOT FINAL;
/

CREATE TYPE applicant_type UNDER person_type(
applicantID NUMBER,
maxPrice number(7,2),
desiredArea varchar2(10),
Attends appointment_list_type
);
/

CREATE TYPE salesperson_type UNDER person_type(
salespersonID NUMBER,
manager varchar2(10),
Makes appointment_list_type
);
/

This is creating the types of person seperating it into inheritance of Salesperson and Applicant.

CREATE TYPE appointment_type AS OBJECT(
appointmentID NUMBER,
Appdate date,
Apptime timestamp,
appointmentType varchar2(10),
levelOfInterest varchar2(10),
offerMade varchar2(10),
Made_by REF salesperson_type,
Attends_by REF applicant_type
);
/

This is appointment type, The references work for relating them together.

For creating the table:

CREATE TABLE person_table OF person_type (
personID PRIMARY KEY NOT NULL)
NESTED TABLE Attends STORE AS attend_meeting_table;

CREATE TABLE applicant_table OF applicant_type (
personID PRIMARY KEY NOT NULL)
NESTED TABLE Attends STORE AS attend_meeting_table;

CREATE TABLE salesperson_table OF salesperson_type (
personID PRIMARY KEY NOT NULL)
NESTED TABLE Makes STORE AS makes_meeting_table;    

CREATE TABLE appointment_table OF appointment_type (
appointmentID PRIMARY KEY NOT NULL,
SCOPE FOR (Made_by) IS person_table,
SCOPE FOR (Attends_by) IS person_table);

Also here is some code of what I done, I now here is my question:

How does inheritance work with doing 1 to many directly into Appointment?

I am realy confused by this. Can anyone out me help me on how to do this?

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
Scot365
  • 41
  • 2
  • You don't need the `;` **and** the `/` in a regular SQL statement. In fact both together are quite bad. For details see here: http://stackoverflow.com/a/10207695/330315 –  Aug 28 '13 at 16:48

1 Answers1

1

phuh, I think I finally figured whats bothering you...

Currently, the appointments REFd in applicant_table and salesperson_table are totally independent. That means that applicants could come to meetings with sales persons that are actually in a meeting with someone else :)

Of course you want all appointments to be stored in appointment_table.

That is the perfect use case for object views. You do not need these object tables at all. Relational tables are much easier to manage.

Just create normal tables and then object views, just like this one for SALESPERSON:

create view ov_salesperson as
 (select personID,
         salespersonID,
         SALESPERSON_TYPE
          (personID
           Surname,
           Forname,
           dateOfBirth,
           AddressLine1,
           AddressLine2,
           Town,
           contacTel1,
           contacTel2,
           salespersonID,
           manager,
           CAST 
            (MULTISET 
              (Select appointment_type
                       (appointmentID,
                        Appdate,
                        Apptime,
                        appointmentType,
                        levelOfInterest,
                        offerMade,
                        salesperson_id,
                        applicant_id
                       )
               From   appointment_table  A
               Where  A.salesperson_id = S.salesperson_id
              ) 
              as appointment_list_type 
            )
          ) as salesperson_obj
  from salesperson_table S
 );
HAL 9000
  • 3,877
  • 1
  • 23
  • 29