Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call an Oracle PL/SQL object super method
    text
    copied!<p>I'd like to call an overridden PL/SQL method. Here's an example:</p> <pre><code>-- 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) ) / </code></pre> <p>Now I want to invoke the inherited version of the <code>proc</code> method. When I try to do an explicit cast like <code>treat(self as test).proc(s);</code> it won't compile because of <strong>PLS-00363: expression 'SYS_TREAT' cannot be used as an assignment target</strong></p> <p>The type body compiles when I use a local variable:</p> <pre><code>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; / </code></pre> <p>But when I run my example like this</p> <pre><code>declare obj test2; begin obj := test2(0); obj.proc('1'); end; </code></pre> <p>...it throws <strong>ORA-21780: Maximum number of object durations exceeded.</strong></p> <p>Is there any way to call test::proc (without serializing/deserializing)?</p> <p>And... after proc has been called, how can any changed attributes (namely <code>n</code>) be reflected in <code>obj</code> ?</p> <hr> <p><strong>Update</strong> (Thanks, tbone):</p> <p>I changed the organization of my methods using template methods ('before' and 'after'). I add them whenever I need to extend a method.</p> <pre><code>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; / </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload