attribute inheritance.The property by which subtype entities possess the values of all attributes of a supertype iscalled:A) hierarchy reception.B) class management.C) attribute inheritance.D) generalization. Show
SupertypeWhich of the following is a generic entity type that has a relationship with one or moresubtypes? Get answer to your question and much more Define one vehicle entity type to hold all entities.Given the following entities, which of the choices below would be the most complicated?Automobile: VIN, EngineSize, NumberOfDoors, NumberOfPassengers, FuelType, TransmissionSUV: VIN, EngineSize, NumberOfPassengers, NoWheelDrive, FuelType, TransmissionTruck: VIN, EngineSize, NoWheelDrive, FuelType, Transmission, Payload Get answer to your question and much more there are attributes that apply to some but not all instances of an entity typeSubtypes should be used when: Get answer to your question and much more specializationThe process of defining one or more subtypes of a supertype and forming relationships iscalled:A) specialization.B) generalization.C) creating discord.D) selecting classesgeneralization 3. Give an example (other than those discussed in the chapter) of asupertype/subtype relationship. Get answer to your question and much more 4.What is attribute inheritance? Why is it important? Get answer to your question and much more 5.Give an example of each of the following:a.supertype/ subtype relationship where the disjoint rule appliesb.supertype/subtype relationship where the overlap rule applies Get answer to your question and much more 2.3.1 About Inheritance in SQL Object TypesInheritance is the mechanism that connects subtypes in a hierarchy to their supertypes. Subtypes automatically inherit the attributes and methods of their parent type. Also, the inheritance link remains alive. Subtypes automatically acquire any changes made to these attributes or methods in the parent: any attributes or methods updated in a supertype are updated in subtypes as well. Note: Oracle only supports single inheritance. Therefore, a subtype can derive directly from only one supertype, not more than one. With object types in a type hierarchy, you can model an entity such as a customer, and also define different specializing subtypes of customers under the original type. You can then perform operations on a hierarchy and have each type implement and execute the operation in a special way. 2.3.2 Supertypes and SubtypesA subtype can be derived from a supertype either directly or indirectly through intervening levels of other subtypes. A supertype can have multiple sibling subtypes, but a subtype can have at most one direct parent supertype (single inheritance). To derive a subtype from a supertype, define a specialized variant of the supertype that adds new attributes and methods to the set inherited from the parent or redefine (override) the inherited methods. For example, from a Unless a subtype redefines an inherited method, it always contains the same core set of attributes and methods that are in the parent type, plus any attributes and methods that it adds. If a Subtypes are created using the keyword
You can specialize the attributes or methods of a subtype in these ways:
The inheritance relationship between a supertype and its subtypes is the source of much of the power of objects and much of their complexity. Being able to change a method in a supertype and have the change take effect in all the subtypes downstream just by recompiling is very powerful. But this same capability means that you have to consider whether or not you want to allow a type to be specialized or a method to be redefined. Similarly, for a table or column to be able to contain any type in a hierarchy is also powerful, but you must decide whether or not to allow this in a particular case. Also, you may need to constrain DML statements and queries so that they pick out just the range of types that you want from the type hierarchy. 2.3.3 FINAL and NOT FINAL Types and Methods for InheritanceObject types can be inheritable and methods can be overridden if they are so defined. For an object type or method to be inheritable, the definition must specify that it is inheritable. For both types and methods, the keywords
2.3.3.1 Creating an Object Type as NOT FINAL with a FINAL Member FunctionYou can create a Example 2-12 Creating an Object Type as NOT FINAL with a FINAL Member Function DROP TYPE person_typ FORCE; -- above necessary if you have previously created object CREATE OR REPLACE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20), FINAL MAP MEMBER FUNCTION get_idno RETURN NUMBER) NOT FINAL; / 2.3.3.2 Creating a NOT FINAL Object TypeYou can create an object type as Example 2-13 declares Example 2-13 Creating the person_typ Object Type as NOT FINAL DROP TYPE person_typ FORCE; -- above necessary if you have previously created object CREATE OR REPLACE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20)) NOT FINAL; / 2.3.4 Changing a FINAL TYPE to NOT FINALYou can change inheritance by changing a final type to a not final type and vice versa with an For example, the following statement changes ALTER TYPE person_typ FINAL; You can only alter a type from 2.3.5 Subtype Creation2.3.5.1 Creating a Parent or Supertype ObjectYou can create a parent or supertype object using the Example 2-14 provides a parent or supertype Note the Example 2-14 Creating the Parent or Supertype person_typ Object DROP TYPE person_typ FORCE; -- if created CREATE OR REPLACE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20), MAP MEMBER FUNCTION get_idno RETURN NUMBER, MEMBER FUNCTION show RETURN VARCHAR2) NOT FINAL; / CREATE OR REPLACE TYPE BODY person_typ AS MAP MEMBER FUNCTION get_idno RETURN NUMBER IS BEGIN RETURN idno; END; -- function that can be overriden by subtypes MEMBER FUNCTION show RETURN VARCHAR2 IS BEGIN RETURN 'Id: ' || TO_CHAR(idno) || ', Name: ' || name; END; END; / 2.3.5.2 Creating a Subtype ObjectA subtype inherits the attributes and methods of the supertype. These are inherited:
Example 2-15 defines the Example 2-15 Creating a student_typ Subtype Using the UNDER Clause -- requires Ex. 2-14 CREATE TYPE student_typ UNDER person_typ ( dept_id NUMBER, major VARCHAR2(30), OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2) NOT FINAL; / CREATE TYPE BODY student_typ AS OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2 IS BEGIN RETURN (self AS person_typ).show || ' -- Major: ' || major ; END; END; / The statement that defines 2.3.5.3 Generalized InvocationGeneralized invocation provides a mechanism to invoke a method of a supertype or a parent type, rather than the specific subtype member method. Example 2-15 demonstrates this using the following syntax: (SELF AS person_typ).show The Methods are invoked just like normal member methods, except that the type name after 2.3.5.4 Using Generalized InvocationIn Example 2-16, there is an implicit Example 2-16 Using Generalized Invocation -- Requires Ex. 2-14 and 2-15
DECLARE
myvar student_typ := student_typ(100, 'Sam', '6505556666', 100, 'Math');
name VARCHAR2(100);
BEGIN
name := (myvar AS person_typ).show; --Generalized invocation
END;
/ 2.3.5.5 Using Generalized ExpressionGeneralized expression, like member method invocation, is also supported when a method is invoked with an explicit self argument. Example 2-17 Using Generalized Expression -- Requires Ex. 2-14 and 2-15
DECLARE
myvar2 student_typ := student_typ(101, 'Sam', '6505556666', 100, 'Math');
name2 VARCHAR2(100);
BEGIN
name2 := person_typ.show((myvar2 AS person_typ)); -- Generalized expression
END;
/
Double parentheses are used in this example because NOTE: Constructor methods cannot be invoked using this syntax. Also, the type name that appears after This syntax can only be used to invoke corresponding overriding member methods of the parent types. 2.3.5.6 Creating Multiple SubtypesA type can have multiple child subtypes, and these subtypes can also have subtypes.
Example 2-18 creates another subtype Example 2-18 Creating an employee_typ Subtype Using the UNDER Clause -- requires Ex. 2-14 DROP TYPE employee_typ FORCE; -- if previously created CREATE OR REPLACE TYPE employee_typ UNDER person_typ ( emp_id NUMBER, mgr VARCHAR2(30), OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2); / CREATE OR REPLACE TYPE BODY employee_typ AS OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2 IS BEGIN RETURN (SELF AS person_typ).show|| ' -- Employee Id: ' || TO_CHAR(emp_id) || ', Manager: ' || mgr ; END; END; / 2.3.5.7 Creating a Subtype Under Another SubtypeA subtype can be defined under another subtype. The new subtype inherits all the attributes and methods that its parent type has, both declared and inherited. Example 2-19 defines a new subtype Example 2-19 Creating a part_time_student_typ Subtype Using the UNDER Clause CREATE TYPE part_time_student_typ UNDER student_typ (
number_hours NUMBER,
OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2);
/
CREATE TYPE BODY part_time_student_typ AS
OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2 IS
BEGIN
RETURN (SELF AS person_typ).show|| ' -- Major: ' || major ||
', Hours: ' || TO_CHAR(number_hours);
END;
END;
/
2.3.5.8 Creating Tables that Contain Supertype and Subtype ObjectsYou can create tables that contain supertype and subtype instances. You can then populate the tables as shown with the Example 2-20 Inserting Values into Substitutable Rows of an Object Table CREATE TABLE person_obj_table OF person_typ; INSERT INTO person_obj_table VALUES (person_typ(12, 'Bob Jones', '650-555-0130')); INSERT INTO person_obj_table VALUES (student_typ(51, 'Joe Lane', '1-650-555-0140', 12, 'HISTORY')); INSERT INTO person_obj_table VALUES (employee_typ(55, 'Jane Smith', '1-650-555-0144', 100, 'Jennifer Nelson')); INSERT INTO person_obj_table VALUES (part_time_student_typ(52, 'Kim Patel', '1-650-555-0135', 14, 'PHYSICS', 20)); You can call the SELECT p.show() FROM person_obj_table p; The output is similar to:
Note that data that the 2.3.6 NOT INSTANTIABLE Types and MethodsTypes and methods can be declared
You can alter an instantiable type to a non-instantiable type and vice versa with an A type that contains a non-instantiable method must itself be declared not instantiable, as shown in Example 2-21. 2.3.7 Creating a Non-INSTANTIABLE Object TypeIf a subtype does not provide an implementation for every inherited non-instantiable method, the subtype itself, like the supertype, must be declared not instantiable. A non-instantiable subtype can be defined under an instantiable supertype. Example 2-21 Creating an Object Type that is NOT INSTANTIABLE DROP TYPE person_typ FORCE; -- if previously created CREATE OR REPLACE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20), NOT INSTANTIABLE MEMBER FUNCTION get_idno RETURN NUMBER) NOT INSTANTIABLE NOT FINAL;/ 2.3.8 Changing an Object Type to INSTANTIABLEThe In
Example 2-22 an Example 2-22 Altering an Object Type to INSTANTIABLE CREATE OR REPLACE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20)) NOT INSTANTIABLE NOT FINAL;/ ALTER TYPE person_typ INSTANTIABLE; Changing to a Not Instantiable Type You can alter an instantiable type to a non-instantiable type only if the type has no columns, views, tables, or instances that reference that type, either directly, or indirectly, through another type or subtype. You cannot declare a non-instantiable type to be 2.3.9 Overloaded and Overridden Methods2.3.9.1 Overloading MethodsAdding new methods that have the same names as inherited methods to the subtype is called overloading. Methods that have the same name but different signatures are called overloads when they exist in the same user-defined type. A method signature consists of the method's name and the number, types, and the order of the method's formal parameters, including the implicit
Overloading is useful when you want to provide a variety of ways of doing something. For example, an ellipse object might overload a The compiler uses the method signatures to determine which method to call when a type has several overloaded methods. In the following pseudocode, subtype
The 2.3.9.2 Overriding and Hiding MethodsRedefining an inherited method to customize its behavior in a subtype is called overriding, in the case of member methods, or hiding, in the case of static methods. Unlike overloading, you
do not create a new method, just redefine an existing one, using the keyword Overriding and hiding redefine an inherited method to make it do something different in the subtype. For example, a subtype Overriding and hiding are similar in that, in either case, the version of the method redefined in the subtype eclipses the original version of the same name and signature so that the new version is executed rather than the original one whenever a subtype instance invokes the method. If the subtype itself has subtypes, these inherit the redefined method instead of the original version. With overriding, the system relies on type information contained in the member method's implicit self argument to dynamically choose the correct version of the method to execute. With hiding, the correct version is identified at compile time, and dynamic dispatch is not necessary. See "Dynamic Method Dispatch". To override or hide a method, you must preserve its signature. Overloads of a method all have the same name, so the compiler uses the signature of the subtype's method to identify the particular version in the supertype that is superseded. You signal the override with the In the following pseudocode, the subtype signals that it is overriding method
For a diagram of this hierarchy, see Figure 2-2. 2.3.9.3 Restrictions on Overriding MethodsThere are certain restrictions on overriding methods:
2.3.10 Dynamic Method DispatchDynamic method dispatch refers to the way that method calls are dispatched to the nearest implementation at run time, working up the type hierarchy from the current or specified type. Dynamic method dispatch is only available when overriding member methods and does not apply to static methods. With method overriding, a type hierarchy can
define multiple implementations of the same method. In the following hierarchy of types When one of these methods is invoked, the type of the object instance that invokes it determines which implementation of the method to use. The call is then dispatched to that implementation for execution. This process of selecting a method implementation is called virtual or dynamic method dispatch because it is done at run time, not at compile time. The method call works up the type hierarchy: never down. If the call invokes a member method of an object instance, the type of that instance is the current type, and the implementation defined or inherited by that type is used. If the call invokes a static method of a type, the implementation defined or inherited by that specified type is used. 2.3.11 Type Substitution in a Type HierarchyWhen you work with types in a type hierarchy, sometimes you need to work at the most general level, for example, to select or update all persons. But at other times, you need to select or update only a specific subtype such as a student, or only persons who are not students. The (polymorphic) ability to select all persons and get back not only objects whose declared type is In general, types are substitutable. Object attributes, collection elements and This seems expected, given that a subtype is, after all, just a specialized kind of one of its supertypes. Formally, though, a subtype is a type in its own right: it is not the same type as its supertype. A column that holds all persons, including all persons who are students and all persons who are employees, actually holds data of multiple types. In principle, object attributes, collection elements and 2.3.12 Column and Row Substitutability2.3.12.1 About Column and Row SubstitutabilityYou can substitute object type columns and object type rows in object tables. Consider the Similarly, Example 2-23 shows that a
substitutable column of type Example 2-23 Inserting Values into Substitutable Columns of a Table DROP TYPE person_typ FORCE; -- if previously created DROP TYPE student_typ FORCE; -- if previously created DROP TYPE part_time_student_typ FORCE; -- if previously created DROP TABLE contacts; if previously created CREATE OR REPLACE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20)) NOT FINAL;/ CREATE TYPE student_typ UNDER person_typ ( dept_id NUMBER, major VARCHAR2(30)) NOT FINAL; / CREATE TYPE part_time_student_typ UNDER student_typ ( number_hours NUMBER); / CREATE TABLE contacts ( contact person_typ, contact_date DATE ); INSERT INTO contacts VALUES (person_typ (12, 'Bob Jones', '650-555-0130'), '24 Jun 2003' ); INSERT INTO contacts VALUES (student_typ(51, 'Joe Lane', '1-650-555-0178', 12, 'HISTORY'), '24 Jun 2003' ); INSERT INTO contacts VALUES (part_time_student_typ(52, 'Kim Patel', '1-650-555-0190', 14, 'PHYSICS', 20), '24 Jun 2003' ); A newly created subtype can be stored in any substitutable tables and columns of its supertype, including tables and columns that existed before the subtype was created. In general, you can access attributes using dot notation. To access attributes of a subtype of a row or column's declared type, you can use the SELECT TREAT(contact AS student_typ).major FROM contacts; See "TREAT". 2.3.12.2 Using OBJECT_VALUE and OBJECT_ID with Substitutable RowsYou can access and identify the object identifier (OID) and value of a substitutable row. Use the Example 2-24 Using OBJECT_VALUE and OBJECT_ID DROP TABLE person_obj_table; -- required if previously created CREATE TABLE person_obj_table OF person_typ; INSERT INTO person_obj_table VALUES (person_typ(20, 'Bob Jones', '650-555-0130')); SELECT p.object_id, p.object_value FROM person_obj_table p; 2.3.12.3 Subtypes with Attributes of a SupertypeA subtype can have an attribute whose type is the type of a supertype. For example: Example 2-25 Creating a Subtype with a Supertype Attribute -- requires Ex 2-22 CREATE TYPE student_typ UNDER person_typ ( dept_id NUMBER, major VARCHAR2(30), advisor person_typ); / However, columns of such types are not substitutable. Similarly, a subtype can have a collection attribute whose element type is one of its supertypes, but, again, columns of such types are not substitutable. For example, if You can, however, define substitutable columns of subtypes that have Example 2-26 Defining Columns of Subtypes that have REF Attributes -- not to be executed CREATE TYPE subcategory_ref_list_typ AS TABLE OF REF category_typ; / CREATE TYPE composite_category_typ UNDER category_typ ( subcategory_ref_list subcategory_ref_list_typ ... See "Turning Off Substitutability in a New Table". 2.3.12.4 Substitution of REF Columns and Attributes
2.3.12.5 Substitution of Collection ElementsCollection elements are substitutable in both views and tables. For
example, a nested table of 2.3.13 Newly Created Subtypes Stored in Substitutable ColumnsIf you create a subtype, any table that already has substitutable columns of the supertype can store the new subtype as well. This means that your options for creating subtypes are affected by the existence of such tables. If such a table exists, you can only create subtypes that are substitutable, that is, subtypes that do not violate table limits or constraints. The following example creates a Example 2-27 Creating a Subtype After Creating Substitutable Columns DROP TYPE person_typ FORCE;
DROP TABLE person_obj_table;
DROP TYPE student_typ;
-- perform above drops if objects/tables created
CREATE OR REPLACE TYPE person_typ AS OBJECT (
idno NUMBER,
name VARCHAR2(30),
phone VARCHAR2(20))
NOT FINAL;/
CREATE TABLE person_obj_table (p person_typ);
The following statement fails because CREATE TYPE student_typ UNDER person_typ ( -- incorrect CREATE subtype
advisor person_typ);
/
The next attempt succeeds. This version of the CREATE TYPE student_typ UNDER person_typ ( dept_id NUMBER, major VARCHAR2(30));/ INSERT INTO person_obj_table VALUES (student_typ(51, 'Joe Lane', '1-650-555-0178', 12, 'HISTORY')); 2.3.14 Dropping Subtypes After Creating Substitutable ColumnsWhen you drop a subtype with the
The following statement fails because an instance of DROP TYPE student_typ VALIDATE -- incorrect: an instance still exists ; To drop the type, first delete any of its instances in substitutable columns of the supertype: -- Delete from table and drop student_typ subtype example, not sample schema DELETE FROM person_obj_table WHERE p IS OF (student_typ); DROP TYPE student_typ VALIDATE; 2.3.15 Turning Off Substitutability in a New TableYou can turn off all substitutability on a column or attribute, including embedded attributes and nested collections, while creating a table. Use the clause This turns off all column or attribute substitutability, including embedded attributes and collections nested to any level. In the following example, the clause confines the column Example 2-28 Turning off Substitutability When Creating a Table DROP TYPE location_typ FORCE; -- required if previously created
DROP TYPE office_typ FORCE; -- required if previously created
CREATE OR REPLACE TYPE location_typ AS OBJECT (
building_no NUMBER,
city VARCHAR2(40) );
/
CREATE TYPE people_typ AS TABLE OF person_typ;
/
CREATE TYPE office_typ AS OBJECT (
office_id VARCHAR(10),
location location_typ,
occupant person_typ )
NOT FINAL;/
CREATE TABLE dept_office (
dept_no NUMBER,
office office_typ)
COLUMN office NOT SUBSTITUTABLE AT ALL LEVELS;
With object tables, the clause can be applied to the table as a whole, such as: DROP TABLE office_tab; -- if previously created CREATE TABLE office_tab OF office_typ NOT SUBSTITUTABLE AT ALL LEVELS; The clause can also turn off substitutability in a particular column, that is, for a particular attribute of the object type of the table: DROP TABLE office_tab; -- if previously created CREATE TABLE office_tab OF office_typ COLUMN occupant NOT SUBSTITUTABLE AT ALL LEVELS; You can specify that the element type of a collection is not substitutable using syntax such as the following: DROP TABLE people_tab;
-- required if previously created
CREATE TABLE people_tab (
people_column people_typ )
NESTED TABLE people_column
NOT SUBSTITUTABLE AT ALL LEVELS STORE AS people_column_nt;
There is no mechanism to turn off substitutability for You can use either 2.3.16 Constraining SubstitutabilityYou can impose a constraint that limits the range of subtypes permitted in an object column or attribute to a particular subtype in the declared type's hierarchy. Do this with the The following statement creates a table of Example 2-29 Constraining Substitutability When Creating a Table DROP TABLE office_tab; -- if previously created CREATE TABLE office_tab OF office_typ COLUMN occupant IS OF (ONLY employee_typ); Although the type You can only use the You can use either 2.3.17 Modifying Substitutability on a TableIn an existing table, you can change an object column from Specify the clause [ You can modify substitutability only for a specific column, not for an object table as a whole. The following statement makes the column Example 2-30 Modifying Substitutability in a Table -- Requires Ex. 2-28
ALTER TABLE dept_office
MODIFY COLUMN office SUBSTITUTABLE AT ALL LEVELS;
The following statement makes the column not substitutable. Notice that it also uses the -- Alter table substitutability with FORCE ALTER TABLE dept_office
MODIFY COLUMN office NOT SUBSTITUTABLE AT ALL LEVELS FORCE; --DROP TABLE dept_office; If you do not use the A 2.3.18 Restrictions on Modifying SubstitutabilityYou can change the substitutability of only one column at a time with an To change substitutability for multiple columns, issue multiple statements. In an object table, you can only modify substitutability for a column if substitutability was not explicitly set at the table level, when the table was created. For example, the following attempt to modify substitutability for column address succeeds because substitutability has not been explicitly turned on or off at the table level in the DROP TABLE office_tab; -- if previously created CREATE TABLE office_tab OF office_typ; ALTER TABLE office_tab MODIFY COLUMN occupant NOT SUBSTITUTABLE AT ALL LEVELS FORCE; However, in the following example, substitutability is explicitly set at the table level, so the attempt to modify the setting for column address fails: DROP TABLE office_tab; -- if previously created CREATE TABLE office_tab OF office_typ NOT SUBSTITUTABLE AT ALL LEVELS; /* Following SQL statement generates an error: */ ALTER TABLE office_tab MODIFY COLUMN occupant SUBSTITUTABLE AT ALL LEVELS FORCE -- incorrect ALTER; A column whose substitutability is already constrained by an 2.3.19 Assignments Across Types2.3.19.1 Typical Object to Object AssignmentSubstitutability is the ability of a subtype to stand in for one of its supertypes. Substituting a supertype for a subtype, that is substitution in the other direction, raises an error at compile time. Assigning a source of type
Case 2 illustrates widening. 2.3.19.2 Widening AssignmentWidening is an assignment in which the declared type of the source is more specific than the declared type of the target. An example of widening is assigning an employee instance to a variable of a person type. An employee is a more narrowly defined, specialized kind of person, so you can put an employee in a slot meant for a person if you do not mind ignoring whatever extra specialization makes that person an employee. All employees are persons, so a widening assignment always works. To illustrate widening, suppose that you have the following table:
The following assignments show widening. The assignments are valid unless
The following is a PL/SQL example, which first requires you to create a Example 2-31 PL/SQL Assignment DROP TYPE person_typ FORCE; -- if previously created CREATE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20)) NOT FINAL; / DROP TYPE employee_typ FORCE; -- if previously created CREATE TYPE employee_typ UNDER person_typ ( emp_id NUMBER, mgr VARCHAR2(30)); / -- PL/SQL assignment example DECLARE var1 person_typ; var2 employee_typ; BEGIN var2 := employee_typ(55, 'Jane Smith', '1-650-555-0144', 100, 'Jennifer Nelson'); var1 := var2; END; / 2.3.19.3 Narrowing AssignmentA narrowing assignment is the reverse of widening. A narrowing assignment involves regarding a more general, less specialized type of thing, such as a person, as a more narrowly defined type of thing, such as an employee. Not all persons are employees, so a particular assignment like this works only if the person in question actually happens to be an employee. Thus, in the end, narrowing assignments only work in cases such as Case 1, described in "Typical Object to Object Assignment". To do a narrowing assignment, you must use the For example, the following
The following statement attempts to do a narrowing assignment without explicitly changing the declared type of the source value. The statement will return an error:
2.3.19.4 Collection AssignmentsIn assignments of expressions of a collection type, the source and target must be of the same declared type. Neither widening nor narrowing is permitted in expression assignments of collection
types. However, a subtype value can be assigned to a supertype collection. For example, after creating a new Example 2-32 Create Collection person_set -- Requires 2-21 DROP student_typ; -- if previously created CREATE TYPE student_typ UNDER person_typ ( dept_id NUMBER, major VARCHAR2(30)) NOT FINAL; / CREATE TYPE person_set AS TABLE OF person_typ; / CREATE TYPE student_set AS TABLE OF student_typ; / Expressions of these different collection types cannot be assigned to each other, but a collection element of DECLARE var1 person_set; var2 student_set; elem1 person_typ; elem2 student_typ; BEGIN -- var1 := var2; /* ILLEGAL - collections not of same type */ var1 := person_set (elem1, elem2); /* LEGAL : Element is of subtype */ END; / What is the property by which subtype entities possess the values of all attributes of a supertype?The property by which subtype entities possess the values of all attributes of a supertype is called: attribute inheritance.
What is supertype and subtype in data modeling?A supertype is a generic entity type that has a relationship with one or more subtypes. A subtype is a sub-grouping of the entities in an entity type that is meaningful to the organization and that shares common attributes or relationships distinct from other subgroups. Subtypes inherit all supertype attributes.
What type of relationship is established between a supertype and an subtype?The relationships among subtypes and supertypes are transitive; this means that the relationship between subtype and supertype exists throughout the entire type hierarchy.
Do subtypes inherit relationships?Just as subtypes inherit relationships they also inherit any attributes of their supertype, and we also have that supertypes do not inherit the attributes of their subtypes.
|