<tfoot id='Sf3x1'></tfoot>

  1. <legend id='Sf3x1'><style id='Sf3x1'><dir id='Sf3x1'><q id='Sf3x1'></q></dir></style></legend>
      <bdo id='Sf3x1'></bdo><ul id='Sf3x1'></ul>

    <small id='Sf3x1'></small><noframes id='Sf3x1'>

    <i id='Sf3x1'><tr id='Sf3x1'><dt id='Sf3x1'><q id='Sf3x1'><span id='Sf3x1'><b id='Sf3x1'><form id='Sf3x1'><ins id='Sf3x1'></ins><ul id='Sf3x1'></ul><sub id='Sf3x1'></sub></form><legend id='Sf3x1'></legend><bdo id='Sf3x1'><pre id='Sf3x1'><center id='Sf3x1'></center></pre></bdo></b><th id='Sf3x1'></th></span></q></dt></tr></i><div id='Sf3x1'><tfoot id='Sf3x1'></tfoot><dl id='Sf3x1'><fieldset id='Sf3x1'></fieldset></dl></div>

    1. 如何调用 Oracle PL/SQL 对象超级方法

      How to call an Oracle PL/SQL object super method(如何调用 Oracle PL/SQL 对象超级方法)
          <bdo id='pNJdW'></bdo><ul id='pNJdW'></ul>

          <i id='pNJdW'><tr id='pNJdW'><dt id='pNJdW'><q id='pNJdW'><span id='pNJdW'><b id='pNJdW'><form id='pNJdW'><ins id='pNJdW'></ins><ul id='pNJdW'></ul><sub id='pNJdW'></sub></form><legend id='pNJdW'></legend><bdo id='pNJdW'><pre id='pNJdW'><center id='pNJdW'></center></pre></bdo></b><th id='pNJdW'></th></span></q></dt></tr></i><div id='pNJdW'><tfoot id='pNJdW'></tfoot><dl id='pNJdW'><fieldset id='pNJdW'></fieldset></dl></div>
          <legend id='pNJdW'><style id='pNJdW'><dir id='pNJdW'><q id='pNJdW'></q></dir></style></legend>

          <small id='pNJdW'></small><noframes id='pNJdW'>

                  <tbody id='pNJdW'></tbody>
                <tfoot id='pNJdW'></tfoot>

              1. 本文介绍了如何调用 Oracle PL/SQL 对象超级方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想调用一个重写的 PL/SQL 方法.举个例子:

                I'd like to call an overridden PL/SQL method. Here's 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)
                )
                /
                

                现在我想调用 proc 方法的继承版本.当我尝试执行像 treat(self as test).proc(s); 这样的显式转换时,它不会编译,因为 PLS-00363: expression 'SYS_TREAT' cannot be used as分配目标

                Now I want to invoke the inherited version of the proc method. When I try to do an explicit cast like treat(self as test).proc(s); it won't compile because of PLS-00363: expression 'SYS_TREAT' cannot be used as an assignment target

                类型主体在我使用局部变量时编译:

                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;
                

                ...它抛出ORA-21780:超出对象持续时间的最大数量.

                有什么方法可以调用 test::proc(无需序列化/反序列化)?

                Is there any way to call test::proc (without serializing/deserializing)?

                而且...在proc被调用后,如何在obj中反映任何改变的属性(即n)?

                And... after proc has been called, how can any changed attributes (namely n) be reflected in obj ?

                更新(谢谢,tbone):

                Update (Thanks, tbone):

                我使用模板方法(之前"和之后")更改了我的方法的组织.每当我需要扩展方法时,我都会添加它们.

                I changed the organization of my methods using template methods ('before' and 'after'). I add them whenever I need to extend a 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;
                /
                

                推荐答案

                要访问超级方法,请尝试通用调用或通用表达式.例如,使用个人超类型和学生子类型:

                To access the super methods, try either general invocation or generalized expression. For example, using a person supertype and student subtype:

                CREATE OR REPLACE TYPE person_typ AS OBJECT (
                    idno number,
                    name varchar2(30),
                    phone varchar2(20),
                    MAP MEMBER FUNCTION get_idno RETURN NUMBER,
                    MEMBER FUNCTION show RETURN VARCHAR2)
                NOT FINAL;
                
                CREATE OR REPLACE TYPE BODY person_typ AS
                  MAP MEMBER FUNCTION get_idno RETURN NUMBER IS
                  BEGIN
                    RETURN idno;
                  END;
                  MEMBER FUNCTION show RETURN VARCHAR2 IS
                  BEGIN
                    -- function that can be overriden by subtypes MEMBER FUNCTION show RETURN VARCHAR2 IS BEGIN
                    RETURN 'Id: ' || TO_CHAR(idno) || ', Name: ' || name;
                  END;
                END;
                
                CREATE TYPE student_typ UNDER person_typ (
                    dept_id NUMBER,
                    major VARCHAR2(30),
                    OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2)
                NOT FINAL;
                
                CREATE TYPE BODY student_typ AS
                  OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2 IS
                  BEGIN
                    RETURN (self AS person_typ).show || ' -- Major: ' || major ;
                  END;
                END;
                
                -- Using Generalized Invocation
                DECLARE
                myvar student_typ := student_typ(100, 'Sam', '6505556666', 100, 'Math');
                name VARCHAR2(100); 
                BEGIN
                name := (myvar AS person_typ).show; --Generalized invocation 
                END;
                
                -- Using Generalized Expression
                DECLARE
                myvar2 student_typ := student_typ(101, 'Sam', '6505556666', 100, 'Math');
                name2 VARCHAR2(100); 
                BEGIN
                name2 := person_typ.show((myvar2 AS person_typ)); -- Generalized expression 
                END;
                

                如果您使用的是 10g,则需要对函数进行一些不同的组织,但与调用 super 方法的子函数具有相同的功能:

                If you are on 10g, you'll need to organize the functions a bit different, but same functionality from the child to call the super method:

                CREATE TYPE BODY person_typ AS 
                  MAP MEMBER FUNCTION get_idno RETURN NUMBER IS 
                  BEGIN
                    RETURN idno; 
                  END;
                  -- static function that can be called by subtypes 
                  STATIC FUNCTION show_super (person_obj in person_typ) RETURN VARCHAR2 IS
                  BEGIN 
                    RETURN 'Id: ' || TO_CHAR(person_obj.idno) || ', Name: ' || person_obj.name;
                  END;
                  -- function that can be overriden by subtypes 
                  MEMBER FUNCTION show RETURN VARCHAR2 IS 
                  BEGIN
                    RETURN person_typ.show_super ( SELF ); 
                  END;
                END;
                
                CREATE TYPE student_typ UNDER person_typ ( 
                  dept_id NUMBER,
                  major VARCHAR2(30), 
                  OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2) 
                  NOT FINAL;
                
                CREATE TYPE BODY student_typ AS 
                  OVERRIDING MEMBER FUNCTION show RETURN VARCHAR2 IS 
                  BEGIN
                    RETURN person_typ.show_super ( SELF ) || ' -- Major: ' || major ;
                  END;
                END;
                

                现在您可以从 student 中为 person 方法调用 show_super(),或者为 student 方法调用 show().

                Now you'd call show_super() from student for the person method, or just show() for the student method.

                来自文档,希望有所帮助.

                From the docs, hope that helps.

                这篇关于如何调用 Oracle PL/SQL 对象超级方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to call Oracle function or stored procedure using spring persistence framework?(如何使用 Spring 持久化框架调用 Oracle 函数或存储过程?)
                What can cause intermittent ORA-12519 (TNS: no appropriate handler found) errors(什么会导致间歇性 ORA-12519(TNS:找不到合适的处理程序)错误)
                SQL to return the number of working days between 2 passed in dates(SQL 返回两个传入日期之间的工作日数)
                Oracle Date Subtraction(Oracle 日期减法)
                Is using quot;select *quot; for a cursor in PL/SQL considered bad programming?(正在使用“选择 *PL/SQL 中的游标被认为是糟糕的编程?)
                Using sql/plsql, how do you find out which character set a text uses?(使用 sql/plsql,你如何找出文本使用的字符集?)
                        <tbody id='ojg2d'></tbody>

                      <small id='ojg2d'></small><noframes id='ojg2d'>

                      • <tfoot id='ojg2d'></tfoot>
                        • <bdo id='ojg2d'></bdo><ul id='ojg2d'></ul>
                        • <legend id='ojg2d'><style id='ojg2d'><dir id='ojg2d'><q id='ojg2d'></q></dir></style></legend>
                          <i id='ojg2d'><tr id='ojg2d'><dt id='ojg2d'><q id='ojg2d'><span id='ojg2d'><b id='ojg2d'><form id='ojg2d'><ins id='ojg2d'></ins><ul id='ojg2d'></ul><sub id='ojg2d'></sub></form><legend id='ojg2d'></legend><bdo id='ojg2d'><pre id='ojg2d'><center id='ojg2d'></center></pre></bdo></b><th id='ojg2d'></th></span></q></dt></tr></i><div id='ojg2d'><tfoot id='ojg2d'></tfoot><dl id='ojg2d'><fieldset id='ojg2d'></fieldset></dl></div>