Search code examples
oracleplsqlmember-functionsnested-table

How to use self defined types with nested tables in PL/SQL member functions?


I am defining a MEMBER FUNCTION for this type:

CREATE OR REPLACE TYPE HITO_T (

    nombre         VARCHAR2 (20) ,
    categoria      VARCHAR2 (20) , 
    estado         VARCHAR2 (10) ,
    costo_entrada  NUMBER (10,0),
    zonas          ZONA_TABLE_T,
   MEMBER FUNCTION listar_zonas RETURN ZONA_T

); /

The type has an attribute for a nested table and the function must return all the values for that nested table, so what I have is:

CREATE OR REPLACE TYPE BODY HITO_T as

   MEMBER FUNCTION listar_zonas RETURN VARCHAR2 is
   BEGIN
      return self.zonas
   END listar_zonas;

END; /

The definitions for ZONA_T and ZONA_TABLE_T are:

CREATE OR REPLACE TYPE ZONA_T UNDER LUGAR_TIPO (

    nombre         VARCHAR2(20),
    tamano         NUMBER,
    poligonos      POLIGONO_TABLE,
   MEMBER FUNCTION listar_poligonos RETURN POLIGONO_T);

/

CREATE OR REPLACE TYPE ZONA_TABLE_T AS TABLE OF ZONA_T; /

I can't seem to start trying stuff since I don't know how to call the function. My specific question is how to call the function to test it with actual objects on the database, instead of using one defined at the moment (that is, CALL HITO_T('a','b','c'...)... will not work because the function needs values from the zonas attribute, which is a nested table and it can't be defined at the moment just like that). Futhermore I am not sure I can just return «self.zonas» just like that.

Any ideas?


Solution

  • The VALUE statement was what I was looking for.