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

Using set transaction, Using SET TRANSACTION You use the SET TRANSACTI...

Using SET TRANSACTION You use the SET TRANSACTION statement to begin the read-only or read-write transaction, start an isolation level, or assign your present transaction to a

Data types in sql - integer, Data Types in SQL - Integer INTEGER or  s...

Data Types in SQL - Integer INTEGER or  synonymously INT, for integers within a certain range. SQL additionally has types SMALLINT and BIGINT for certain ranges of integers. T

Components of an object type in pl/sql, Components of an Object Type: A...

Components of an Object Type: An object type encapsulates the operations and data. Therefore, you can declare the methods and attributes in an object type specification, but no

Scope and visibility- pl/sql, Scope and Visibility The References to an ...

Scope and Visibility The References to an identifier are resolved according to its visibility and scope. The scope of an identifier is that area of a program unit (subprogram, b

Calculating a Shopper''s Total Spending, Many of the reports generated from...

Many of the reports generated from the system calculate the total dollars in a shopper''s purchases. Follow these steps to create a function named TOT_PURCH_SF that accepts a shopp

Boolean values-assignments in pl/sql, Boolean Values Only the values TRU...

Boolean Values Only the values TRUE, FALSE, & NULL can be assigned to a Boolean variable. For illustration, given the declaration DECLARE done BOOLEAN; the following statements

Execute your documentation in oracle, Using research notes and Oracle docum...

Using research notes and Oracle documentation plan and execute an upgrade of an installation of Oracle 10g to Oracle 11g release 1. To do this you must show in screen shots and wri

Transaction context, Transaction context As the figure shows, the majo...

Transaction context As the figure shows, the major transaction shares its context with the nested transactions, but not with the autonomous transactions. Similarly, If one aut

Join query, Using a join on 3 tables, select 5 columns and 10 rows from the...

Using a join on 3 tables, select 5 columns and 10 rows from the 3 tables without the use of a Cartesian product Query: SELECT E.LAST_NAME, E.FIRST_NAME, S.BUILDING, S.BRAN

Sql database, SQL Database: So, an SQL database is one whose symbols a...

SQL Database: So, an SQL database is one whose symbols are organized into a collection of tables. Now, shows an SQL table as the current value of an SQL variable, ENROLMENT, b

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