Object-oriented programming on PL/SQL: intro

Once again, I’m at a loss for what to write in the post title. Okay, Let’s start with this: "Implementation of OOP first appeared in the Oracle 9g RDBMS."
create or replace type OBJECT_TEST1 as object (
       id                          number(7),
       name                        varchar2(50),
       effective_start_date        date,
       effective_end_date          date,
       value                       number,
       inc_value                   number,
       value_sign                  number(1),
       constructor function object_test1(
                   p_value  number
                   ) return self as result,
       member function get_inc_value return number,
       member function get_sign_value return number
)
create or replace type body OBJECT_TEST1 as
 constructor function object_test1(
                      p_value number
                   ) return self as result is
 begin
   self.value := p_value;
   self.inc_value := p_value + 1;
   self.value_sign := sign(p_value);
   self.id := object_test1_s.nextval;
   self.effective_start_date := sysdate;
   self.effective_end_date := to_date('31.12.4212', 'DD.MM.YYYY');
   return;
 end object_test1;
 --
 member function get_inc_value return number
 is
 begin
   return self.inc_value;
 end get_inc_value;
 --
 member function get_sign_value return number
 is
 begin
   return self.value_sign;
 end get_sign_value;
end;
Create a table to store objects and some auxiliary elements, such as a sequence. We pay attention to the concise syntax of the table definition, as well as the fact that the set of fields after creation corresponds to the set of variables in the object type.
create table test1_objects of object_test1
/
create sequence object_test1_s
start with 1
increment by 1
maxvalue 99999999999
nocache
/
Create API
create or replace package OBJECT_TEST1_PKG is
  procedure insert_object(p_object object_test1);
  procedure update_object(p_old object_test1,
                          p_new object_test1);
  procedure delete_object(p_object object_test1); 
end OBJECT_TEST1_PKG;
create or replace package body OBJECT_TEST1_PKG is
  procedure insert_object(p_object object_test1)
  is
  begin
    insert into test1_objects
    values (p_object);
  end insert_object;
  --
  procedure update_object(p_old object_test1,
                          p_new object_test1)
  is
  begin
    update test1_objects tob
    set tob.name = p_new.name
    where tob.id = p_old.id;
  end update_object;

  procedure delete_object(p_object object_test1)
  is
  begin
    delete from test1_objects tob
    where tob.id = p_object.id;
  end delete_object;
end OBJECT_TEST1_PKG;
Call API
declare
 l_object object_test1;
begin
 l_object := new object_test1(1);
 object_test1_pkg.insert_object(l_object);
end;
Result
SQL> select * from test1_objects
  2  /

ID NAME EFFECTIVE_START_DATE EFFECTIVE_END_DATE VALUE INC_VALUE VALUE_SIGN

-- ---- -------------------- ------------------ ----- --------- ---------- 
3       15.06.2013 0:13:24   31.12.4212         1     2         1
SQL> 
ceo@thomsonslegacy.com

We customize Oracle e-Business Suite R12 modules with Oracle Applications Framework and providing Oracle ADF based solutions


© Thomsonslegacy.com, 2025.
If you publish the materials of the site, the reference to the source is obligatory. The site uses cookies.