[英]PL/SQL inherit rowtype
I know Oracle PL/SQL allows to create object sub type using the "under" keyword. 我知道Oracle PL / SQL允许使用“ under”关键字创建对象子类型。 But is it possible to create a subtype that inherit the RowType of a particular table?
但是是否可以创建一个继承特定表的RowType的子类型?
For example, if there is a table named Customer and I want to create an object type that has all attributes in Customer table with extra fields. 例如,如果有一个名为Customer的表,而我想创建一个对象类型,该对象类型具有Customer表中的所有属性以及额外的字段。
I tried: 我试过了:
create or replace type t_sub_type as object under Customer%RowType (
price NUMBER
);
Of course, the code fails to compile. 当然,代码无法编译。 So is there any way to achieve this?
那么有什么办法可以做到这一点?
Not unless customer
happens to be an object table. 除非
customer
碰巧是一个对象表,否则不会这样。 If customer
is a regular old table, customer%rowtype
is a record, not an object, so it cannot be inherited from. 如果
customer
是常规旧表, customer%rowtype
是记录,而不是对象,因此不能从中继承。 If you created an object type customer_typ
and created a table customer
of those object types, then you could create a subtype of customer_typ
. 如果创建了对象类型
customer_typ
并创建了这些对象类型的表customer
,则可以创建customer_typ
的子类型。 Something like 就像是
SQL> ed
Wrote file afiedt.buf
1 create type customer_typ
2 as object (
3 name varchar2(100),
4 address varchar2(1000),
5 phone varchar2(30)
6 )
7* not final
SQL> /
Type created.
SQL> create table customer_tbl of customer_typ;
Table created.
SQL> create type subcustomer_typ
2 under customer_typ (
3 newColumn number
4 );
5 /
Type created.
SQL> desc subcustomer_typ;
subcustomer_typ extends SCOTT.CUSTOMER_TYP
Name Null? Type
----------------------------------------- -------- ----------------------------
NAME VARCHAR2(100)
ADDRESS VARCHAR2(1000)
PHONE VARCHAR2(30)
NEWCOLUMN NUMBER
Of course, I'm hard pressed to imagine a case where this would make a great deal of sense. 当然,我很难想像这种情况很有道理。 But it is possible.
但是有可能。 If you can describe why you want to inherit from a
%rowtype
record, we may be able to suggest some alternative approaches. 如果您可以描述为什么要从
%rowtype
记录继承,我们也许可以提出一些替代方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.