Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to oracle call own type member 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 implemented my type's body:

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 a row:

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

I would like that this is callable like this:

SELECT foo1.get() FROM test_table

but it doesn't works.

like image 964
user1949713 Avatar asked Feb 19 '13 10:02

user1949713


1 Answers

you have to use an alias when referencing type methods/attributes.

eg alias the table to 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
like image 133
DazzaL Avatar answered Oct 10 '22 23:10

DazzaL