Calling constructors in pl sql, PL-SQL Programming

Assignment Help:

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


Related Discussions:- Calling constructors in pl sql

Creating and destroying base tables, Creating and Destroying Base Tables: ...

Creating and Destroying Base Tables: Example shows an SQL command to create the base table counterpart of the ENROLMENT variable Example  Creating a base table. CREATE T

Out mode - parameter modes, OUT Mode An OUT parameter returns values t...

OUT Mode An OUT parameter returns values to the caller of a subprogram. Within the subprogram, an OUT parameter act like a variable. That means that you can use an OUT formal

Blocks, Blocks: The fundamental program unit in the PL/SQL is the bloc...

Blocks: The fundamental program unit in the PL/SQL is the block. The PL/SQL block is defined by the keywords BEGIN, DECLARE, EXCEPTION, and END. These keywords partition the b

Check constraints in sql, CHECK Constraints in SQL A CHECK constraint ...

CHECK Constraints in SQL A CHECK constraint is a table constraint defined using the key word CHECK, as already illustrated in several examples in this chapter. In particular,

Perform exception handling with user-defined errors, On occasion, some of B...

On occasion, some of Brewbean's customers mistakenly leave an item out of a basket already checked out, so they create a new basket containing the missing items. However, they requ

Manipulating collections-nested table examples, Manipulating Collections ...

Manipulating Collections Within PL/SQL, the collections add procedural power and flexibility. The biggest benefit is that your program can compute subscripts to process the spec

Mechanistis theory-haeckel - origin of life, MECHANISTI S THEORY-HAECKEL (...

MECHANISTI S THEORY-HAECKEL (1866) - Haeckel stating that after each catalysm, some new organism suddenly forms as a chance event in one stride from inanimate matter and sub

Use the nocopy compiler hint - performance of application, Use the NOCOPY C...

Use the NOCOPY Compiler Hint By default, the OUT and IN OUT parameters are passed by the value i.e. the value of an IN OUT actual parameter is copied into the corresponding fo

Declaring a cursor, Declaring a Cursor The Forward references are not ...

Declaring a Cursor The Forward references are not allowed in the PL/SQL. Therefore, you must declare a cursor before referencing it in other statements. Whenever you declare a

How pl/sql resolves the calls? , How Calls Are Resolved? The figure sho...

How Calls Are Resolved? The figure shows that how the PL/SQL compiler resolves the subprogram calls. When the compiler encounters the procedure or function call, it tries to di

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd