Re: Object oriented oracle ?

From: Ken Johnson <ken.johnson_at_mail.tapestry.com>
Date: 1996/05/31
Message-ID: <31AFC77C.3033_at_mail.tapestry.com>#1/1


95donakanti_at_wmich.edu wrote:
>
> hi,
>
> I am just learning oracle 7.1.
> I'm supposed to do a Object oriented database in Oracle...
>
> I have been reading oracle for quite some time, and i found that tables,views
> etc.. are stored as objects in oracle..
>
> but i was not able to understand what a object oriented database in
> oracle would be...
> if i use tables,views etc does it mean the database is object
> oriented ?
>
> or, does oracle support any other object oriented tools ?
> if it supports , what are they and how do i implement it ....
>
> any help is appreciated...
>
> thankx in advance
>
> RamOracle7 is a relational database not an object-oriented database.
However, you can do some object-oriented type things (Data Hiding, Encapsalation(sp)) using PL/SQL packages. Here is an example:

CREATE TABLE Employee_Data
(

	EmployeName	Varchar2(50),
	StartDate	Date,
	EndDate		Date,
	Salary		Number

);

CREATE PACKAGE Employee AS

	No_Such_Employee	Exception;
	After_Hours		Exception;

	Procedure HireEmployee(Name IN Varchar2, StartingSalary IN Number);
	Procedure FireEmployee(Name IN Varchar2);
	Procedure ChangeSalary(Name IN Varchar2, NewSalary IN Number);
	Function GetSalary(Name IN Varchar2) RETURN Number;
END;
/

CREATE PACKAGE BODY Employee AS

  • This procedure is private (because it isnt listed in the Package Spec above
	Procedure CheckHours IS
		Hour	Number;
	BEGIN
		Hour := TO_Number(TO_CHAR(Sysdate, 'hh24'));

		IF (Hour < 8 OR Hour > 17) THEN
			Raise After_Hours;  -- Generate an Exception (Error)
		END IF;
	END;

	PROCEDURE HireEmployee(Name IN Varchar2, StartingSalary IN Number)
	BEGIN
		INSERT INTO Employee_Data
		(
			EmployeeName,
			StartDate,
			Salary
		)
		VALUES
		(
			Name,
			SysDate,
			StartingSalary
		);
	END;

	PROCEDURE FireEmployee(Name IN Varchar2)
	BEGIN
		null;
	END;

	PROCEDURE ChangeSalary(Name IN Varchar2, NewSalary IN Number)
	BEGIN
		null;
	END;

	Function GetSalary(Name IN Varchar2) RETURN Number IS
		SalaryTemp	Number;
	BEGIN
		SELECT Salary INTO SalaryTemp
		FROM Employee_Data
		WHERE EmployeeName = Name;
	WHEN No_Data_Found THEN
		Raise No_Such_Employee;
	END;

END;
/
GRANT EXECUTE ON EMPLOYEE to PERSONELL;

Then users with the PERSONELL role would only be able to manipulate the EMPLOYEE_DATA through the methods you allow in the package.

-- 
-------------------------------------------------
Ken Johnson -  Technical Consultant
Tapestry Computing, Inc. http://www.tapestry.com
Received on Fri May 31 1996 - 00:00:00 CEST

Original text of this message