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
现在我想运行此查询:
select p.gender, p.name.firstName, p.name.lastName, p.yearlySalary from person p
我收到错误。我知道yearlySalary位于FullTimeEmployee中,它是person的子类型,但我只是不知道如何引用它。
Please help, the question is at the bottom.
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
Now I want to run this query:
select p.gender, p.name.firstName, p.name.lastName, p.yearlySalary from person p
I got an error. I know that yearlySalary is in FullTimeEmployee which is a subtype of person, but I just don't know how to reference it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要 TREAT 函数
You need the TREAT function