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
Updating by insertion Syntax : INSERT INTO ENROLMENT VALUES (SID ('S4'), 'Devinder', CID ('C1'));

Effects of NULL for Table Expression Here's an important distinction between expressions denoting tables and expressions denoting multisets of rows: a table expression cannot

Some Varray Examples In SQL Plus, assume that you define an object type Project, as described below: SQL> CREATE TYPE Project AS OBJECT ( 2 project_no NUMBER(2), 3 title VARCHA

LOOP Statements The LOOP statements execute a series of statements at multiple times. The loops enclose the series of statements that is to be repeated. The PL/SQL provides typ

Mutual Recursion The Subprograms are mutually recursive if they directly or indirectly call each other. In the illustration below, the Boolean functions odd & even, that dete

THEO R Y OF ETERNITY OF LIFE (PRAYER - 1880) - The theory of eternity of life, also called the steady-state theory , states that life has ever been in existence as at presen

Renaming Columns - SQL SQL has no direct counterpart of RENAME. To derive the table on the right in Figure 4.4 from the table on the left, Tutorial D has IS_CALLED RENAME ( St

(a) What are decision support systems, and what role do they play in the business environment? (b) Data warehousing is defined as "a subject-oriented, integrated, non-volatile c

Example of Using Aggregation on Nested Tables Example: How many students sat each exam WITH C_ER AS (SELECT CourseId, CAST (TABLE (SELECT DISTINCT StudentId, Mark FROM EXAM

Using NOT NULL Besides assigning an initial value, the declarations can impose the NOT NULL constraint, as the example below shows: acct_id INTEGER(4) NOT NULL := 9999; You ca