Calling constructors in pl sql, PL-SQL Programming

Calling Constructors:

The Calls to a constructor are allowed wherever the function calls are allowed. Similarly to the functions, a constructor is called as a section of an expression, as the illustration below is a shown:

DECLARE

r1 Rational := Rational(2, 3);

FUNCTION average (x Rational, y Rational) RETURN Rational IS

BEGIN

...

END;

BEGIN

r1 := average(Rational(3, 4), Rational(7, 11));

IF (Rational(5, 8) > r1) THEN

...

END IF;

END;

Whenever you pass a parameter to a constructor, the call assigns its initial value to the attributes of the object being instantiated. You should supply a parameter for every attribute as, dissimilar constants and variables, the attributes cannot have the default values. As the illustration shown below, the nth parameter assigns a value to the nth attribute:

DECLARE

r Rational;

BEGIN

r := Rational(5, 6); -- assign 5 to num, and 6 to den

-- now r is 5/6

The later illustration shows that you can call a constructor using the named notation rather than that of the positional notation:

BEGIN

r := Rational(den => 6, num => 5); -- assign 5 to num, and 6 to den

Posted Date: 10/6/2012 8:15:20 AM | Location : United States







Related Discussions:- Calling constructors in pl sql, Assignment Help, Ask Question on Calling constructors in pl sql, Get Answer, Expert's Help, Calling constructors in pl sql Discussions

Write discussion on Calling constructors in pl sql
Your posts are moderated
Related Questions
What Is a Package? The package is a schema object that group logically related PL/SQL items, types, and subprograms. The Packages usually have 2 parts, a specification & a bo

Explicit Cursors The set of rows returned by the query can include zero, one, or multiple rows, depending on how many rows meet your search criteria. Whenever a query returns

Deriving Predicates from Predicates in SQL The corresponding section in the theory book describes how predicates can be derived from predicates using (a) the logical connectiv

Project Description: I want a database for large governmental and private data sets on one country that will be easily extended to other countries in the future. Also, the datab

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,

Wrapping and unwrapping in SQL Operators WRAP and UNWRAP in connection with attributes whose declared types are tuple types. Example shows how extension and projection can be

Project Description: This is stage 1 of a larger conversion project. We are converting a traditional Server/Client application written in Access 2007 into a web interface with S

Committing and Rolling Back The COMMIT and ROLLBACK end the active autonomous transaction but do not exit the autonomous routine. As the figure shows, if one transaction ends,

Functions   The function is a subprogram that calculates a value. The Functions and procedures are structured similar, except that the functions have a RETURN clause. You can

Closing a Cursor The CLOSE statements disable the cursor, and the result set becomes undefined. An illustration of the CLOSE statement as shown: CLOSE c1;