我在执行存储过程以取回结果时遇到问题。目前,我想在toad
,eclipse
的输出窗口中显示结果,或者我将要使用的任何其他结果。稍后,我想从程序中访问它们。现在忽略程序部分,除非它是必需的。从存储过程或函数获取结果
我有这个存储过程的代码:
create or replace procedure pottyuserange (p_date_format in varchar2,
p_start_date in varchar2,
p_end_date in varchar2,
p_ref_cursor out sys_refcursor)
as
begin
open p_ref_cursor for
select to_char(time_range, p_date_format) as current_date,
lm_search,
ao_search,
ro_search,
fl_search,
total
from (select trunc(time_range) time_range,
sum(case when porta_potty = 'LM' then 1 else 0 end) as lm_search,
sum(case when porta_potty = 'AO' then 1 else 0 end) as ao_search,
sum(case when porta_potty = 'RO' then 1 else 0 end) as ro_search,
sum(case when porta_potty = 'FL' then 1 else 0 end) as fl_search,
sum(case when porta_potty in ('LM', 'AO', 'RO', 'FL') then 1 else 0 end) as total
from core.date_test
where trunc(time_range) >= to_date(p_start_date, p_date_format)
and trunc(time_range) <= to_date(p_end_date, p_date_format)
group by trunc(time_range))
order by time_range asc;
end pottyuserange;
/
而且我试图得到这样的结果:
variable rc refcursor;
BEGIN
pottyuserange('YYYY-MM-DD', '2008-10-1', '2010-10-12', :rc);
END;
print rc;
这是我得到的错误:
ORA-01722: invalid number
ORA-06512: at "core.pottyuserange", line 4
ORA-06512: at line 1
我该如何正确地访问这些数据,或将它变成User-Defined Function
? \
这是我在把它变成一个功能的尝试:
create or replace function pottyuserange (p_date_format in varchar2,
p_start_date in varchar2,
p_end_date in varchar2)
return result_set as rc sys_refcursor;
BEGIN
OPEN result_set FOR
select to_char(time_range, p_date_format) as current_date,
lm_search,
ao_search,
ro_search,
fl_search,
total
from (select trunc(time_range) time_range,
sum(case when porta_potty = 'LM' then 1 else 0 end) as lm_search,
sum(case when porta_potty = 'AO' then 1 else 0 end) as ao_search,
sum(case when porta_potty = 'RO' then 1 else 0 end) as ro_search,
sum(case when porta_potty = 'FL' then 1 else 0 end) as fl_search,
sum(case when porta_potty in ('LM', 'AO', 'RO', 'FL') then 1 else 0 end) as total
from core.date_test
where trunc(time_range) >= to_date(p_start_date, p_date_format)
and trunc(time_range) <= to_date(p_end_date, p_date_format)
group by trunc(time_range))
order by time_range asc;
return result_set;
end pottyuserange;
/
我与上面得到的错误是:PLS-00201: identifier 'RESULT_SET' must be declared
编辑:TIME_RANGE
是DATE
。 PORTA_POTTY
是一个varchar2。
,然后创建一个用户定义的函数,而不是一个存储过程。 –
我更新了问题。我将如何将其转换为用户定义的函数?我一直在摆弄这个,但我没有运气。我会用我试过的东西来更新这篇文章。 –
涉及的数据类型是什么?除非您的代码正在进行某种隐式转换,否则您得到的错误似乎没有多大意义。但是这种转换不会是明显的。我猜''time_range'是'date' –