CREATE OR REPLACE TYPE BODY Organization_Type IS

MEMBER FUNCTION isMember (the_country IN VARCHAR2)
  RETURN VARCHAR2
IS
BEGIN
   IF SELF.Members IS NULL OR SELF.Members.COUNT = 0
   THEN RETURN 'no'; END IF;
   FOR i in  1 .. Members.COUNT
   LOOP
      IF the_country = Members(i).country
       THEN RETURN Members(i).type; END IF;
   END LOOP;
   RETURN 'no';
END;

MEMBER FUNCTION people RETURN NUMBER IS
p NUMBER;
BEGIN
   SELECT SUM(population) INTO p
   FROM Country ctry
   WHERE ctry.Code IN
 ( SELECT Country
      FROM THE (SELECT Members
          FROM Organization_ObjTab org
          WHERE org.Abbrev = SELF.Abbrev));
   RETURN p;
END;

MEMBER FUNCTION numberOfMembers RETURN NUMBER
IS
BEGIN
   IF SELF.Members IS NULL THEN RETURN 0; END IF;
   RETURN Members.COUNT;
END;

MEMBER PROCEDURE addMember
     (the_country IN VARCHAR2, the_type IN VARCHAR2) IS
BEGIN
  IF NOT SELF.isMember(the_country) = 'no'
   THEN RETURN; END IF;
   IF SELF.Members IS NULL THEN
   UPDATE Organization_ObjTab
   SET Members = Member_List_Type()
   WHERE Abbrev = SELF.Abbrev;
  END IF;
   INSERT INTO
   THE (SELECT Members
               FROM Organization_ObjTab org
               WHERE org.Abbrev = SELF.Abbrev)
   VALUES (the_country, the_type);
END;
END;
/
