Oracle Deref 函数 : wrong numer or type of arguments

标签 oracle plsql

我正在尝试在 Oracle 中创建一个对象方法,如下所示:

CREATE OR REPLACE TYPE BODY TheType AS
    MEMBER FUNCTION getAtt RETURN VARCHAR2 IS
    BEGIN
        RETURN DEREF(SELF.Att).Att2;
    END;
END;
/

但我收到以下错误:
PLS-00306: wrong number or types of arguments in call to 'DEREF'

TheType 类型也是这样声明的:

CREATE OR REPLACE TYPE TheType UNDER SuperType ();
/

...

ALTER TYPE TheType ADD ATTRIBUTE ( Att REF TheType ) CASCADE;

...

ALTER TYPE TheType 
    ADD MEMBER FUNCTION getAtt RETURN VARCHAR2
CASCADE;

以及 Supertype 的定义:

CREATE OR REPLACE TYPE SuperType AS OBJECT ( Att2 VARCHAR2(50) )
NOT FINAL NOT INSTANTIABLE;
/

我给 DEREF 函数一个正确类型的 var,为什么会发生这个错误?

如果我信任 Oracle doc,它应该可以工作

谢谢。

最佳答案

将 DEREF 转换为 SQL。例如

SQL> create or replace type supertype as object ( att2 varchar2(50) )
  2  not final not instantiable;
  3  /

Type created.

SQL> create or replace type thetype under supertype (
  2  att ref thetype,
  3  member function getatt return varchar2);
  4  /

Type created.

SQL> show errors type thetype
No errors.
SQL> create or replace type body thetype as
  2    member function getatt return varchar2 is
  3      v_t thetype;
  4    begin
  5             select deref(self.att) into v_t from dual;
  6             return v_t.att2;
  7    end;
  8  end;
  9  /

Type body created.

SQL> show errors type body thetype
No errors.
SQL> create table thetypes of thetype;

Table created.

SQL> insert into thetypes values ('hi there', null);

1 row created.

SQL> set serverout on
SQL> declare
  2    v_t thetype;
  3  begin
  4    select thetype(null, ref(a)) into v_t from thetypes a;
  5    dbms_output.put_line(v_t.getatt);
  6  end;
  7  /
hi there

PL/SQL procedure successfully completed.

SQL>

关于Oracle Deref 函数 : wrong numer or type of arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14030364/

相关文章:

sql - 如何更改 APEX 5.1 中的单行值?

sql - 甲骨文 - 将日期分成几个季度

oracle - 是否有关于使用显式 ANSI JOIN 与隐式连接的 Oracle 官方建议?

oracle - 如何从 Oracle PL/SQL 函数返回现有表中的记录?

oracle - 在 PL/SQL 中将二进制转换为 varchar

oracle - PLSQL 并非所有变量都绑定(bind)

oracle - PL/SQL : re-write SELECT statement using IN parameter in stored procedure

sql - Oracle Pro*C 用游标更新表失败

sql - ORA-00903 : invalid table name

sql - ORA-06532 : Subscript outside of limit