Oracle PL/SQL:如何从 REF VARRAY 中 DEREF?

发布于 2024-11-04 19:09:18 字数 948 浏览 0 评论 0原文

我是 Oracle 对象新手,遇到了问题。我不知道如何从 REF VARRAY 中取消引用某个项目。下面是一些重现我遇到的问题的源代码。 错误是: PLS-00306:调用“DEREF”时参数的数量或类型错误


DROP TYPE LOC FORCE
/
DROP TYPE LIST_LOC FORCE
/
DROP TYPE PIZ FORCE
/

CREATE OR REPLACE TYPE LOC AS OBJECT(
  NAME      VARCHAR2(30),
  MEMBER FUNCTION GET_NAME RETURN VARCHAR2 
)
/

CREATE OR REPLACE TYPE BODY LOC AS
  MEMBER FUNCTION GET_NAME RETURN VARCHAR2 IS
  BEGIN
    RETURN SELF.NAME;
  END;
END;
/

CREATE OR REPLACE TYPE LIST_LOC AS VARRAY(10) OF REF LOC
/

CREATE OR REPLACE TYPE PIZ AS OBJECT(
  LOCS      LIST_LOC,
  MEMBER PROCEDURE DISPLAY_LOCS
)
/

CREATE OR REPLACE TYPE BODY PIZ AS
  MEMBER PROCEDURE DISPLAY_LOCS IS
  BEGIN
    FOR IDX IN SELF.LOCS.FIRST..SELF.LOCS.LAST LOOP
      DBMS_OUTPUT.PUT_LINE(DEREF(SELF.LOCS(IDX)).GET_NAME()); --this is the line that generates the error
    END LOOP;
  END;
END;
/

当我尝试从 LOCS 变量获取位置 IDX 处的 REF 并对其进行 DEREF 以获得名称时,DISPLAY_LOCS 过程中出现错误。

I'm new to Oracle Objects and I have a problem. I don't know how to dereference an item from a VARRAY of REFs. Below is some source code that reproduces the problem that I have.
The error is: PLS-00306: Wrong number or types of arguments in call to 'DEREF'


DROP TYPE LOC FORCE
/
DROP TYPE LIST_LOC FORCE
/
DROP TYPE PIZ FORCE
/

CREATE OR REPLACE TYPE LOC AS OBJECT(
  NAME      VARCHAR2(30),
  MEMBER FUNCTION GET_NAME RETURN VARCHAR2 
)
/

CREATE OR REPLACE TYPE BODY LOC AS
  MEMBER FUNCTION GET_NAME RETURN VARCHAR2 IS
  BEGIN
    RETURN SELF.NAME;
  END;
END;
/

CREATE OR REPLACE TYPE LIST_LOC AS VARRAY(10) OF REF LOC
/

CREATE OR REPLACE TYPE PIZ AS OBJECT(
  LOCS      LIST_LOC,
  MEMBER PROCEDURE DISPLAY_LOCS
)
/

CREATE OR REPLACE TYPE BODY PIZ AS
  MEMBER PROCEDURE DISPLAY_LOCS IS
  BEGIN
    FOR IDX IN SELF.LOCS.FIRST..SELF.LOCS.LAST LOOP
      DBMS_OUTPUT.PUT_LINE(DEREF(SELF.LOCS(IDX)).GET_NAME()); --this is the line that generates the error
    END LOOP;
  END;
END;
/

The error appears in DISPLAY_LOCS procedure, when I try to get the REF at position IDX from the LOCS varray, and to DEREF it to get the name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-11-11 19:09:18

DEREF 必须位于 SQL 语句中:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i463707

PL/SQL 中的 VALUE、REF 和 DEREF
函数只能出现在 SQL 中
声明

这个

CREATE OR REPLACE TYPE BODY PIZ AS
  MEMBER PROCEDURE DISPLAY_LOCS IS
  x varchar2(30) ;
  BEGIN
    FOR IDX IN SELF.LOCS.FIRST..SELF.LOCS.LAST LOOP
        select DEREF(SELF.LOCS(IDX)).GET_NAME() into x from dual ;
      DBMS_OUTPUT.PUT_LINE(x); --this is the line that generates the error
    END LOOP;
  END;
END;
/

测试用例可以很好地重现!

the DEREF must be in a SQL Statement:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i463707

In PL/SQL the VALUE, REF and DEREF
functions can appear only in a SQL
statement

this works

CREATE OR REPLACE TYPE BODY PIZ AS
  MEMBER PROCEDURE DISPLAY_LOCS IS
  x varchar2(30) ;
  BEGIN
    FOR IDX IN SELF.LOCS.FIRST..SELF.LOCS.LAST LOOP
        select DEREF(SELF.LOCS(IDX)).GET_NAME() into x from dual ;
      DBMS_OUTPUT.PUT_LINE(x); --this is the line that generates the error
    END LOOP;
  END;
END;
/

nice test case to reproduce!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文