2013-04-26 161 views
2

我有一個包含一個函數的包,如下所示,它需要其中一個參數是數組。無法調用Oracle函數

create or replace PACKAGE selected_pkg IS 

TYPE NUM_ARRAY IS TABLE OF NUMBER; 

FUNCTION get_selected_kml(
    in_layer  IN NUMBER, 
    in_solm_id  IN NUMBER, 
    in_feature_ids IN NUM_ARRAY, 
    in_lx   IN NUMBER, 
    in_ly   IN NUMBER, 
    in_ux   IN NUMBER, 
    in_uy   IN NUMBER) 
RETURN CLOB; 

END selected_pkg; 

現在我想從下面的匿名塊調用函數:

declare 
    result CLOB; 
    TYPE NUM_ARRAY1 IS TABLE OF NUMBER; 
    myarray NUM_ARRAY1 := NUM_ARRAY1(); 
begin 
    myarray.extend(3); 
    myarray(1) := 1; 
    myarray(2) := 5; 
    myarray(3) := 9; 
    EXECUTE IMMEDIATE 'truncate table demoresult'; 
    result:=SELECTED_PKG.get_selected_kml(103, 19, myarray, 4.11, 56.27, 4.59, 56.39); 
    insert into demoresult values(result); 
    COMMIT; 
end; 

我收到錯誤

PLS-00306: wrong number or types of arguments in call to 'GET_SELECTED_KML'

可能有人請建議我,我究竟做錯了什麼?

感謝, Alankar

+2

同一陣列類型你基本上打[該數據兼容性限制(http://docs.oracle的.com/CD/E11882_01/appdev.112/e25519/composites.htm#autoId15);雖然您的集合類型具有相同的元素類型,但它們不被視爲等同。所以你試圖用不同類型的函數調用它所期望的函數。正如Justin的答案所示,您必須使用完全相同的集合類型。 – 2013-04-26 10:56:53

回答

4

您需要使用您的函數需要

declare 
    result CLOB; 
    myarray selected_pkg.num_array := selected_pkg.num_array(); 
begin 
    myarray.extend(3); 
    myarray(1) := 1; 
    myarray(2) := 5; 
    myarray(3) := 9; 
    EXECUTE IMMEDIATE 'truncate table demoresult'; 
    result:=SELECTED_PKG.get_selected_kml(103, 19, myarray, 4.11, 56.27, 4.59, 56.39); 
    insert into demoresult values(result); 
    COMMIT; 
end; 
+0

感謝賈斯汀,讓它工作! – AlanShar 2013-04-26 11:38:57

+0

如果我使用類似下面的東西,那麼我也會得到錯誤: 聲明 結果CLOB; myarray selected_pkg.num_array:= selected_pkg.num_array(); begin myarray.extend(3); myarray(1):= 1; myarray(2):= 5; myarray(3):= 9; EXECUTE IMMEDIATE'select table_value from table(cast(myarray AS selected_pkg.num_array))'; COMMIT; 結束; 請建議。 謝謝, Alan – AlanShar 2013-04-26 12:02:19