Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Q: Using SELF's nested table in a function?
Hi,
I have a problem with using a table-valued attribute of an object table in a member function (setting: a geo-database for educational purposes):
CREATE TYPE Member_Type AS OBJECT
(Country VARCHAR2(4),
Type VARCHAR2(30));
/
CREATE TYPE Member_List_Type AS
TABLE OF Member_Type;
/
CREATE TABLE Country
(Code VARCHAR2(4));
CREATE OR REPLACE TYPE Organization_Type AS OBJECT
(Abbrev VARCHAR2(12),
Members Member_List_Type,
MEMBER FUNCTION people RETURN NUMBER,
PRAGMA RESTRICT_REFERENCES (people,WNDS,WNPS));
/
CREATE TABLE Organization_ObjTab OF Organization_Type
(Abbrev PRIMARY KEY)
NESTED TABLE Members STORE AS Members_nested;
CREATE OR REPLACE TYPE BODY Organization_Type IS
MEMBER FUNCTION people RETURN NUMBER IS
p NUMBER;
BEGIN
SELECT SUM(population) INTO p
FROM Country
WHERE Code IN (SELECT Country
FROM TABLE (Members)); -- <<<<<<<<<<<<<<<<<<<RETURN p;
INSERT INTO Organization_ObjTab VALUES
(Organization_Type('EU',
Member_List_Type(member_type('D','full'))));
compiles without problem ...
SELECT abbrev, o.people()
FROM Organization_ObjTab o;
complains:
SQL> SQL> SELECT abbrev, o.people()
FROM Organization_ObjTab o;
2 SELECT abbrev, o.people()
*
FEHLER in Zeile 1:
ORA-00903: Ungueltiger Tabellenname [engl.: invalid table name] ORA-06512: in "MAY.ORGANIZATION_TYPE", Zeile 5 ORA-06512: in Zeile 1
where "members" is a collection-valued attribute of the object:
SQL> select members from Organization_ObjTab;
MEMBERS(COUNTRY, TYPE)
Question: How can this be used in the function ? (I tried SELF.members and some other things which did not succeed)
Can someone perhaps mail/post an example where a nested table is used in a member function/procedure?
THX, Wolfgang