Structure of an object type in pl/sql, PL-SQL Programming

Assignment Help:

Structure of an Object Type:

Similar to package, an object type has 2 parts: the specification and the body. The specification is the interface to your applications; it declares a data structure (that is, a set of attributes) along with the operations required to operate the data. The body fully explains the methods, and therefore implements the specification.

1290_Structure of an Object Type.png

Figure: Object Type Structure

All the information a client program require to use the methods is in the specification. Imagine of the specification as an operational interface and of the body as the black box. You can debug, replace, or enhance the body without changing the enhance -and without affecting the client programs.

In an object type specification, all the attributes should be declared before any methods. The subprograms only have a fundamental implementation. As a result, if an object type specification declares only the attributes, the object type body is needless. You cannot declare attributes into the body. All the declaration in the object type specification is public.

To recognize the structure enhanced study the illustration below, in which an object type for the complex numbers is explained. For now, it is adequate to know that the complex number has two sections, a real part & an imaginary part, and that quite a few arithmetic operations are defined for complex numbers.

CREATE TYPE Complex AS OBJECT (

rpart REAL, -- attribute

ipart REAL,

MEMBER FUNCTION plus (x Complex) RETURN Complex, -- method

MEMBER FUNCTION less (x Complex) RETURN Complex,

MEMBER FUNCTION times (x Complex) RETURN Complex,

MEMBER FUNCTION divby (x Complex) RETURN Complex

);

CREATE TYPE BODY Complex AS

MEMBER FUNCTION plus (x Complex) RETURN Complex IS

BEGIN

RETURN Complex(rpart + x.rpart, ipart + x.ipart);

END plus;

MEMBER FUNCTION less (x Complex) RETURN Complex IS

BEGIN

RETURN Complex(rpart - x.rpart, ipart - x.ipart);

END less;

MEMBER FUNCTION times (x Complex) RETURN Complex IS

BEGIN

RETURN Complex(rpart * x.rpart - ipart * x.ipart,

rpart * x.ipart + ipart * x.rpart);

END times;

MEMBER FUNCTION divby (x Complex) RETURN Complex IS

z REAL := x.rpart**2 + x.ipart**2;

BEGIN

RETURN Complex((rpart * x.rpart + ipart * x.ipart) / z,

(ipart * x.rpart - rpart * x.ipart) / z);

END divby;

END;


Related Discussions:- Structure of an object type in pl/sql

Updating by replacement, Updating by replacement Syntax: UPDAT...

Updating by replacement Syntax: UPDATE ENROLMENT SET Name = 'Ann' WHERE StudentId = SID ('S1'); Note the use of SET, as already noted in connection with direct a

Manipulating local collections - pl/sql, Manipulating Local Collections ...

Manipulating Local Collections Within PL/SQL, to manipulate the local collection, by using the  TABLE and CAST operators . The operands of CAST are a collection declared locally

Mutual recursion, Mutual Recursion The Subprograms are mutually recursi...

Mutual Recursion The Subprograms are mutually recursive if they directly or indirectly call each other. In the illustration below, the Boolean functions odd & even, that dete

Constants and variables in pl sql, Constants and Variables:   You can...

Constants and Variables:   You can declare the constants and variables in the declarative section of any PL/SQL subprogram, block, or package. The Declarations allot the stor

Query optimization, 1.( /5 marks) Suppose that a B+-tree index with the sea...

1.( /5 marks) Suppose that a B+-tree index with the search key (dept_name, building) is available on relation department. What would be the best way to handle the following selecti

Relational operators-comparison operators, Relational Operators The rela...

Relational Operators The relational operators permit you to compare randomly complex expressions. The list below provides the meaning of each operator:

Close statement in pl sql, CLOSE Statement The CLOSE statement allows ...

CLOSE Statement The CLOSE statement allows the resources held by a cursor variable or open cursor to be reused. No more rows can be fetched from the cursor variable or closed

Parameter default values, Parameter Default Values As the illustration ...

Parameter Default Values As the illustration below shows, you can initialize the IN parameters to the default values. In that way, you can pass various numbers of actual par

Conditionals - sql, Conditionals - SQL At first sight SQL does not app...

Conditionals - SQL At first sight SQL does not appear to have a single operator for expressing logical implication. In this respect it would be in common with most programming

Develop data business intelligence project, Develop Data Business Intellige...

Develop Data Business Intelligence Project Project Description: We are linking our Microsoft SQL Database to GoodData Business Intelligence. We are seeking somebody who has e

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