Вам нужно будет объявить КОНСТРУКТОР для вашего типа.Затем вы можете поместить в тело любую понравившуюся вам проверку.
CREATE TYPE Rational AS OBJECT (
num INTEGER,
den INTEGER,
MAP MEMBER FUNCTION convert RETURN REAL,
MEMBER PROCEDURE normalize,
MEMBER FUNCTION reciprocal RETURN Rational,
MEMBER FUNCTION plus (x Rational) RETURN Rational,
MEMBER FUNCTION less (x Rational) RETURN Rational,
MEMBER FUNCTION times (x Rational) RETURN Rational,
MEMBER FUNCTION divby (x Rational) RETURN Rational,
constructor function rational
(n integer, d integer)
return self as result,
PRAGMA RESTRICT_REFERENCES (DEFAULT, RNDS,WNDS,RNPS,WNPS)
);
В тело вашего типа добавьте код конструктора:
constructor function rational
(n integer, d integer)
return self as result
is
begin
if d = 0 then
raise_application_error(-20000, 'Denominator cannot be zero!');
end if;
self.num := n;
self.den := d;
end rational;