2016-03-25 8 views
1

Oracle R EnterpriseへのSQLインタフェースを使用したいとします。PL/SQL:パイプライン・テーブル関数からカーソルをフェッチするときにタイプが一致しない

まず、タイプからグローバルオブジェクトタイプとテーブルタイプを作成します。

create or replace type sts_one_sample_t_test is object 
(
    "Variable Name" varchar2(4000), 
    "Average" number, 
    "T-Test" number, 
    "P-Value" number, 
    "Con.Level Lower Bound (95%)" number, 
    "Con.Level Upper Bound (95%)" number 
); 

create or replace type sts_one_sample_t_test_table is table of sts_one_sample_t_test; 

次に、テーブルオブジェクトを返すパイプライン関数を作成します。

create or replace function f_sts_one_sample_t_test 
    (p_data in sys_refcursor, 
     target_number in number) 
    return sts_one_sample_t_test_table pipelined 
is 
    v_sts_one_sample_t_test sts_one_sample_t_test; 
    cursor v_cursor is 
     select * 
     from table (
      cast(
       rqTableEval(
         p_data, 
         cursor 
         (
         select target_number as "target_number", 
           1 as "ore.connect" 
         from dual 
        ), -- Param Cursor 
         'select str_col as "Variable Name", 
           num_col as "Average", 
           num_col as "T-Test", 
           num_col as "P-Value", 
           num_col as "Con.Level Lower Bound (95%)", 
           num_col as "Con.Level Upper Bound (95%)" 
         from RQSYS.RQ_TEMP 
         WHERE ROWNUM=1', -- Output Definition 
         'R_ONE_SAMPLE_T_TEST' -- R Script 
       ) as sts_one_sample_t_test_table 
      ) 
    ); 
begin 
    v_sts_one_sample_t_test:=sts_one_sample_t_test(null,null,null,null,null,null); 
    open v_cursor; 
    loop 
     fetch v_cursor into v_sts_one_sample_t_test;  --- [Error] PLS-00386 (49: 17): PLS-00386: type mismatch found at 'V_STS_ONE_SAMPLE_T_TEST' between FETCH cursor and INTO variables 
     exit when v_cursor%notfound; 
     pipe row(v_sts_one_sample_t_test); 
    end loop; 
    close v_cursor; 
    return; 
end f_sts_one_sample_t_test; 

しかし、エラーがコンパイラから発生します

[エラー] PLS-00386(49:17):PLS-00386:カーソルを取得し、変数

INTO間の 'V_STS_ONE_SAMPLE_T_TEST' で見られるタイプの不一致

私を助けてください。

答えて

1

解決策が見つかりました。

オブジェクト型にフェッチするのではなく、各オブジェクト要素に明示的にフェッチします。

fetch v_cursor into 
     v_sts_one_sample_t_test."Variable Name" , 
     v_sts_one_sample_t_test. "Average" , 
     v_sts_one_sample_t_test."T-Test" , 
     v_sts_one_sample_t_test."P-Value" , 
     v_sts_one_sample_t_test."Con.Level Lower Bound (95%)" , 
     v_sts_one_sample_t_test."Con.Level Upper Bound (95%)" ; 

エラーは発生しますが、実行中は無限ループになります。

関連する問題