Components of an object type - parameter self, PL-SQL Programming

Parameter SELF in pl/sql

The MEMBER methods recognize a built-in parameter named SELF that is an instance of the object type. Whether declared explicitly or implicitly, it is forever the first parameter passed to the MEMBER method. Though, the STATIC methods cannot accept or reference SELF.

In the method body, the SELF represents the object whose method was invoked. For illustration, the method transform declares SELF as an IN OUT parameter:

CREATE TYPE Complex AS OBJECT (

MEMBER FUNCTION transform (SELF IN OUT Complex) ...

You cannot specify a unlike datatype for SELF. In the MEMBER functions, if SELF is not declared, its parameter mode defaults to IN. Though, in the MEMBER procedures, if SELF is not declared then its parameter mode defaults to IN OUT. You can't specify the OUT parameter mode for SELF. As the illustration below shows, the methods can reference the attributes of SELF lacking a qualifier:

CREATE FUNCTION gcd (x INTEGER, y INTEGER) RETURN INTEGER AS

-- find maximum common divisor of x and y

ans INTEGER;

BEGIN

IF (y <= x) AND (x MOD y = 0) THEN ans := y;

ELSIF x < y THEN ans := gcd(y, x);

ELSE ans := gcd(y, x MOD y);

END IF;

RETURN ans;

END;

CREATE TYPE Rational AS OBJECT (

num INTEGER,

den INTEGER,

MEMBER PROCEDURE normalize,

...

);

CREATE TYPE BODY Rational AS

MEMBER PROCEDURE normalize IS

g INTEGER;

BEGIN

g := gcd(SELF.num, SELF.den);

g := gcd(num, den); -- equivalent to previous statement

num := num / g;

den := den / g;

END normalize;

...

END;

From the SQL statement, if you call a MEMBER method on a null instance, the method is not invoked and a null is returned. From the procedural statement, when you call the  MEMBER method on a null instance, the PL/SQL raises the predefined exception SELF_IS_NULL before the method is invoked.

Posted Date: 10/6/2012 8:07:01 AM | Location : United States







Related Discussions:- Components of an object type - parameter self, Assignment Help, Ask Question on Components of an object type - parameter self, Get Answer, Expert's Help, Components of an object type - parameter self Discussions

Write discussion on Components of an object type - parameter self
Your posts are moderated
Related Questions
Example of EXCEPT Operator - SQL Example, like its counterpart in the theory book, illustrates the convenience of allowing any table expression to be the source for an INSERT

At times, Brewbean's has changed the id number for existing products. In the past, they have had to add a new product row with the new id to the BB_PRODUCT table, modify all the co

Find the account numbers of all customers whose balance is more than 10,000 $

Organi c Evolution Evolution is a slow continuous, irreversible and natural process of change to give rise to advance and diverse forms of life i.e. formation of new specie

What is Cursors how to use it in Real time application ?

Lightweight system to provide and take info from workers in the field and office, have basic design outlined already just require build and implementation Desired Skills CSS,

heap sort program in pl/sql

Need Windows and Linux system Administrator We are seeking a part time system administrator to take care of our servers. Your things to do would add, but not limited to: -

PL SQL Code Review HEADER ELEMENTS File Name Clear, meaningful and descriptive about main objective of the file. Multiple words are joined using underscores which adh

If two relations R and S are joined, then the non matching tuples of both R and S are ignored in __________________.