Type Compatibility With the NUMBER Datatype
An unconstrained subtype is interchangeable with its base type. For example, given the following declarations, the value of amount can be assigned to total without conversion:
Different subtypes are interchangeable if they have the same base type:
Different subtypes are also interchangeable if their base types are in the same datatype family. For example, given the following declarations, the value of verb can be assigned to sentence:
DECLARE
SUBTYPE accumulator IS NUMBER;
amount NUMBER(7,2);
total ACCUMULATOR;
BEGIN
amount := 10000.50;
total := amount;
END;
/
Different subtypes are interchangeable if they have the same base type:
DECLARE
SUBTYPE b1 IS BOOLEAN;
SUBTYPE b2 IS BOOLEAN;
finished B1; -- Different subtypes,
debugging B2; -- both based on BOOLEAN.
BEGIN
finished := false;
debugging := finished; -- They can be assigned to each other.
END;
/
Different subtypes are also interchangeable if their base types are in the same datatype family. For example, given the following declarations, the value of verb can be assigned to sentence:
DECLARE
SUBTYPE Word IS CHAR(15);
SUBTYPE Text IS VARCHAR2(1500);
verb Word; -- Different subtypes
sentence Text(150); -- of types from the same family
BEGIN
verb := 'program';
sentence := verb; -- can be assigned, if not too long.
END;
/
0 comments:
Post a Comment