【问题标题】:Oracle Data Miner - Simplify Oracle R Enterprise interfaceOracle Data Miner - 简化 Oracle R Enterprise 界面
【发布时间】:2016-03-23 09:16:33
【问题描述】:

我需要将 Oracle SQL 接口简化为 Oracle R Enterprise,以便用户对其他用户更容易听到。

例如,通过调用 R 函数“R_ONE_SAMPLE_T_TEST”来计算 One Sample T-Test,我以原始方式运行以下 SSQ 语句:

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 
)
)

我希望我可以通过以下语句来简化它:

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: invalid datatype for the table type one_sample_t_test_table 已经在包头中定义。

我该如何解决这个问题?

谢谢。

【问题讨论】:

    标签: sql r oracle interface enterprise


    【解决方案1】:

    只有 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      相关资源
      最近更新 更多