2014-01-20 198 views
0

試圖使Java函數從成員函數中工作。我對此很陌生,所以我不知道錯誤可能在哪裏。將複製所有相關的代碼。Sql開發人員ORA-29531

create or replace 
type sfera as object(
radius number(10,2), 
member function tilpums(radius double precision) return double precision); 

create or replace and compile JAVA source named "Papild" as 
public class Papild { 
public static double rek(double radius) 
{ 
return 3.14*radius*radius*radius*4/3; 
} 
} 

create or replace 
type body sfera as 
member function tilpums(radius double precision) return double precision as Language java 
Name 'Papild.rek(double) return double'; 
end; 

Create table sferas of sfera; 

Insert into sferas values(4); 

select value(a).tilpums(radius) from sferas a; 

,並從選擇我收到以下錯誤信息:

Error starting at line 1 in command: 
select value(a).tilpums(radius) from sferas a 
Error report: 
SQL Error: ORA-29531: no method rek in class Papild 
29531. 00000 - "no method %s in class %s" 
*Cause: An attempt was made to execute a non-existent method in a 
      Java class. 
*Action: Adjust the call or create the specified method. 

所有幫助將不勝感激。

回答

1

能不能提出一個解決方法(而不是由一個工作知府) - 使用standalong功能,並調用它的成員之一:

SQL> create or replace function standalon_tilpums(radius double precision) 
    2 return double precision as Language java 
    3 Name 'Papild.rek(double) return double'; 
    4/

SQL> select standalon_tilpums(4) from dual; 

STANDALON_TILPUMS(4)                
--------------------                
      267,946667                

SQL> create or replace 
    2 type sfera as object(
    3 radius number(10,2), 
    4 member function tilpums(radius double precision) return double precision); 
    5/

SQL> create or replace 
    2 type body sfera as 
    3 member function tilpums(radius double precision) return double precision 
    4 is begin return standalon_tilpums(radius); end; 
    5 end; 
    6/

SQL> Create table sferas of sfera; 

SQL> Insert into sferas values(4); 

SQL> select value(a).tilpums(radius) from sferas a; 

VALUE(A).TILPUMS(RADIUS)               
------------------------               
       267,946667               
+0

謝謝,會嘗試這一點。這是我的額外任務,我不清楚我必須遵守的規則。 – user3215354

+0

解決方案已被接受,但我仍然想知道如何在沒有此解決方法的情況下執行此操作。 – user3215354