如何oracle调用自己的类型成员函数

use*_*713 3 oracle user-defined-types

我创建了一个SQL对象:

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

        member function get return integer
)
Run Code Online (Sandbox Code Playgroud)

我实现了我的类型的身体:

CREATE TYPE BODY foo_type as
member function get return integer is
begin
   return bar;
END;
END;
Run Code Online (Sandbox Code Playgroud)

然后我创建了一个这种类型的表:

CREATE TABLE test_table(
    foo1 foo_type
)
Run Code Online (Sandbox Code Playgroud)

我插了一行:

INSERT INTO test_table (foo1) VALUES (foo_type(1, 'a'))
Run Code Online (Sandbox Code Playgroud)

我想这可以像这样调用:

SELECT foo1.get() FROM test_table
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

Daz*_*zaL 5

在引用类型方法/属性时必须使用别名.

例如将表别名为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
Run Code Online (Sandbox Code Playgroud)