2009-12-21 29 views
0

這裏是PostgreSQL的,我面臨着最後幾天的問題:使用 選擇usage_rep_sp.get_result(「2009-01-01」,「2009-12-01」)FULL_NAME問題與返回的記錄

來自雙重;下面 包設返回大量的記錄((至少5個不同的名字) 但是它返回只有一個

從iReports它給我的錯誤信息: 產生的原因:org.postgresql.util.PSQLException :ERROR:光標「()」不存在;

你能幫我看看這些問題

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

這是相當傾倒。嘗試重新格式化;選擇並使用Ctrl-K。 – Tobu

回答

2

我不知道你用什麼,但這不是PostgreSQL的PostgreSQL沒有? 「dual」(這是Oracle的東西),它沒有PACKAGES,沒有%isopen操作符。實際上沒有理由在函數中使用PostgreSQL中的遊標。 PostgreSQL中沒有varchar2數據類型。

+0

對不起,我感到困惑。它是8.3。 Oracle兼容版Postgresql。 – sfslku

+0

我完全不知道「Oracle兼容版本的PostgreSQL」是什麼。有一些基於Pg的數據庫,內置擴展模擬Oracle - 我認爲它是由EnterpriseDB開發的 - 也許你應該嘗試對它進行支持? – 2009-12-21 22:53:52

0

看起來您正在嘗試將遊標上的聲明和打開組合在一起。我沒有EnterpriseDB,但我從來沒有在Oracle或PostgreSQL上看到過。您可能需要聲明遊標,然後打開它。

+0

不幸的是,即使我在雙精度 , 的選擇usage_rep_sp.get_usage_rep(p_start_date,p_end_date)中爲mycursor動態地聲明瞭遊標 ,它也無關緊要。結果是一樣的。 – sfslku

+0

您正在獲取遊標不存在的錯誤。嘗試定義光標時會出現什麼錯誤,然後嘗試打開它?這些消息可能會導致對停止第一種格式的錯誤的啓示。 –