create type foo_type as object ( foo number, member procedure proc(p in number), member function func(p in number) return number ); /
create type body foo_type as member procedure proc(p in number) is begin foo := p*2; end proc; member function func(p in number) return number is begin return foo/p; end func; end; /
The Type definition you've declared creates the object class, but not actually an object itself.
SQL> set serverout on SQL> SQL> declare 2 v_foo foo_type; 3 v_val number; 4 begin 5 v_foo := foo_type(20); -- instantiate the object and initialize the object attributes 6 v_foo.proc(20); -- call the object method (proc) 7 v_val := v_foo.func(4); -- call the object method (func) 8 dbms_output.put_line(v_val); 9 end; 10 / 10 PL/SQL procedure successfully completed.
BS2012 wrote:This is standard object-orientated (o-o) programming principles. The object type created, is called a class in o-o programming. A class has a number of features - including properties (attribute values) and methods (procedures and functions).
Please do have a look at these codes and help me understand. I have no idea about this member function and member procedure. How do they work?