Oracle Database
What is Object in Oracle?
= This concept is almost analogue to Java Object. Oracle object types are user-defined types that make it possible to model real-world entities such as customers and purchase orders as objects in the database.When you create a variable of an object type, you create an instance of the type and the result is an object. An object has the attributes and methods defined for its type. Because an object instance is a concrete thing, you can assign values to its attributes and call its methods.Defining an object type does not allocate any storage. Let us see example to learn how to create and use Object in Oracle.
First, define an Object Type, i.e data type:
Example:
CREATE TYPE person_typ AS OBJECT ( idno NUMBER, first_name VARCHAR2(20), last_name VARCHAR2(25), email VARCHAR2(25), phone VARCHAR2(20), MAP MEMBER FUNCTION get_idno RETURN NUMBER, CREATE TYPE BODY person_typ AS MAP MEMBER FUNCTION get_idno RETURN NUMBER IS BEGIN RETURN idno; END; END;
Using the above crated Object Type:
CREATE TABLE contacts ( contact person_typ, contact_date DATE ); INSERT INTO contacts VALUES ( person_typ (65, 'Verna', 'Mills', 'vmills@oracle.com', '1-800-555-4412'), '24 Jun 2003' );
What is Package in Oracle ?
=Packages provide a method of encapsulating related procedures, functions, and associated cursors and variables together as a unit in the database.
CREATE PACKAGE bank_transactions AS
minimum_balance CONSTANT NUMBER := 100.00;
PROCEDURE apply_transactions;
PROCEDURE enter_transaction (acct NUMBER, kind CHAR, amount NUMBER);
END bank_transactions;
CREATE PACKAGE BODY bank_transactions AS
new_status CHAR(20); /* a Global variable */ It works like a global variable in JavaScript whose value can be set from any methods .
PROCEDURE do_journal_entry (acct NUMBER, kind CHAR) IS
BEGIN
.........do some tasks,,,,,,,,,,,,,,
new_status := set somevalue
END do_journal_entry;
END do_journal_entry;
PROCEDURE credit_account (acct NUMBER, credit NUMBER) IS
BEGIN
.........do some tasks,,,,,,,,,,,,,,
new_status := again set somevalue
END
END credit_account;
END bank_transactions
Comments