oracle执行存储过程,如何在包里if执行哪段语句?

因为有旧的数据手工填报在另外一个表,如何在oracle package 里判断执行取那段语句?比如oracle 包如图,当传进来是2025年,执行第一段代码,否则执行下面select 代码

79b9b8232fcec3688be4f7087abfe39a.png包体如:

create or replace package body fr_pkg_data_qin3 is

procedure FR_finance_xjll_QIN3(p_nf number,p_data out fr_pkg_data_qin3.p_cursor)

is

begin  

 open p_data for

  if p_nf=2025 then 

  select tc_xjll04,tc_xjll01,sum(tc_xjll03)金额256

       from tc_xjll_fr_qin

       where tc_xjll04=2024--p_nf

       group by tc_xjll04,tc_xjll01;

else 

  select tc_xjll04,tc_xjll01,sum(tc_xjll03)金额256

         from tc_xjll_fr_qin

         where tc_xjll04=2025--p_nf

         group by tc_xjll04,tc_xjll01;

  end if;

end;

end fr_pkg_data_qin3;

FineReport 用户S6544908 发布于 2025-9-14 16:21
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
CD20160914Lv8专家互助
发布于2025-9-14 16:27

类似如下

create or replace package body fr_pkg_data_qin3 is

procedure FR_finance_xjll_QIN3(p_nf number, p_data out fr_pkg_data_qin3.p_cursor)
is
    v_sql varchar2(1000);
    v_year number;
begin  
    if p_nf = 2025 then 
        v_year := 2024;
    else 
        v_year := 2025;
    end if;

    v_sql := 'select tc_xjll04, tc_xjll01, sum(tc_xjll03) as 金额256 ' ||
             'from tc_xjll_fr_qin ' ||
             'where tc_xjll04 = :1 ' ||
             'group by tc_xjll04, tc_xjll01';

    open p_data for v_sql using v_year;

end FR_finance_xjll_QIN3;

end fr_pkg_data_qin3;

  • 2关注人数
  • 19浏览人数
  • 最后回答于:2025-9-14 16:27
    请选择关闭问题的原因
    确定 取消
    返回顶部