Oracle PL/SQL:如何从 REF VARRAY 中 DEREF?
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DEREF 必须位于 SQL 语句中:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i463707
这个
测试用例可以很好地重现!
the DEREF must be in a SQL Statement:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i463707
this works
nice test case to reproduce!