Object-PL/SQL: Difference between revisions

Content deleted Content added
Addbot (talk | contribs)
m Bot: Migrating 2 interwiki links, now provided by Wikidata on d:q3348103
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="SQLplsql">
 
create or replace type base_type as object (
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="SQLplsql">
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="SQLplsql">
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="SQLplsql">
create or replace type body deriv_type as
overriding member function func return number is
Line 69:
end;
/</source>
The created types can be instantiaded and methods can be called:<source lang="SQLplsql">
declare
b1 base_type :=base_type();
Line 89:
* 24
* 30
The created types have become real types and can be used in tables:<source lang="SQLplsql">
create table table_base (
b base_type
Line 106:
* 0
* 72
<source lang="SQLplsql">
select avg(t.b.func()) from table_base t;
AVG(T.B.FUNC())</source>