CURSOR不显示数据/结果集

时间:2014-06-04 01:39:49

标签: sql oracle plsql jasper-reports

我已尽力而为,但仍然无法让cursor显示数据。这是我的代码:

DECLARE 

CURSOR SL_Cur IS
    select *
    from (
        select
            cdav.bank_id,
            ent.bank_desc Bank_Description,
            cdav.sol_id,
            sol.sol_desc SOL_Description,
            cdav.gl_sub_head_code GLSH_Code,
            decode(cdav.gl_sub_head_code,
                '10301',1,
                '10403',2, '60403',2, '10501',2, '60501',2, '10502',2, 
                '10503',2, '10504',2, '10505',2, '10507',2, '10509',2, 
                '60509',2, '10511',2, '10518',2, '60518',2, '10523',2, 
                '60523',2, '10551',2, '10552',2, '10553',2, '10554',2, 
                '10555',2, '10557',2, '10559',2, '10561',2, '10568',2, 
                '10573',2,
                '12336',3, '62336',3, '10401',3, '60402',3, 4 ) GLSH_SET ,
            gsh.gl_sub_head_desc GLSH_Name,
            case
                when (cast(substr(cdav.gl_sub_head_code,0,1) as int) >= 1
                    and cast(substr(cdav.gl_sub_head_code,0,1) as int) <= 5)
                then 'R'
                when cast(substr(cdav.gl_sub_head_code,0,1) as int) = 0
                    or (cast(substr(cdav.gl_sub_head_code,0,1) as int) >= 6
                    and cast(substr(cdav.gl_sub_head_code,0,1) as int) <= 9)
                then 'F'
            end book_type,
            gam.foracid account_number,
            gam.acct_name,
            cdav.tran_crncy_code Tran_Currency,
            cdav.value_date,
            cdav.tran_date Transaction_Date,
            cdav.gl_date,
            cdav.tran_particular,
            rank() over(partition by gam.foracid order by eab.eod_date desc) eod_date_rank,
            eab.eod_date,
            case when
                (select tran_date_bal from tbaadm.eab
                    where eab.eod_date = (select max(eab.eod_date) from tbaadm.eab
                        where cdav.acid = eab.acid and eab.eod_date < '28-MAY-2013')
                    and cdav.acid = eab.acid
                    and cdav.bank_id = eab.bank_id) is not null
                then (select tran_date_bal from tbaadm.eab
                    where eab.eod_date = (select max(eab.eod_date) from tbaadm.eab
                        where cdav.acid = eab.acid and eab.eod_date < '28-MAY-2013')
                    and cdav.acid = eab.acid
                    and cdav.bank_id = eab.bank_id)
                else 0
            end beg_tran_date_bal,
            (select tran_date_bal from tbaadm.eab eab
                where eod_date = (select max(eab.eod_date) from tbaadm.eab eab
                    where cdav.acid = eab.acid and eab.eod_date <= '28-MAY-2013')
                and cdav.acid = eab.acid
                and cdav.bank_id = eab.bank_id) end_tran_date_bal,
            ott.ref_num OAP_Ref_No,
            trim(cdav.tran_id) Transaction_ID,
            --cdav.dth_init_sol_id Initiating_SOL_ID,
            'PCC_Code',
            cdav.tran_rmks Tran_Remarks,
            case
                when (cdav.part_tran_type = 'D')
                then (cdav.tran_amt)
            end dr_amount,
            case
                when (cdav.part_tran_type = 'C')
                then (cdav.tran_amt)
            end cr_amount

        from tbaadm.ctd_dtd_acli_view cdav
            left outer join tbaadm.gam
                on cdav.bank_id = gam.bank_id and cdav.acid = gam.acid
            left outer join tbaadm.gsh
                on gam.bank_id = gsh.bank_id and gam.sol_id = gsh.sol_id
                and gam.gl_sub_head_code = gsh.gl_sub_head_code
                and gam.acct_crncy_code = gsh.crncy_code
            left outer join tbaadm.sol
                on cdav.bank_id = sol.bank_id and cdav.sol_id = sol.sol_id
            left outer join tbaadm.eab
                on gam.bank_id = eab.bank_id and gam.acid = eab.acid
            left outer join tbaadm.cnc
                on gam.bank_id = cnc.bank_id and gam.acct_crncy_code = cnc.crncy_code
            left outer join crmuser.end ent
                on cdav.bank_id = ent.bank_id
            left outer join tbaadm.gct
                on cdav.bank_id = gct.bank_id
            left outer join tbaadm.ott
                on cdav.tran_id = ott.tran_id and cdav.tran_date = ott.tran_date
                and cdav.part_tran_srl_num = ott.part_tran_srl_num
                and cdav.bank_id = ott.bank_id and cdav.acid = ott.acid

        where
            gam.acct_ownership = 'O'
            and cdav.bank_id = 'CBC01'
            and cdav.gl_date = '28-MAY-2013'
            and (gam.gl_sub_head_code in ('10301','10403','60403',
                '10501','60501','10502','10503','10504','10505',
                '10507','10509','60509','10511','10518','60518',
                '10523','60523','10551','10552','10553','10554',
                '10555','10557','10559','10561','10568','10573',
                '12336','62336','10401','60402')

                or gam.acct_classification_flg in ('I','E')
                )
            and trim(cdav.del_flg) in ('N', null)
            and trim(gam.del_flg) in ('N', null)
            and trim(gsh.del_flg) in ('N', null)
            and trim(sol.del_flg) in ('N', null)
            and trim(cnc.del_flg) in ('N', null)
            and trim(gct.del_flg) in ('N', null)
    )

    where
        eod_date_rank = 1
        and GLSH_SET = 1

    order by
        bank_id,
        sol_id,
        tran_currency,
        glsh_code,
        book_type desc,
        account_number,
        transaction_date;

  in_sl_rec SL_Cur%ROWTYPE;

BEGIN

open SL_Cur;

LOOP
    FETCH SL_Cur INTO in_sl_rec;


    exit when SL_Cur%notfound;
END LOOP;

close SL_Cur;

END;

首先,我只需要让CURSOR显示我想要查看的结果集。接下来,我想将光标变为某种FOR LOOP,因为在iReport执行代码时会涉及输入参数,主要是日期范围。

1 个答案:

答案 0 :(得分:1)

游标执行时不只是“显示” - 你必须编写一些代码才能执行此操作。请尝试在exit when SL_Cur%notfound;之后和END LOOP;

之前的循环中添加以下行
DBMS_OUTPUT.PUT_LINE('BANK_ID=' || in_sl_rec.BANK_ID ||
                     'Bank_Description=' || in_sl_rec.Bank_Description ||
                     'sol_id=' || in_sl_rec.sol_id ||
                     'SOL_Description=' || in_sl_rec.SOL_Description);

您可以根据需要添加更多字段。

分享并享受。