How to use oracle type username function

I created a SQL object:

create type foo_type as object (
        bar integer(2),
        bar2  varchar(200),

        member function get return integer
)

      

and I have implemented a body of my type:

CREATE TYPE BODY foo_type as
member function get return integer is
begin
   return bar;
END;
END;

      

Then I created a table with this type:

CREATE TABLE test_table(
    foo1 foo_type
)

      

and I inserted the line:

INSERT INTO test_table (foo1) VALUES (foo_type(1, 'a'))

      

I would like it to be called like this:

SELECT foo1.get() FROM test_table

      

but it doesn't work.

+3


source to share


1 answer


you need to use an alias when referring to methods / attributes of types.

for example a table alias in t:



SQL> INSERT INTO test_table (foo1) VALUES (foo_type(1, 'a'));

1 row created.

SQL> select t.foo1.get() from test_table t;

T.FOO1.GET()
------------
           1

      

+5


source







All Articles