2016-03-23 6 views
1

Oracle SQLインタフェースをOracle R Enterpriseに簡素化して、他のユーザーに対してユーザーにはより敏感にする必要があります。私は次の文で、それを簡略化することができます願っていOracle Data Miner - Oracle Rエンタープライズ・インタフェースの簡素化

select * 
from 
table 
(
rqTableEval(
    cursor 
    (
    select * 
    from "INSUR_CUST_LTV_SAMPLE" 
), -- Input Cursor 
    cursor 
    (
    select 10 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 
) 
) 

たとえば、元のように私はSSQ文の次に実行している、「R_ONE_SAMPLE_T_TEST」Rのfuncitonを呼び出すことにより、1つの標本t検定を計算します:

select * 
from table 
(
    pkg_one_sample_t_test.f_run 
    (
     cursor(select * from "INSUR_CUST_LTV_SAMPLE"), 
     10 -- Target number 
    ) 
) 

だから私は、パッケージpkg_one_sample_t_testを書いた:

create or replace package pkg_one_sample_t_test as 

    type one_sample_t_test is record 
    (
      "Variable Name" varchar2(4000), 
      "Average" number, 
      "T-Test" number, 
      "P-Value" number, 
      "Con.Level Lower Bound (95%)" number, 
      "Con.Level Upper Bound (95%)" number 
    ); 

    type one_sample_t_test_table is table of one_sample_t_test; 

    function f_run 
    (
     p_data in sys_refcursor, 
     target_number in number 
    ) 
    return one_sample_t_test_table pipelined; 

end pkg_one_sample_t_test; 


create or replace package body pkg_one_sample_t_test as 

    function f_run 
    (
     p_data in sys_refcursor, 
     target_number in number 
    ) 
    return one_sample_t_test_table pipelined 
    is 
      v_one_sample_t_test one_sample_t_test; 
--   cursor v_cursor is 
--   select 'a', 1, 1,1, 1, 1 from dual; 
      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 
         one_sample_t_test_table ----PL/SQL: ORA-00902: invalid datatype 
       ) 
     ); 

    begin 
      open v_cursor; 
      loop 
       fetch v_cursor into v_one_sample_t_test; 
       exit when v_cursor%notfound; 
       pipe row(v_one_sample_t_test); 
      end loop; 
      close v_cursor; 
      return; 
    end; 

end pkg_one_sample_t_test; 

しかし、コンパイラはPL/SQLエラーを返します。ORA-00902:パッケージ・ヘッダー内ですでに定義されている表タイプone_sample_t_test_tableのデータ型が無効です。

どうすればこの問題を解決できますか?

ありがとうございます。

答えて

0

Oracle 12cのみでは、SQL文でパッケージ・タイプにアクセスできます。以前のバージョンでは、以下のようなスキーマオブジェクトとしてそれらの型を作成する必要があります。 SQL文はPL/SQLパッケージ内でのみ使用されますが、実行するとSQL文で実行され、PL/SQLパッケージ・タイプにはアクセスできません。

create or replace type 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 one_sample_t_test_table is table of one_sample_t_test; 
関連する問題