Pl/sql -Member function

Dear Expert,
  I can't understand what is member function in below example and
the body return self -
Why we need to use member function here.

Please explain to me .Thanks & regards



 CREATE TYPE object_type AS OBJECT
  2  ( x INT
  3  , y DATE
  4  , z VARCHAR2(1)
  5  , MEMBER FUNCTION print RETURN VARCHAR2
  6  );
  7  /

Type created.

SQL> CREATE TYPE BODY object_type AS
  2     MEMBER FUNCTION print RETURN VARCHAR2 IS
  3     BEGIN
  4        RETURN TO_CHAR(SELF.x)            || ',' ||
  5               TO_CHAR(SELF.y,'YYYYMMDD') || ',' ||
  6               z;
  7     END;
  8  END;
  9  /

daprjoAsked:
Who is Participating?
 
slightwv (䄆 Netminder) Commented:
I'll defer you to the docs since they can explain it better than we can:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i477669

If you have a specific question about the code you posted we can try to answer that:

the print member returns a comma separated list for the three objects in the type.  It converts 'x' to a character then converts the 'Y' date to a formated character string and tacks on 'Z', all concatenated together with a ','.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Why we need to use member function here.
you ask a question we cannot answer here

the member function will allow to centralize code related to the type into the type itself.

SELF refers to the object_type instance itself, so when you create a variable of that type, you can use

yourvariable.print  

to get some of the variable's member data to be returned in the given format.

hope this explains
0
 
daprjoAuthor Commented:
Dear Expert,

       U no need to answer the above question.
       Can u please explain to me member procedure and member function in object type
      with simple  examples.
     Thanks & regards
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I don't know how the example could be simplified ...
the type has 3 members, x,y and z.

to function returns the values of those 3, with a "," in between the 3 values, and ensureing the date is formatted YYYYMMDD

0
 
daprjoAuthor Commented:
Dear Expert,
How we can effectively use this object in pl/sql procedures
0
 
slightwv (䄆 Netminder) Commented:
>>How we can effectively use this object in pl/sql procedures

That depends on your requirements.  From the code you posted, at some time someone found it necessary to create a comma separated list for those three objects.

You would use it in PL/SQL when you needed the list in that format.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.