2017-10-11 69 views
0

我試圖打電話與在包範圍定義的表類型參數的功能,但得到的錯誤:PLS-00306:錯號碼或類型的呼叫「好玩」的論點

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

CREATE OR REPLACE PACKAGE pkg AS 
    TYPE aging_sch_record_type IS 
     RECORD (days_delq NUMBER, eligible NUMBER, unit NUMBER, balance NUMBER); 
    TYPE aging_sch_table_type IS 
     TABLE OF aging_sch_record_type INDEX BY VARCHAR2(20); 

    PROCEDURE proc(); 
    FUNCTION fun (v_aging_sch_table aging_sch_table_type, 
     v_days_delq NUMBER, v_eligible NUMBER) RETURN NUMBER; 
END pkg; 

create or replace PACKAGE BODY pkg AS 
    PROCEDURE proc() AS 
     CURSOR aging_sch_cursor IS 
     SELECT ... 
     GROUP BY ...; 

     v_aging_sch_row aging_sch_cursor%rowtype; 
     v_aging_sch_table aging_sch_table_type; 
    BEGIN 
     FOR v_aging_sch_row IN aging_sch_cursor LOOP 
      v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).days_delq := v_aging_sch_row.days_delq; 
      v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).eligible := v_aging_sch_row.eligible; 
      v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).unit := v_aging_sch_row.unit; 
      v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).balance := v_aging_sch_row.balance; 
     END LOOP; 

     INSERT INTO t 
     VALUES (fun(v_aging_sch_table,0,2)); 
    END proc; 

    FUNCTION fun (v_aging_sch_table aging_sch_table_type, 
     v_days_delq NUMBER, v_eligible NUMBER) RETURN NUMBER 
     AS 
    BEGIN 
     ... 
    END fun; 
END pkg; 

有什麼想法是什麼問題?

謝謝。

+0

錯誤是哪一行? – Tenzin

回答

0

不能使用在SQLassociative array(你不能使用在之前12C的Oracle版本SQL在包規範中聲明的任何陣列),但你可以存儲結果fun功能分爲局部變量,然後插入可變進表t

PROCEDURE proc() AS 
    CURSOR aging_sch_cursor IS 
    SELECT ... 
    GROUP BY ...; 

    v_aging_sch_row aging_sch_cursor%rowtype; 
    v_aging_sch_table aging_sch_table_type; 
    v_fun number; 
BEGIN 
    FOR v_aging_sch_row IN aging_sch_cursor LOOP 
     v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).days_delq := v_aging_sch_row.days_delq; 
     v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).eligible := v_aging_sch_row.eligible; 
     v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).unit := v_aging_sch_row.unit; 
     v_aging_sch_table(v_aging_sch_row.days_delq || ' ' || v_aging_sch_row.eligible).balance := v_aging_sch_row.balance; 
    END LOOP; 

    v_fun := fun(v_aging_sch_table,0,2) 
    INSERT INTO t 
    VALUES (v_fun); 
END proc; 

此外,您要插入的功能分爲表t的結果不點名列 - 這是否表實際上是隻有一個列?如果沒有,你應該命名每列要在其中插入數據,如:

INSERT INTO t (COLUMN1) 
VALUES (v_fun); 

如果你不是字符串索引,你也可以使用這將在SQL工作過獨立的對象類型和嵌套表,但在你的情況下,這不是一個選項。