2012-11-13 2 views
0

나는 다음과 같은 유형이 있습니다는 PLS-00382 표현은 잘못된 유형입니다 던졌습니다

CREATE OR REPLACE TYPE num_t AS OBJECT 
(
    c1 number, 
    MAP MEMBER FUNCTION sort_key RETURN VARCHAR2 
) 
CREATE OR REPLACE TYPE BODY num_t AS 
    MAP MEMBER FUNCTION sort_key RETURN VARCHAR2 IS 
    BEGIN 
     RETURN c1; 
    END; 
END; 

다음과 같이 내 패키지를 정의

CREATE OR REPLACE TYPE num_tab AS TABLE OF num_t 

를 :

create or replace package test_package is 

    type t_test is table of number index by binary_integer; 
    test_empty_array t_test; 

    procedure test_proc(cur_out out sys_refcursor); 

    function test_fn(i_test in t_test) return num_tab; 

end test_package; 

create or replace package body test_package is 

    procedure test_proc(cur_out out sys_refcursor) is 
    i_test t_test := test_empty_array; 
    begin 
    open cur_out for 
     select * from table(test_fn(i_test)); 

    end; 

    function test_fn(i_test in t_test) return num_tab is 
    v_results num_tab; 
    begin 
    for i in i_test.first .. i_test.last loop 
     v_results.extend; 
     v_results(i) := num_t(c1 => i_test(i)); 
    end loop; 

    return v_results; 
    end; 

end test_package; 

나는 이것을 컴파일하려고하면, 나는 다음과 같은 오류를 얻을 :

Error: PLS-00382: expression is of wrong type 
Line: 7 
Text: select * from table(test_fn(i_test)); 

Error: PLS-00306: wrong number or types of arguments in call to 'TEST_FN' 
Line: 7 
Text: select * from table(test_fn(i_test)); 

Error: PL/SQL: ORA-00904: "TEST_PACKAGE"."TEST_FN": invalid identifier 
Line: 7 
Text: select * from table(test_fn(i_test)); 

Error: PL/SQL: SQL Statement ignored 
Line: 7 
Text: select * from table(test_fn(i_test)); 

저에게는 효과가있는 것처럼 보입니다. 어떤 아이디어?

답변

4

정상이며 예상됩니다. SQL에서 사용되는 함수는 SQL 데이터 유형만을 참조 할 수 있습니다 (예 : 부울 데이터 유형이있는 경우 오류가 발생 함).

패키지에 숨길 수 : first..last 빈의 경우 실패로

create or replace package test_package is 

    type t_test is table of number index by binary_integer; 
    test_empty_array t_test; 

    procedure test_proc(cur_out out sys_refcursor); 

    function test_fn(i_test in t_test) return num_tab; 

end test_package; 
/
create or replace package body test_package is 

    procedure test_proc(cur_out out sys_refcursor) is 
    i_test t_test := test_empty_array; 
    t_num num_tab; 
    begin 
    t_num := test_fn(i_test); 
    open cur_out for 
     select * from table(t_num); 

    end; 

    function test_fn(i_test in t_test) return num_tab is 
    v_results num_tab := num_tab(); 
    begin 
    for i in 1..i_test.count loop 
     v_results.extend; 
     v_results(i) := num_t(c1 => i_test(i)); 
    end loop; 

    return v_results; 
    end; 

end test_package; 
/

내가 또한

v_results num_tab := num_tab(); 

for 1..i_test.count loop 

불통 배열 (숫자 오류)

예 : 일부 데이터 :

SQL> create or replace package body test_package is 
    2 
    3 procedure test_proc(cur_out out sys_refcursor) is 
    4  i_test t_test; 
    5  t_num num_tab; 
    6 begin 
    7  i_test(1) := 1; 
    8  i_test(2) := 3; 
    9  t_num := test_fn(i_test); 
10  open cur_out for 
11  select * from table(t_num); 
12 
13 end; 
14 
15 function test_fn(i_test in t_test) return num_tab is 
16  v_results num_tab := num_tab(); 
17 begin 
18  for i in 1..i_test.count loop 
19  v_results.extend; 
20  v_results(i) := num_t(c1 => i_test(i)); 
21  end loop; 
22 
23  return v_results; 
24 end; 
25 
26 end test_package; 
27/

Package body created. 

SQL> exec test_package.test_proc(:c) 

PL/SQL procedure successfully completed. 

SQL> print c 

     C1 
---------- 
     1 
     3 

SQL> 
+0

감사합니다. –

관련 문제