Méthodes de table d'objets

Méthodes de table

Si le type sur lequel s'appuie la création de la table définit des méthodes, alors les méthodes seront associées à la table (méthodes de table).

Il sera possible d'accéder à ces méthodes de la même façon que l'on accède aux attributs (projection, sélection...).

Accès aux méthodes d'une table d'objets

SELECT t.m1(), t.m2() ...
FROM table t
...

L'utilisation d'un alias est obligatoire pour accéder aux méthodes.

Déclaration de type avec méthodes

CREATE TYPE nom_type AS OBJECT (
 nom_attribut1 type_attribut1
 ...
 MEMBER FUNCTION nom_fonction1 (parametre1 IN|OUT type_parametre1, ...) RETURN type_fonction1
 ...
);
/
CREATE TYPE BODY nom_type
 IS 
 MEMBER FUNCTION nom_fonction1 (...) RETURN type_fonction1
  IS
  BEGIN
  ...
  END ;
 MEMBER FUNCTION nom_fonction2 ...
  ...
 END ;
END ;
/
CREATE TYPE typCours AS OBJECT (
  pknum NUMBER(2),
  debut DATE,
  MEMBER FUNCTION fin RETURN DATE
);
/
CREATE TYPE BODY typCours IS
MEMBER FUNCTION fin RETURN DATE
  IS
  BEGIN
    RETURN SELF.debut + 5;
  END;
END;
/
CREATE TABLE tCours OF typCours (
pknum PRIMARY KEY
);
SELECT c.pknum, c.fin()
FROM tCours c;

Type retourné par une méthode

« The datatype cannot specify a length, precision, or scale. »

http://docs.oracle.com/cd/B13789_01/server.101/b10759/statements_5009.htm

AccueilCours > Compléments > Méthodes > Méthodes de table d'objets< PrécédentSuivant >