这是我过去几天遇到的Postgresql的问题:
使用 从dual中选择usage_rep_sp.get_result('2009-01-01','2009-12-01')full_name; 下面的包假设返回一些记录((至少5个不同的名字) 但它只返回一个。
从iReports它给我错误信息: 引起:org.postgresql.util.PSQLException:错误:游标“()”不存在;
你能帮我解决这些问题吗?
CREATE OR REPLACE PACKAGE usage_rep_sp
IS
type usage_type is record (
full_name varchar2(50));
--
type srr_rec is ref cursor return usage_type;
type mycursor is ref cursor;
function get_usage_rep(p_start_date timestamp without time zone,
p_end_date timestamp without time zone)
return srr_rec;
function get_result(p_start_date timestamp without time zone, p_end_date timestamp without time zone) return mycursor;
END usage_rep_sp;
CREATE OR REPLACE PACKAGE BODY usage_rep_sp
IS
function get_usage_rep
(p_start_date timestamp without time zone, p_end_date timestamp without time zone)
return srr_rec
is
v_report srr_rec;
v_temp varchar2(50):=' ';
v_aff_level varchar2(30);
commapos number ;
outstring varchar2(50) := upper(v_temp) ;
vquery varchar2(3200);
whereclause varchar2(3200);
begin
if v_temp =' ' or v_temp is null then
whereclause := 'and u.affiliate_id in (select aff_id from ultra_affiliate)';
else
for index_var in 1..50
loop
commapos := instr(outstring,',',1,index_var) ;
exit when commapos=0 ;
outstring := substr(outstring,1,(commapos-1))||''','''|| substr(outstring,(commapos+1));
end loop ;
--outstring := '('''||outstring||''')' ;
v_temp := outstring ;
if v_aff_level= 'COUNCIL' then
whereclause := 'and u.affiliate_id in (select aff_id from ultra_affiliate where council_id = '''|| v_temp ||''')';
elsif v_aff_level = 'DISTRICT' then
whereclause := 'and u.affiliate_id in (select aff_id from ultra_affiliate where district = '''|| v_temp ||''')';
elsif v_aff_level= 'LOCAL' then
whereclause := 'and u.affiliate_id in (select aff_id from ultra_affiliate where aff_id = '''|| v_temp ||''')';
end if;
end if;
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >= '''|| p_start_date|| ''' and s.login <= '''|| p_end_date|| ''' '
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end get_usage_rep;
function get_result(p_start_date timestamp without time zone, p_end_date timestamp without time zone) return mycursor
is
mycursor usage_rep_sp.srr_rec;
myrec usage_rep_sp.usage_type;
begin
select usage_rep_sp.get_usage_rep(p_start_date, p_end_date)
into mycursor from dual;
if mycursor%isopen then
loop
fetch mycursor into myrec;
exit when mycursor%notfound;
end loop;
close mycursor;
end if;
return myrec;
end get_result;
END usage_rep_sp;
答案 0 :(得分:2)
我不知道你使用的是什么,但这不是PostgreSQL。 PostgreSQL没有“双重”(它是Oracle的东西)。它没有包装。没有%isopen运算符。几乎没有理由在函数中使用PostgreSQL中的游标。 PostgreSQL中没有varchar2数据类型。
答案 1 :(得分:0)
您似乎正在尝试将声明和开放组合在光标上。我没有EnterpriseDB,但我从来没有在Oracle或PostgreSQL上看过这个。您可能需要声明光标,然后将其打开。