2013-02-19 25 views
3

創建一個SQL對象:我如何Oracle調用自己的類型成員函數

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

     member function get return integer 
) 

和我實現了我喜歡的類型的身體:

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

然後,我創建了一個表,此類型:

CREATE TABLE test_table(
    foo1 foo_type 
) 

我插了一行:

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

我想,這是調用這樣的:

SELECT foo1.get() FROM test_table 

但它沒有工作。

回答

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 
相關問題