Method Example II (Cont.)

SQL> CREATE TYPE  rectangle_typ  AS OBJECT (
  2    pt1  point_t,
  3    pt2  point_t,
  4    MEMBER FUNCTION  resize( p point_t )  RETURN  rectangle_typ );
  5  /

Type created.

SQL> CREATE TYPE BODY  rectangle_typ  AS
  2    MEMBER FUNCTION  resize( p point_t )  RETURN  rectangle_typ  IS
  3      newrect  rectangle_typ := self;
  4    BEGIN
  5      IF  p.x > self.pt1.x  AND  p.y > self.pt1.y  THEN
  6        newrect.pt2 := p;
  7      END IF;
  8      RETURN  newrect;
  9    END;
 10  END;

Type body created.

SQL> CREATE TABLE  rects1  OF  rectangle_typ (
  2    PRIMARY KEY( pt1.x, pt1.y, pt2.x, pt2.y ) );

Table created.

SQL> INSERT INTO  rects1  VALUES( point_t(1, 2), point_t(3, 4) );

1 row created.

SQL> INSERT INTO  rects1  VALUES( point_t(1, 1), point_t(6, 6) );

1 row created.


SQL> SELECT  r.resize( point_t(10, 10) )  FROM  rects1 r;

R.RESIZE(POINT_T(10,10))(PT1(X, Y), PT2(X, Y))
-----------------------------------------------------------
RECTANGLE_TYP(POINT_T(1, 2), POINT_T(10, 10))
RECTANGLE_TYP(POINT_T(1, 1), POINT_T(10, 10))


SQL> UPDATE  rects1 r
  2    SET  r = r.resize( point_t(r.pt2.x+1, r.pt2.y+1) )
  3    WHERE  r.pt1 = point_t(1, 2);

1 rows updated.




      “You yourself, as much as anybody in the entire universe,    
      deserve your love and affection.”    
      ― Sharon Salzberg