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 Foreign Key Constraint Example: Alternative formulation for 6.3 as a foreign key constraint ALTER TABLE EXAM_MARK ADD CONSTRAINT Must_be_enrolled_to_take_exam

At times, customers make mistakes in submitting their orders and call to cancel the order. Brewbean’s wants to create a trigger that automatically updates the stock level of all pr

SELECT a.child_fname,a.child_lname,concat(b.parent_title,b.parent_fname), b.parent_lname,b.parent_tphone FROM child a,parent b WHERE a.parent_id=b.parent_id ORDER BY a.child_fnam

Understanding Nested Tables Within the database, the nested tables can be considered as one-column database tables. The Oracle stores the rows of a nested table in no specific o

Write a pl/sql block that declares and uses cursors with parameters. In a loop, use a cursor to retrieve the department number and the department name from the departments table

Write a program to implement the inverted file shown in the slides (Simple Index file, LabelID file and Data file).  Use the Avail_List to point at the deleted Label IDs so that th

LIKE Operator You use the LIKE operator to compare the character value to a pattern. The Case is significant. LIKE returns the Boolean value TRUE when the character patterns mat

Running the PL/SQL Wrapper To run the PL/SQL Wrapper, go through the wrap command at your operating system prompt by using the syntax as shown: wrap iname=input_file [oname=

Equivalences & Rewrite Rules: If notice that as well as allowing us to prove trivial theorems, and tautologies enable us to establish that certain sentences are saying the sam

Perform the following queries on the Hospital1.DB using SQL Anywhere (START EARLY!). a. Which patients have purchased the drug "Tylenol"? List the names and addresses. Arrange the