2010-12-13 47 views
1

Veuillez aider, la question est en bas.Référence SubType dans Oracle

CREATE OR REPLACE TYPE NameType AS OBJECT 
(firstName VARCHAR(20), middleName VARCHAR(20), lastName VARCHAR(20)) 
INSTANTIABLE 
FINAL; 

CREATE OR REPLACE TYPE ServicerType AS OBJECT 
(servicerID INTEGER, servicerType VARCHAR(10)) 
INSTANTIABLE 
FINAL; 

CREATE OR REPLACE TYPE PersonType AS OBJECT 
(personID INTEGER, name NameType, gender CHAR(1)) 
INSTANTIABLE 
NOT FINAL; 

CREATE OR REPLACE TYPE EmployeeType UNDER PersonType 
(servicerRef REF ServicerType) 
NOT INSTANTIABLE 
NOT FINAL; 

CREATE OR REPLACE TYPE FullTimeEmployeeType UNDER EmployeeType 
(yearlySalary NUMBER(19,4)) 
INSTANTIABLE 
FINAL; 

CREATE TABLE Servicer OF ServicerType; 
CREATE TABLE Person OF PersonType; 

INSERT ALL 
INTO Servicer values (ServicerType(100, 'Company') 
SELECT * FROM dual 

INSERT ALL 
INTO Person VALUES (FullTimeEmployeeType(200, 
    NameType('Bob', 'T', 'Builder'), 'M', 
    (select ref(s) from servicer s where servicerid = 100), 56700)) 
SELECT * FROM dual 

Maintenant, je veux exécuter cette requête:

select p.gender, p.name.firstName, p.name.lastName, p.yearlySalary from person p 

Je suis une erreur. Je sais que annualSalary est en FullTimeEmployee qui est un sous-type de personne, mais je ne sais pas comment le référencer.

Répondre

3

Vous avez besoin de la fonction TREAT

select p.gender, p.name.firstName, p.name.lastName, 
     treat(value(p) as FullTimeEmployeeType).yearlySalary 
from person p 
/