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
Parameter and Keyword Description: cursor_variable_name: This identifies a cursor variable or the parameter formerly declared within the present scope. host_cursor_va

ROWID The ROWID returns the rowid (binary address) of a row in the database table. You can use the variables of the type UROWID to store rowids in a readable format. In the il

Indeterminacy in SQL Some SQL expressions are actually not function invocations at all in the mathematical sense, being indeterminate-invocations operating on identical input

SQL Pseudocolumns The PL/SQL recognizes the following SQL pseudocolumns, that returns the specific data items: LEVEL, NEXTVAL, CURRVAL, ROWID, & ROWNUM. The Pseudocolumns are n

Using ROLLBACK The ROLLBACK statements end the present transaction and undo any change made during the transaction. The Rolling back is helpful for two reasons. Firstly, if yo

Using SET TRANSACTION You use the SET TRANSACTION statement to begin the read-only or read-write transaction, start an isolation level, or assign your present transaction to a

Consider the following set of database tables (same tables from Assignment 6-1). Please take note of foreign keys (most of them carry the same names as the corresponding primary ke

Problem: (a) Define the following terms: (i) data mining. (ii) OLAP. (b) Differentiate between snowflake schema and star schema. Support your answer with appropriate

1. Create a procedure called TAX_COST_SP to accomplish the tax calculation task. Keep in mind that the state and subtotal values are inputs into the procedure and the procedure is

Parameter and Keyword Description: package_name: This construct identifies the package. AUTHID Clause: This determine whether all the packaged subprograms impleme