I want to implement a stack data structure in 10gR2.
However, when I try to do:
CREATE or replace TYPE ContainerArray AS VARRAY(25) OF XDB.DBMS_XMLDOM.DOMNODE ;
I get
"schema-level type has illegal reference to XDB.DBMS_XMLDOM."
So I've figured out that's because Oracle will not let you create a schema-level type which references a package-level type.
I can fix that problem by creating the type inside of the package:
TYPE ContainerArray AS VARRAY(25) OF XDB.DBMS_XMLDOM.DOMNODE;
However, then when I try to create my object, I can't reference the package-level type:
CREATE TYPE DOMNode_Stack AS OBJECT (
max_size INTEGER,
top INTEGER,
position ContainerArray,
MEMBER PROCEDURE initialize,
MEMBER FUNCTION full RETURN BOOLEAN,
MEMBER FUNCTION empty RETURN BOOLEAN,
MEMBER PROCEDURE push (n IN INTEGER),
MEMBER PROCEDURE pop (n OUT INTEGER)
);
and I can't create the object type inside of the package because I get
"Object not supported in this context."
Any thoughts on how I can solve this issue?
Best Answer
sql level objects like an OBJECT can only reference SQL types in their attributes.
if you see the package spec:
so you could create an sql array of
then in your object put
which will work. when you reference it, just assign a local variable v_dom xml_dom.domnode; begin v_dom.id := your array index value that you're dealing with at the time;
be advised that on any Oracle upgrade you need to verify that the structure of DOMNODE hasn't changed.
edit: here's a sample:
the important bit being:
to assign from DBMS_XMLDOM to the sql type we take v_dom.id.
13 v_dom := DBMS_XMLDOM.item(v_nl, idx); 14 position.extend; 15 position(position.last) := v_dom.id;
and when reversing:
23 for idx in 1..position.count 24 loop 25 v_dom.id := position(idx);
ie assign the ID part (not the record itself..that would error out) back.