Unix Technical Forum

How to implement SubType/SuperType in Oracle ?

This is a discussion on How to implement SubType/SuperType in Oracle ? within the Oracle Database forums, part of the Database Server Software category; --> Hi, I have a supertype and three subtypes, as attached below, how is the best approach to implement it ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-24-2008, 02:09 PM
xtanto@hotmail.com
 
Posts: n/a
Default How to implement SubType/SuperType in Oracle ?

Hi,

I have a supertype and three subtypes, as attached below, how is the
best approach to implement it in Oracle (9i/10g) ?

Thank you for your help,
Krist

Supertype : Employee
Employee_Number
Employee_Name
Address
Employee_Type
Date_Hired

SubType : Hourly_Employee
Hourly_Rate

SubType : Salaried_Employee
Annual_Salary
Stock_Options

SubType : CONSULTANT
Contract_Number
Billing_Rate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-24-2008, 02:09 PM
Tony Andrews
 
Posts: n/a
Default Re: How to implement SubType/SuperType in Oracle ?

xtanto@hotmail.com wrote:
> Hi,
>
> I have a supertype and three subtypes, as attached below, how is the
> best approach to implement it in Oracle (9i/10g) ?
>
> Thank you for your help,
> Krist
>
> Supertype : Employee
> Employee_Number
> Employee_Name
> Address
> Employee_Type
> Date_Hired
>
> SubType : Hourly_Employee
> Hourly_Rate
>
> SubType : Salaried_Employee
> Annual_Salary
> Stock_Options
>
> SubType : CONSULTANT
> Contract_Number
> Billing_Rate


For something this simple perhaps this:

CREATE TABLE Employee
( Employee_Number
, Employee_Name
, Address
, Employee_Type
, Date_Hired
, Hourly_Rate
, Annual_Salary
, Stock_Options
, Contract_Number
, Billing_Rate
);

With some check constraints like this one:

CHECK ((Employee_Type = 'Hourly' and Hourly_rate is not null) or
(Employee_Type <> 'Hourly' and Hourly_rate is null))

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-24-2008, 02:09 PM
Billy
 
Posts: n/a
Default Re: How to implement SubType/SuperType in Oracle ?

xtanto@hotmail.com wrote:
>
> I have a supertype and three subtypes, as attached below, how is the
> best approach to implement it in Oracle (9i/10g) ?
>
> Supertype : Employee
> Employee_Number
> Employee_Name
> Address
> Employee_Type
> Date_Hired
>
> SubType : Hourly_Employee
> Hourly_Rate
>
> SubType : Salaried_Employee
> Annual_Salary
> Stock_Options
>
> SubType : CONSULTANT
> Contract_Number
> Billing_Rate



The best approach depends on what your requirements are. If this is a
Relational Design, then simply apply Codd's normalisation rules and
normalise these entities to 3rd normal form.

If you want an Object Relation (O-R) design, it is a tad more complex
as the objects are persist as rows or columns in a table. A single
column itself can be a collection of persistant objects (called a
nested table in Oracle speak). There are limitations in dealing with
nested tables from a query perspective as each column contains a
distinctly unique table - you cannot simply query all nested tables.
After all, each nested table (collection) has no relationship with
another object's collection.

O-R designs can be very flexible - but otoh relational designs and
theory are mature, principles easy to grasp, understood by many more
than object designs.. so I tend to favour relational designs myself
(seeing how a muck up many developers already make using relational
designs I think O-R designs are too complex for the ordinary
developer).

So why O-R in Oracle? It has a terrific application in PL/SQL code..
which turning PL/SQL in PL/SQL++ (or is that PL/SQL# instead? ;-)

PS. Don't forget that your above sub-types are date range specific.
Hourly rates, salaries, stock options, billing rates and so on changes
over time.

--
Billy

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-24-2008, 02:10 PM
 
Posts: n/a
Default Re: How to implement SubType/SuperType in Oracle ?

I think , you can try:


CREATE TYPE "my_super_type" .....etc

it's available since oracle8i;

<xtanto@hotmail.com> a écrit dans le message de news:
1118746309.163235.138790@g14g2000cwa.googlegroups. com...
> Hi,
>
> I have a supertype and three subtypes, as attached below, how is the
> best approach to implement it in Oracle (9i/10g) ?
>
> Thank you for your help,
> Krist
>
> Supertype : Employee
> Employee_Number
> Employee_Name
> Address
> Employee_Type
> Date_Hired
>
> SubType : Hourly_Employee
> Hourly_Rate
>
> SubType : Salaried_Employee
> Annual_Salary
> Stock_Options
>
> SubType : CONSULTANT
> Contract_Number
> Billing_Rate
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com