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
Using Operator DEREF: You cannot navigate through refs within the PL/SQL procedural statements. Rather than, you should use the operator DEREF in the SQL statement. The DEREF

Using Aggregation on Nested Tables Example is the most direct translation of its counterpart in the theory book that can be obtained in SQL but it is so over-elaborate that no

Remote Operations: As the illustration shows below, the PL/SQL subprograms can execute the dynamic SQL statements which refer to the objects on a remote database: PROCEDURE

The SQL ‘CREATE TABLE' scripts for all the tables you have implemented. Note that your tables must correspond exactly to the ERD you have provided in 1. above, or you will lose ma

Collection Methods:   The collection method is a built-in function or procedure which operates on the collections and is called using the dot notation. The methods like the C

Biconditional - SQL The biconditional p ↔ q can be expressed in Tutorial D by p = q and the same is true of SQL. The question then arises as to whether, in SQL, p = q is equiv

Example of GROUP BY and COLLECT Operator Example: Using GROUP BY and COLLECT to obtain C_ER2 SELECT CourseId, CAST ( COLLECT (ROW (StudentId, Mark)) AS ROW (Studen

Declaring Exceptions The Exceptions can be declared only in the declarative part of the PL/SQL subprogram, block, or package. By introducing its name, you can declare an excep

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

Need for Dynamic SQL: You need dynamic SQL in the situations as follows: 1) You would like to execute a SQL data definition statement (like CREATE), a data control statemen