Content deleted Content added
Rescuing 3 sources and tagging 0 as dead.) #IABot (v2.0 |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 26:
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>
<
create or replace type base_type as object (
a number,
Line 33:
member procedure proc (n number)
) instantiable not final;
/</
Now, the type's implementation is created. The implementation defines how the type's functions, procedures and how explicit constructors behave:<
create or replace type body base_type as
constructor function base_type return self as result is
Line 52:
end proc;
end;
/</
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.<
create or replace type deriv_type under base_type (
m number,
overriding member function func return number
);
/</
As is the case with base types, the overridden methods in the derived type must be implemented:
<
create or replace type body deriv_type as
overriding member function func return number is
Line 67:
end;
end;
/</
The created types can be instantiated and methods can be called:
<
declare
b1 base_type :=base_type();
Line 83:
dbms_output.put_line(d2.func);
end;
/</
Results
0
Line 90:
30
The created types have become real types and can be used in tables:
<
create table table_base (
b base_type
Line 103:
/
select t.b.func() from table_base t;
</syntaxhighlight>
Results:
0
72
<
select avg(t.b.func()) from table_base t;
</syntaxhighlight>
Result:
36
|