PLS-00540: the object is not supported in this context when trying to compile a package specification

I am trying to compile a package specification. I would like to include some type definitions and declare a function:

TYPE col_type AS OBJECT (
col_name VARCHAR2(50)
);

TYPE col_sub_type
IS TABLE OF
col_type;

FUNCTION get_col_tab RETURN col_sub_type;

And finally, the function get_col_tab:

FUNCTION get_col_tab RETURN col_sub_type AS
l_type  col_sub_type := col_sub_type();
BEGIN
FOR i IN (SELECT DISTINCT TABLE_NAME t_name FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'TABLE_1') LOOP
l_type.extend;
l_type(l_type.last) := col_type(i.t_name);
END LOOP;
RETURN l_type;
END;

But when compiling the package specification, I get the following error:

PLS-00540: object is not supported in this context

As I understand it, I can not use the type OBJECTin the package specification. Is there a workaround or another way to do this?

Thanks in advance.

+4
source share
2 answers

In PL / SQL, you need to use recordinstead object.

TYPE col_type IS RECORD (
col_name VARCHAR2(50)
);

TYPE col_sub_type
IS TABLE OF
col_type;

FUNCTION get_col_tab RETURN col_sub_type;

, , .


, record ( ). , :

l_type(l_type.last).col_name := i.t_name;

bulk collect:

SELECT DISTINCT table_name t_name
BULK   COLLECT INTO l_type
FROM   all_tab_columns
WHERE  table_name = 'TABLE_1';
+7

?

TYPE col_sub_type IS TABLE OF VARCHAR2(50);

FUNCTION get_col_tab RETURN col_sub_type AS
l_type  col_sub_type;
BEGIN

   SELECT DISTINCT TABLE_NAME 
   BULK COLLECT INTO l_type
   FROM ALL_TAB_COLUMNS 
   WHERE TABLE_NAME = 'TABLE_1';

   RETURN l_type;
END;
+1

Source: https://habr.com/ru/post/1611672/


All Articles