title: Save oracle objects in tables
body: <p>I've read about OOP in Oracle. Did some practice on inserting objects into tables.
  For example:</p>
  
  <pre><code>create or replace type person as object(
   id number,
   name varchar2(50),
   age number,
   constructor function person return self as result,
   constructor function person(id number, name varchar2, age number) return self as result,
   member procedure set_id(id in number),
   member function get_id return number,
   member procedure set_name(name in varchar2),
   member function get_name return varchar2,
   member procedure set_age(age in number),
   member function get_age return number,
   member function to_string return varchar2
  )
  </code></pre>
  
  <p>Type body:</p>
  
  <pre><code>create or replace type body person as
   constructor function person return self as result is
    begin
      self := person();
      return;
    end;
  
   constructor function person(id in number, name in varchar2, age in number) return self as result is
    begin
      self.id := id;
      self.name := name;
      self.age := age;
      return;
    end;
  
  
   member procedure set_id(id in number) is
    begin
      self.id := id;
    end;
  
   member function get_id return number is
    begin 
      return self.id;
    end;
  
   member procedure set_name(name in varchar2) is
    begin
      self.name := name;
    end;
  
   member function get_name return varchar2 is
    begin
      return self.name;
    end;
  
  
  member procedure set_age(age in number) is
   begin
     self.age := age;
   end;
  
  member function get_age return number is
   begin
     return self.age;
   end;
  
  member function to_string return varchar2 is
   begin
     return 'Person={id='||self.get_id||', name='||self.get_name||', age='||self.get_age||'}';
   end;
  
  end;
  </code></pre>
  
  <p>Create some table:</p>
  
  <pre><code>create table test_objs(
   id number,
   person person
  )
  </code></pre>
  
  <p>And some DML:</p>
  
  <pre><code>insert into test_objs(id, person) values(1, person(1, 'Test person', 25));
  
  select * from test_objs;
  </code></pre>
  
  <p>The result is:</p>
  
  <p><img src="https://i.stack.imgur.com/LfR1u.png" alt="enter image description here"></p>
  
  <p>Looks great for me, and it is better to work with objects instead of couple of arguments in procedures/functions (imho). Oracle has good OOP (it will be super if they add encapsulation too). I create objects, save these objects in tables, create stored programs which work with objects and so on.. But I did not see anywhere people keeping data as objects or doing fully oop in db level. Do experts advise this way of db programming? What are the cons and pros of it?</p>