使用 SYS_REFCURSOR OUT 调用过程

Posted

技术标签:

【中文标题】使用 SYS_REFCURSOR OUT 调用过程【英文标题】:call procedure with SYS_REFCURSOR OUT 【发布时间】:2014-09-16 06:20:47 【问题描述】:

我的数据库中有以下过程,编译时没有任何错误:

create or replace procedure itcustadm.TEST_PROC_AJCP_1
(
    sldr_indate   in date,
    r18_refcursor out sys_refcursor
)
as begin

open r18_refcursor for

select
    gthv.bank_id,
    gthv.sol_id,
    gthv.gl_sub_head_code GLSH_Code,
    decode(gthv.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, 
    case
        when (cast(substr(gthv.gl_sub_head_code,0,1) as int) >= 1
            and cast(substr(gthv.gl_sub_head_code,0,1) as int) <= 5)
        then 'R'
        when cast(substr(gthv.gl_sub_head_code,0,1) as int) = 0
            or (cast(substr(gthv.gl_sub_head_code,0,1) as int) >= 6
            and cast(substr(gthv.gl_sub_head_code,0,1) as int) <= 9)
        then 'F'
    end book_type,
    gthv.tran_crncy_code Tran_Currency,
    gthv.value_date,
    gthv.tran_date Transaction_Date,
    gthv.gl_date,
    gthv.tran_particular,
    trim(gthv.tran_id) Transaction_ID,
    gthv.dth_init_sol_id Posting_SOL,
    gthv.tran_rmks Tran_Remarks,
    case
        when (gthv.part_tran_type = 'D')
        then (gthv.tran_amt)
    end dr_amount,
    case
        when (gthv.part_tran_type = 'C')
        then (gthv.tran_amt)
    end cr_amount,
    gsh.gl_sub_head_desc GLSH_Name,
    gam.foracid account_number,
    gam.acct_name,
    case when
       (select tran_date_bal from tbaadm.eab
           where eab.eod_date = (select max(eab.eod_date) from tbaadm.eab
               where gthv.bank_id = eab.bank_id and gthv.acid = eab.acid and eab.eod_date < '4-NOV-2013')
           and gthv.acid = eab.acid
           and gthv.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 gthv.bank_id = eab.bank_id and gthv.acid = eab.acid and eab.eod_date < '4-NOV-2013')
           and gthv.acid = eab.acid
           and gthv.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 gthv.bank_id = eab.bank_id and gthv.acid = eab.acid and eab.eod_date <= '4-NOV-2013')
        and gthv.acid = eab.acid
        and gthv.bank_id = eab.bank_id) end_tran_date_bal,
    (select ent.bank_desc from crmuser.entity_details ent
        where gam.bank_id = ent.bank_id) bank_description,
    (select crncy_alias_num from tbaadm.cnc where gam.bank_id = cnc.bank_id
        and cnc.crncy_code = gam.acct_crncy_code) currency_no,
    (select sol.sol_desc from tbaadm.sol where gthv.bank_id = sol.bank_id
        and gthv.sol_id = sol.sol_id) SOL_Description,
    ott.ref_num OAP_Ref_No,
    crp.pcc_code,
    crp.mop_id

from itcustadm.gl_tran_hist_view gthv
    left outer join tbaadm.gam
        on gthv.bank_id = gam.bank_id and gthv.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.ott
        on gthv.tran_id = ott.tran_id and gthv.tran_date = ott.tran_date
        and gthv.part_tran_srl_num = ott.part_tran_srl_num
        and gthv.bank_id = ott.bank_id and gthv.acid = ott.acid
    left outer join custom.c_REPRINT crp
        on gthv.bank_id = crp.bank_id and gthv.tran_date = crp.tran_date
        and trim(gthv.tran_id) = trim(crp.tran_id)

where
    gam.acct_ownership = 'O'
    and gthv.bank_id = 'CBC01'
    and gthv.gl_date = sldr_indate
    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(gthv.del_flg) != 'Y' or gthv.del_flg is null)
    and (trim(gam.del_flg) != 'Y' or gam.del_flg is null)
    and (trim(gsh.del_flg) != 'Y' or gsh.del_flg is null);
end;

我想要做的是以某种方式调用 Toad 中的过程,因为我想测试输入日期是否已通过并且输出是否是我所期望的。这是我到目前为止所拥有的:

begin
    TEST_PROC_AJCP_1( '4-NOV-2013' :r18r );
end;

出现Variables弹窗,我将R18R的Type设置为Cursor,点击OK,出现错误:

RA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:

   ) , * & = - + < / > at in is mod remainder not rem =>
   <an exponent (**)> <> or != or ~= >= <= <> and or like like2
   like4 likec as between from using || multiset member
   submultiset
The symbol "," was substituted for "" to continue.

如何使用 Toad 正确调用或执行程序?提前感谢您的帮助。

【问题讨论】:

【参考方案1】:

您只是在调用中的两个参数参数之间缺少一个逗号:

begin
    TEST_PROC_AJCP_1( '4-NOV-2013', :r18r );
end;

您还应该将日期作为日期而不是字符串传递,以避免歧义,例如to_date('4-NOV-2013', 'DD-MON-YYYY')date '2013-11-04'

【讨论】:

GOD-F***ING-DAMMIT... 一个小逗号一直困扰着我 LOL XD 是的,我知道,我需要稍后使用 to_date 函数,但我'我现在只是测试一些东西,看看程序是否按预期工作。非常感谢。

以上是关于使用 SYS_REFCURSOR OUT 调用过程的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 out sys_refcursor 参数执行 oracle 过程?

使用 FOR UPDATE SKIP LOCKED 打开 OUT SYS_REFCURSOR 时出错

SYS_REFCURSOR out 参数 - 运行存储过程失败

在存储过程中使用“out”ref_cursor 调用 Oracle 存储过程

JPA 实体的 Oracle OUT SYS_REFCURSOR 始终为空

无法在实体框架中映射 SYS_REFCURSOR