0

I have a schema RTRD_W built in an Oracle 11g database that contains a table rtrd_pri that has a column NOMNL which is has a type defined as VARRAY(10) OF KPS_ADM.NUMBER_T (an object defined as a type in the KPS_ADM schema). I am trying to run a query to retrieve the KPS_ADM.NUMBER_T object inside the varray but I keep getting an error returned in my SQL syntax. The function I built is posted below

CREATE or replace function RETRIEVEPRIREF RETURN KPS_ADM.NUMBER_T AS
REF1 KPS_ADM.NUMBER_T;
BEGIN
SELECT KPS_ADM.NUMBER_T INTO REF1 from table(NOMNL) WHERE (SELECT NOMNL FROM RTRD_W.rtrd_pri WHERE (syst_id like '%0516%'));
RETURN REF1;
END RETRIEVEPRIREF;

I know the query :SELECT NOMNL FROM RTRD_W.rtrd_pri WHERE (syst_id like '%0516%') works and does return a varray with a single KPS_ADM.NUMBER_T object inside it, but I can't seem to get the syntax right for searching inside the varray to retrieve the object.

Can anyone show the proper syntax to do this?

Jon Heller
  • 34,999
  • 6
  • 74
  • 132

1 Answers1

1
-- an object defined as a type in the KPS_ADM schema
CREATE TYPE number_t        AS OBJECT (object_value NUMBER);
CREATE TYPE varray_number_t AS VARRAY(10) OF number_t;

CREATE TABLE rtrd_pri
(
    column_one NUMBER
,   column_two varray_number_t
);

INSERT INTO rtrd_pri VALUES(1, (varray_number_t(number_t(11), number_t(22))));
INSERT INTO rtrd_pri VALUES(2, (varray_number_t(number_t(33), number_t(44))));

SELECT  column_one, OBJECT_VALUE AS column_two
FROM    rtrd_pri, TABLE(rtrd_pri.column_two)
;

COLUMN_ONE  COLUMN_TWO
1           11
1           22
2           33
2           44
the_slk
  • 2,172
  • 1
  • 11
  • 10