SQL> CREATE TYPE point_t AS OBJECT (
2 x INT,
3 y INT );
4 /
Type created.
SQL> CREATE TYPE rectangle_t AS OBJECT (
2 pt1 point_t,
3 pt2 point_t,
4 MEMBER FUNCTION inside(p point_t) RETURN INT,
5 MEMBER FUNCTION area RETURN INT);
6 /
Type created.
SQL> CREATE TYPE BODY rectangle_t AS
2 MEMBER FUNCTION area RETURN INT IS
3 BEGIN
4 RETURN (self.pt2.x - self.pt1.x) * (self.pt2.y - self.pt1.y);
5 END;
6
7 MEMBER FUNCTION inside(p in point_t) RETURN INT IS
8 BEGIN
9 IF (p.x >= self.pt1.x) AND (p.x <= self.pt2.x) AND
10 (p.y >= self.pt1.y) AND (p.y <= self.pt2.y) THEN
11 RETURN 1;
12 ELSE
13 RETURN 0;
14 END IF;
15 END;
16 END;
17 /
Type body created.
|