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

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;

Posted Date: 10/6/2012 7:59:44 AM | Location : United States







Related Discussions:- Structure of an object type in pl/sql, Assignment Help, Ask Question on Structure of an object type in pl/sql, Get Answer, Expert's Help, Structure of an object type in pl/sql Discussions

Write discussion on Structure of an object type in pl/sql
Your posts are moderated
Related Questions
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

Organi c Evolution Evolution is a slow continuous, irreversible and natural process of change to give rise to advance and diverse forms of life i.e. formation of new specie

Advantages of Invoker Rights The Invoker-rights routines centralize the data retrieval. They are particularly helpful in applications which store data in various schemas. In su

Using the FORALL Statement The keyword FORALL instruct the PL/SQL engine to bulk-bind input collections before sending them all to the SQL engine. Though the FORALL statement

Use the RETURNING Clause Frequently, the application requires information about the row affected by a SQL operation, for illustration, to produce a report or take a subsequent

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

Keys in SQL SQL support for keys in the following respects: SQL does not require at least one key for every base table. If no key is explicitly declared, then KEY {ALL B

Using FORALL and BULK COLLECT Together You can unite the BULK COLLECT clause with the FORALL statement, in that case, the SQL engine bulk-binds column values incrementally. In

Enrolment was split - SQL Example shows how relvars IS_CALLED and IS_ENROLLED_ON can be derived from the original ENROLMENT relvar, using projection in the initial assignment

SQL Functions The PL/SQL uses all the SQL functions involving the following aggregate functions that summarize the whole columns of the Oracle data: GROUPING, AVG, COUNT, STDDE