我想简单地使用Oracle R Enterprise的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;
其次,我使用pipelined函数返回表对象。
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:在FETCH光标和INTO变量之间的'V_STS_ONE_SAMPLE_T_TEST'中找到类型不匹配
请帮帮我。
答案 0 :(得分:1)
我找到了解决方案。
我没有使用fetch到对象类型,而是显式地获取每个对象元素。
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%)" ;
传递错误,但运行时函数进入无限循环。