I would like to call an overridden PL / SQL method. Here is an example:
-- super class create or replace type test as object ( n number, member procedure proc(SELF in out nocopy test, s varchar2) ) alter type test not final / create or replace type body test is member procedure proc(SELF in out nocopy test, s varchar2) is begin dbms_output.put_line('test1: n='||nvl(self.n, 'null')||' s='||s); self.n := to_number(s); end; end; / -- derived class create or replace type test2 under test ( overriding member procedure proc(SELF in out nocopy test2, s varchar2) ) /
Now I want to call the inherited version of the proc
method. When I try to do an explicit conversion, for example treat(self as test).proc(s);
, it will not compile due to PLS-00363: the expression 'SYS_TREAT' cannot be used as the destination
The type body compiles when I use a local variable:
create or replace type body test2 is overriding member procedure proc(SELF in out nocopy test2, s varchar2) is O test; begin O := treat(self as test); O.proc(s); end; end; /
But when I run my example like this
declare obj test2; begin obj := test2(0); obj.proc('1'); end;
... he throws out ORA-21780: The maximum number of object durations has been exceeded.
Is there a way to call test :: proc (without serialization / deserialization)?
And ... after calling proc, how can I change any changed attributes (namely n
) in obj
?
Update (Thanks, tbone):
I changed the organization of my methods using template methods ("before" and "after"). I add them when I need to extend the method.
create or replace type test as object ( n number, member procedure proc (SELF in out nocopy test, s varchar2), member procedure afterProc (SELF in out nocopy test, s varchar2) member procedure beforeProc(SELF in out nocopy test, s varchar2), ) not final / create or replace type body test is member procedure proc(SELF in out nocopy test, s varchar2) is begin beforeProc(s); dbms_output.put_line('test1: n='||nvl(n, 'null')||' s='||s); n := to_number(s); afterProc(s); end; member procedure afterProc (SELF in out nocopy test, s varchar2) is begin null; end; member procedure beforeProc(SELF in out nocopy test, s varchar2) is begin null; end; end; /