Content deleted Content added
m →Examples of uses of syntax of O-PL/SQL: lang="plpgsql" |
|||
Line 27:
=== Example 1 ===
A simple example of object-oriented PL/SQL<ref>{{cite web|url=http://www.adp-gmbh.ch/ora/plsql/oo/example_1.html|title=Object Oriented Oracle, example 1|publisher=René Nyffenegger's collection of things on the web|accessdate=19 April 2012}}</ref>
<source lang=" create or replace type base_type as object (
a number,
Line 36:
) instantiable not final;
/</source>
Now, the type's implementation is created. The implementation defines how the type's functions, procedures and how explicit constructors behave:<source lang="
create or replace type body base_type as
constructor function base_type return self as result is
Line 55:
end;
/</source>
We're ready to derive from base_type. The keyword for deriving is under. The derived type defines a new attribute (named: m) and overrides func.<source lang="
create or replace type deriv_type under base_type (
m number,
Line 61:
);
/</source>
As is the case with base types, the overridden methods in the derived type must be implemented:
<source lang=" create or replace type body deriv_type as
overriding member function func return number is
Line 69 ⟶ 70:
end;
/</source>
The created types can be instantiated and methods can be called:
<source lang=" declare
b1 base_type :=base_type();
Line 85 ⟶ 87:
/</source>
Results
The created types have become real types and can be used in tables:
<source lang=" create table table_base (
b base_type
Line 104 ⟶ 107:
</source>
Results:
<source lang="
select avg(t.b.func()) from table_base t;
</source>
Result:
=== Example 2 ===
|