Friday 5 June 2015

Objects in PL/SQL-Part1

        Oracle object types are user-defined types that make it possible to model the real world entities, such as employees, customers and Customer Order details as objects in the database.

     New Object types can be created using any built-in datatypes, Composite data types, collections or existing object types.

    Object Type model is same as classes in any other languages such as C++, Java.

Advantages of Objects:
1) Objects can encapsulate the operations along with data:
     Any database table contains only the data but objects can have both data and  methods/functions.
2) Objects are efficient:
    As the objects consists both data and operations and metadata is stored in the database, Developers can re-use these objects as it is. It provides the re-usability option.
3) Objects can re-presents Part-Whole relationships.
    Object types allow you to represent part-whole relationships. Any object can have another object as attribute.

Object Types:
    Object types are database schema objects which defines both structure and behavior. You can use object types as normal datatypes like NUMBER, VARCHAR2.

Structure of an Object Type:
An object type has 2 parts:
1) Specification : Specification declares a data structure i.e. set of attributes and Operations called methods needed to manipulate the data .

2) Body: The body part defines the methods declared in the specification i.e. body implements the specification.

General Syntax:
1) Specification:


2) Body:


No comments: