/**PageBeginHtml Block Begin **/ /***自定义返回顶部小火箭***/ /*生成博客目录的JS 开始*/ /*生成博客目录的JS 结束*/

存储过程示例

示例1:遍历大量游标数据更新临时表

  1 create or replace procedure pro_yearbal_yjz( startyear in varchar2 /*起始年度*/,
  2                                              oper_account in number,/*制单人*/
  3                                              oper_org in number/*制单机构*/
  4                                             /* v_cur   out pkg_query.cur_query*/ )--返回的结果集
  5 is
  6 
  7   --用于判断临时表是否存在中间变量
  8 /*  TABEXT  VARCHAR2(10);*/
  9   --查询所有语句
 10  /* v_sql VARCHAR2(4000);*/
 11   delete_sql   VARCHAR2(50); --删除临时表记录语句
 12   timetemp date;
 13   jzstandard number;
 14   ybstandard number;
 15   --删表语句
 16 /*  delete_sql VARCHAR2(4000);*/
 17   --建表语句
 18 /*  create_sql VARCHAR2(4000);*/
 19 
 20 ---===============================================================================================================================================
 21 ---========================================   声明: 指标信息  游标  ================================================================================
 22 ---===============================================================================================================================================
 23 
 24  CURSOR  zbinfo_loop  IS
 25       select (select u.unit_name from bs_bdg_unit u where u.unitno = z.unitno ) unit_name  ,
 26      (select  zj.fund  from bs_zjly zj where zj.fundno = z.src_id ) src_name ,
 27      (select  (case zj.org_type when '1' then '预算内' else '预算外' end) src_typename  from bs_zjly zj where zj.fundno = z.src_id ) src_typename ,
 28      (select   zj.org_type  from bs_zjly zj where zj.fundno = z.src_id ) src_type ,
 29      (select   pd.dict_text   from pwp_dict p ,pwp_dict_detail pd where p.dict_id=pd.dict_id  and p.dict_name ='budgetType' and pd.dict_value=z.bdgt_id_type  ) bdgt_id_typename ,
 30      ( select  bg.func_bdgname  from bs_gnflyskm bg where bg.func_bdgid = z.budgetno and bg.bdgyear=z.bdgyear and z.budgetid=bg.id) budgetname ,
 31      (select  bx.prj_name from bs_xmk bx where bx.prj_code=z.prj_code  ) prj_codename ,
 32      (select  bj.econ_bdg from bs_jjflyskm bj where bj.bdgyear=z.bdgyear and (  bj.econ_bdgid=z.itemno) )  itemname ,
 33      (select  po.org_name from pwp_org po where po.org_id= z.org_id ) org_name ,
 34      (case z.adjlevel when '0' then '本级' when '1' then '上级'  end ) adjlevel_name ,
 35      (case z.yearbal_status when '0' then '' when '1' then '' end  ) yearbal_name ,
 36      ( select   pd.dict_text   from pwp_dict p ,pwp_dict_detail pd where p.dict_id=pd.dict_id  and p.dict_name ='prjType' and pd.dict_value=z.zb_project_type ) pro_type_name  ,
 37      (case z.fundtype when '1' then '人员经费' when '2' then '公用经费' when '3' then '项目经费' when '4' then '其他经费' end  )  fundtype_name ,
 38       (select  hd.gk_heding_id from gk_yearbal_heding hd where hd.zbz_bal_id= z.id ) heding_id ,
 39  z.*  from  zb_bal z
 40       where z.bdgyear =startyear
 41       order by id ;
 42 
 43 
 44 ---===============================================================================================================================================
 45 ---======================================== 声明:查询(直接支付)支出数   信息的游标     =======================================================
 46 ---===============================================================================================================================================
 47 
 48   CURSOR zjzf_zc_loop  IS
 49 select gz.zbz_bal_id as zjzf_zc_zbid,
 50           to_char(gz.affirm_date, 'yyyy') as zjzf_zc_adutiem,
 51           nvl(sum(gz.amt), 0) as zjzf_zc
 52      from gk_zfpz gz
 53     where gz.check_status in ('1','2','02') /*正常支付*/
 54       and gz.wf_status = '9' /*审结状态*/
 55       and gz.voucher_type = '0' /*支付凭证类型(直接为'0' */
 56       and to_char(gz.affirm_date, 'yyyy')=startyear
 57     group by gz.zbz_bal_id, to_char(gz.affirm_date, 'yyyy');
 58 
 59 ---===============================================================================================================================================
 60 ---======================================== 声明:查询(直接支付)全额退款   信息的游标     =======================================================
 61 ---===============================================================================================================================================
 62  CURSOR zjzf_qetk_loop  IS
 63 select gz.zbz_bal_id as zjzf_qetk_zbid,
 64           to_char(gz.back_oper_date, 'yyyy') as zjzf_qetk_adutiem,
 65           nvl(sum(gz.amt), 0) as zjzf_qetk
 66      from gk_zfpz gz
 67     where gz.check_status = '2' /*确认全额退款*/
 68       and gz.wf_status = '9' /*审结状态*/
 69       and gz.voucher_type = '0' /*支付凭证类型(直接为'0' */
 70       and to_char(gz.back_oper_date, 'yyyy')=startyear
 71     group by gz.zbz_bal_id, to_char(gz.back_oper_date, 'yyyy');
 72 
 73 ---===============================================================================================================================================
 74 ---======================================== 声明:查询(直接支付)部分退款   信息的游标     =======================================================
 75 ---===============================================================================================================================================
 76  CURSOR zjzf_bftk_loop  IS
 77 select gpr.zbz_bal_id as zjzf_bftk_zbid,
 78           to_char(gpr.collate_date, 'yyyy') as zjzf_bftk_adutiem,
 79           nvl(sum(gpr.amt), 0) as zjzf_bftk
 80      from gk_part_refundment gpr
 81     where gpr.audit_status = '9' /*流程审结状态*/
 82       and gpr.voucher_type = '0' /*支付凭证类型(直接为'0' */
 83       and to_char(gpr.collate_date, 'yyyy')=startyear
 84     group by gpr.zbz_bal_id, to_char(gpr.collate_date, 'yyyy');
 85 
 86 ---===============================================================================================================================================
 87 ---======================================== 声明:查询(直接支付)调整前金额   信息的游标     =======================================================
 88 ---===============================================================================================================================================
 89  CURSOR zcywtz_zjzf_tzq_loop  IS
 90 select gad.df_zba_id as  zcywtz_zjzf_tzq_zbid ,/*调整前指标*/
 91             to_char(ga.create_dt,'yyyy')  as  zcywtz_zjzf_tzq_adutiem ,/*调整前:调整年份*/
 92             sum(gad.balance )as zcywtz_zjzf_tzq  /*调整前:调整金额*/
 93         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
 94              gk_adjust ga /*支出账务调整业务_主表*/
 95        where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
 96         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
 97         and  ga.expenditure_type='0' /* 支出类型(0直接支付,1授权支付) */
 98         and to_char(ga.create_dt ,'yyyy')=startyear
 99    group by  gad.df_zba_id, to_char(ga.create_dt ,'yyyy');
100 
101 
102 ---===============================================================================================================================================
103 ---======================================== 声明:查询(直接支付)调整后金额   信息的游标     =======================================================
104 ---===============================================================================================================================================
105  CURSOR zcywtz_zjzf_tzh_loop  IS
106 select gad.jf_zba_id as zcywtz_zjzf_tzh_zbid ,/*调整后指标*/
107             to_char(ga.create_dt ,'yyyy')  as zcywtz_zjzf_tzh_adutiem ,/*调整后:调整年份*/
108             sum(gad.balance) as zcywtz_zjzf_tzh /*调整后:调整金额*/
109         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
110              gk_adjust ga /*支出账务调整业务_主表*/
111         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
112         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
113         and  ga.expenditure_type='0' /* 支出类型(0直接支付,1授权支付) */
114         and to_char(ga.create_dt ,'yyyy')=startyear
115         group by gad.jf_zba_id  ,to_char(ga.create_dt ,'yyyy');
116 
117 ---===============================================================================================================================================
118 ---======================================== 声明:查询 (授权支付)支出数 信息的游标   ===========================================================
119 ---===============================================================================================================================================
120 
121 
122  CURSOR  sqzf_zc_loop IS
123 select gz.zbz_bal_id as sqzf_zc_zbid,
124           to_char(gz.affirm_date, 'yyyy') as sqzf_zc_adutiem,
125           nvl(sum(gz.amt), 0) as sqzf_zc
126      from gk_zfpz gz
127     where gz.check_status in ('1','2','02') /*正常支付*/
128       and gz.wf_status = '9' /*审结状态*/
129       and gz.voucher_type = '1' /*支付凭证类型(授权支付为'1' */
130       and to_char(gz.affirm_date, 'yyyy')=startyear
131     group by gz.zbz_bal_id, to_char(gz.affirm_date, 'yyyy');
132 
133 
134 ---===============================================================================================================================================
135 ---======================================== 声明:查询 (授权支付)全额退款 信息的游标   ===========================================================
136 ---===============================================================================================================================================
137  CURSOR sqzf_qetk_loop IS
138 select gz.zbz_bal_id as sqzf_qetk_zbid,
139           to_char(gz.back_oper_date, 'yyyy') as sqzf_qetk_adutiem,
140           nvl(sum(gz.amt), 0) as sqzf_qetk
141      from gk_zfpz gz
142     where gz.check_status = '2' /*确认全额退款*/
143       and gz.wf_status = '9' /*审结状态*/
144       and gz.voucher_type = '1' /*支付凭证类型(授权支付为'1' */
145       and to_char(gz.back_oper_date, 'yyyy')=startyear
146     group by gz.zbz_bal_id, to_char(gz.back_oper_date, 'yyyy');
147 
148 
149 ---===============================================================================================================================================
150 ---======================================== 声明:查询 (授权支付)部分退款 信息的游标   ===========================================================
151 ---===============================================================================================================================================
152  CURSOR sqzf_bftk_loop IS
153 select gpr.zbz_bal_id as sqzf_bftk_zbid,
154           to_char(gpr.collate_date, 'yyyy') as sqzf_bftk_adutiem,
155           nvl(sum(gpr.amt), 0) as sqzf_bftk
156      from gk_part_refundment gpr
157     where gpr.audit_status = '9' /*流程审结状态*/
158 
159       and gpr.voucher_type = '1' /*支付凭证类型(授权支付为'1' */
160       and to_char(gpr.collate_date, 'yyyy')=startyear
161     group by gpr.zbz_bal_id, to_char(gpr.collate_date, 'yyyy');
162 
163 
164 ---===============================================================================================================================================
165 ---======================================== 声明:查询 (授权支付)调整前金额 信息的游标   ===========================================================
166 ---===============================================================================================================================================
167  CURSOR zcywtz_sqzf_tzq_loop IS
168 select gad.df_zba_id as  zcywtz_sqzf_tzq_zbid ,/*调整前指标*/
169             to_char(ga.create_dt ,'yyyy')  as  zcywtz_sqzf_tzq_adutiem ,/*调整前:调整年份*/
170             sum(gad.balance )as zcywtz_sqzf_tzq  /*调整前:调整金额*/
171         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
172              gk_adjust ga /*支出账务调整业务_主表*/
173         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
174         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
175         and  ga.expenditure_type='1' /* 支出类型(0直接支付,1授权支付) */
176         and to_char(ga.create_dt ,'yyyy')=startyear
177    group by  gad.df_zba_id, to_char(ga.create_dt ,'yyyy');
178 
179 
180 ---===============================================================================================================================================
181 ---======================================== 声明:查询 (授权支付)全额退款 信息的游标   ===========================================================
182 ---===============================================================================================================================================
183  CURSOR zcywtz_sqzf_tzh_loop IS
184 select gad.jf_zba_id as zcywtz_sqzf_tzh_zbid ,/*调整后指标*/
185             to_char(ga.create_dt ,'yyyy')  as zcywtz_sqzf_tzh_adutiem ,/*调整后:调整年份*/
186             sum(gad.balance) as zcywtz_sqzf_tzh /*调整后:调整金额*/
187         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
188              gk_adjust ga /*支出账务调整业务_主表*/
189         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
190         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
191         and  ga.expenditure_type='1' /* 支出类型(0直接支付,1授权支付) */
192         and  to_char(ga.create_dt ,'yyyy')=startyear
193         group by gad.jf_zba_id  ,to_char(ga.create_dt ,'yyyy');
194 
195 ---===============================================================================================================================================
196 ---======================================== 声明:查询 (一般支付)支出数 信息的游标   ===========================================================
197 ---===============================================================================================================================================
198   CURSOR  ybzf_zc_loop IS
199   select ybzf.zbz_bal_id as ybzf_zc_zbid,
200           to_char(ybzf.checker_date, 'yyyy') as ybzf_adutiem,
201           nvl(sum(ybzf.amt), 0) as ybzf_zc
202      from gk_zfpz ybzf
203      where ybzf.voucher_type ='3'
204      and ybzf.wf_status ='9'
205      and to_char(ybzf.checker_date, 'yyyy')=startyear
206     group by ybzf.zbz_bal_id, to_char(ybzf.checker_date, 'yyyy');
207 
208 
209 ---===============================================================================================================================================
210 ---======================================== 声明:查询 (一般支付)退款金额 信息的游标   ===========================================================
211 ---===============================================================================================================================================
212   CURSOR  ybzf_tk_loop IS
213 select crbd.zbz_bal_id as ybzf_tk_zbid,
214           to_char(crb.checker_date, 'yyyy') as ybzf_tk_adutiem,
215           nvl(sum(crbd.back_amt), 0) as ybzf_tk
216      from  common_req_back_detail crbd,common_req_back crb
217      where crb.id = crbd.common_req_back_id and crb.wf_status ='9'
218      and to_char(crb.checker_date, 'yyyy')=startyear
219     group by crbd.zbz_bal_id, to_char(crb.checker_date, 'yyyy');
220 
221 
222 ---===============================================================================================================================================
223 ---======================================== 声明:查询 (一般支付)调整前金额 信息的游标   ===========================================================
224 ---===============================================================================================================================================
225   CURSOR  zcywtz_ybzf_tzq_loop IS
226 select gad.df_zba_id as  zcywtz_ybzf_tzq_zbid ,/*调整前指标*/
227             to_char(ga.create_dt ,'yyyy')  as  zcywtz_ybzf_tzq_adutiem ,/*调整前:调整年份*/
228             sum(gad.balance )as zcywtz_ybzf_tzq  /*调整前:调整金额*/
229         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
230              gk_adjust ga /*支出账务调整业务_主表*/
231         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
232         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
233         and  ga.expenditure_type='3' /* 支出类型(0直接支付,1授权支付) */
234         and to_char(ga.create_dt ,'yyyy')=startyear
235    group by  gad.df_zba_id, to_char(ga.create_dt ,'yyyy');
236 
237 
238 ---===============================================================================================================================================
239 ---======================================== 声明:查询 (一般支付)调整前金额 信息的游标   ===========================================================
240 ---===============================================================================================================================================
241   CURSOR  zcywtz_ybzf_tzh_loop IS
242 select gad.jf_zba_id as zcywtz_ybzf_tzh_zbid ,/*调整后指标*/
243             to_char(ga.create_dt ,'yyyy')  as zcywtz_ybzf_tzh_adutiem ,/*调整后:调整年份*/
244             sum(gad.balance) as zcywtz_ybzf_tzh /*调整后:调整金额*/
245         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
246              gk_adjust ga /*支出账务调整业务_主表*/
247          where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
248         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
249         and  ga.expenditure_type='3' /* 支出类型(0直接支付,1授权支付) */
250         and to_char(ga.create_dt ,'yyyy')=startyear
251         group by gad.jf_zba_id  ,to_char(ga.create_dt ,'yyyy');
252 
253 ---===============================================================================================================================================
254 ---======================================== 声明:核定表数据   ===========================================================
255 /*---===============================================================================================================================================
256  CURSOR  gk_yearbal_yjz_loop IS
257     select * from gk_yearbal_yjz jz where jz.make_date>=timetemp;*/
258 
259 ---===============================================================================================================================================
260 ---======================================== 声明:全部数据   ===========================================================
261 ---===============================================================================================================================================
262  CURSOR  tmp_tab_yjz_loop IS
263     select * from tmp_tab_yjz;
264 
265 ---===============================================================================================================================================
266 ---========================================         脚本程序块:开始执行区域             ===========================================================
267 ---===============================================================================================================================================
268 
269 
270 begin
271 ----对参数进行判断空校验
272 if startyear  is null then
273    dbms_output.put_line('年度不能为空');
274    END IF;
275 
276 delete_sql := 'delete from tmp_tab_yjz';
277 EXECUTE IMMEDIATE delete_sql;
278 
279 
280 /*v_sql :='select * from tmp_tab_yjz t ';*/
281 select sysdate into timetemp from dual;
282 
283 select value into jzstandard from pwp_sysparam p where p.name='hezhunjzStandard';
284 select value into ybstandard from pwp_sysparam p where p.name='hezhunybStandard';
285 
286  ---- 向 临时表tmp_tab_summary 中插入  指标信息
287    for  zbinfo IN  zbinfo_loop loop  --遍历游标
288         insert into  tmp_tab_yjz (
289    heding_id,zbid,bdgyear,fundtype,unitno,unitid,org_id,src_id,prj_code,prj_id,bdgt_id_type,
290    budgetno,budgetid,itemno,item_id,entire_manage,adjlevel,is_heding,direct_amt,accredit_amt,tradition_amt,
291    zb_amt
292   /* zjzf_zc_sum,sqzf_zc_sum,ybzf_sum,zc_sum,zbjy_sum,zbjy_zjzf,zbjy_sqzf,zbjy_ybzf,
293    cz_hezhun_direct,cz_hezhun_accredit,cz_hezhun_tradition,cz_hezhun_sum,
294    biz_status,remark,back_remark,make_date,maker_accountid, --核定表信息
295    toback_direct_amt,toback_accredit_amt,toback_tradition_amt,toback_sum    */
296     )
297     values(zbinfo.heding_id,zbinfo.id,zbinfo.bdgyear,zbinfo.fundtype,zbinfo.unitno,zbinfo.unitid,zbinfo.org_id,zbinfo.src_id,zbinfo.prj_code,zbinfo.prj_id,zbinfo.bdgt_id_type,
298     zbinfo.budgetno,zbinfo.budgetid,zbinfo.itemno,zbinfo.item_id,zbinfo.entire_manage,zbinfo.adjlevel,zbinfo.is_heding,zbinfo.direct_amt,zbinfo.accredit_amt,zbinfo.tradition_amt,
299     zbinfo.zb_amt
300    /* zbinfo.ITEMNO,zbinfo.ITEMNAME,zbinfo.ORG_ID,zbinfo.ORG_NAME,zbinfo.ZB_AMT,zbinfo.DIRECT_AMT,zbinfo.ACCREDIT_AMT,zbinfo.DIRECT_PLAN,zbinfo.ACCREDIT_PLAN,zbinfo.TRADITION_AMT,zbinfo.ADJLEVEL,
301     zbinfo.ADJLEVEL_NAME,zbinfo.YEARBAL_STATUS,zbinfo.YEARBAL_NAME,zbinfo.IS_HEDING,zbinfo.EARLY_AMT,zbinfo.EARLY_CHANGE_AMT,zbinfo.ADDITIONAL_AMT,zbinfo.TRADITION_NUM,zbinfo.FUNDTYPE,
302     zbinfo.FUNDTYPE_NAME,zbinfo.ISSUE_NUM,zbinfo.BZ,zbinfo.IS_UNIFY,zbinfo.IS_FREEZE,zbinfo.ENTIRE_MANAGE*/
303     ) ;
304     --结束游标
305     END LOOP;
306 
307 
308     ----更新  (直接支付)  支出数信息
309      for  zjzf_zc IN  zjzf_zc_loop loop  --遍历游标
310          update   tmp_tab_yjz  tts set tts.zjzf_zc=nvl(zjzf_zc.zjzf_zc,0)
311             where tts.zbid= zjzf_zc.zjzf_zc_zbid;
312     --结束游标
313     END LOOP;
314 
315       ----更新  (直接支付) 全额退款 信息
316      for  zjzf_qetk IN  zjzf_qetk_loop loop  --遍历游标
317          update   tmp_tab_yjz  tts set tts.zjzf_qetk=nvl(zjzf_qetk.zjzf_qetk,0)
318             where tts.zbid= zjzf_qetk.zjzf_qetk_zbid;
319     --结束游标
320     END LOOP;
321 
322       ----更新  (直接支付) 部分退款 信息
323      for  zjzf_bftk IN  zjzf_bftk_loop loop  --遍历游标
324          update   tmp_tab_yjz  tts set tts.zjzf_bftk=nvl(zjzf_bftk.zjzf_bftk,0)
325             where tts.zbid= zjzf_bftk.zjzf_bftk_zbid;
326     --结束游标
327     END LOOP;
328 
329       ----更新  (直接支付) 调整前金额 信息
330      for  zcywtz_zjzf_tzq IN  zcywtz_zjzf_tzq_loop loop  --遍历游标
331          update   tmp_tab_yjz  tts set tts.zcywtz_zjzf_tzq=nvl(zcywtz_zjzf_tzq.zcywtz_zjzf_tzq,0)
332             where tts.zbid= zcywtz_zjzf_tzq.zcywtz_zjzf_tzq_zbid;
333     --结束游标
334     END LOOP;
335 
336      ----更新  (直接支付) 调整后金额 信息
337      for  zcywtz_zjzf_tzh IN  zcywtz_zjzf_tzh_loop loop  --遍历游标
338          update   tmp_tab_yjz  tts set tts.zcywtz_zjzf_tzh=nvl(zcywtz_zjzf_tzh.zcywtz_zjzf_tzh,0)
339             where tts.zbid= zcywtz_zjzf_tzh.zcywtz_zjzf_tzh_zbid;
340     --结束游标
341     END LOOP;
342 
343 
344     ----更新  (授权支付)  支出数信息
345      for  sqzf_zc IN  sqzf_zc_loop loop  --遍历游标
346          update   tmp_tab_yjz  tts set tts.sqzf_zc =nvl(sqzf_zc.sqzf_zc,0)
347             where tts.zbid= sqzf_zc.sqzf_zc_zbid ;
348     --结束游标
349     END LOOP;
350 
351     ----更新  (授权支付)  全额退款金额
352      for  sqzf_qetk IN  sqzf_qetk_loop loop  --遍历游标
353          update   tmp_tab_yjz  tts set tts.sqzf_qetk =nvl(sqzf_qetk.sqzf_qetk,0)
354             where tts.zbid= sqzf_qetk.sqzf_qetk_zbid ;
355     --结束游标
356     END LOOP;
357 
358     ----更新  (授权支付)  部分退款金额
359      for  sqzf_bftk IN  sqzf_bftk_loop loop  --遍历游标
360          update   tmp_tab_yjz  tts set tts.sqzf_bftk =nvl(sqzf_bftk.sqzf_bftk,0)
361             where tts.zbid= sqzf_bftk.sqzf_bftk_zbid ;
362     --结束游标
363     END LOOP;
364 
365     ----更新  (授权支付)  调整前金额
366      for  zcywtz_sqzf_tzq IN  zcywtz_sqzf_tzq_loop loop  --遍历游标
367          update   tmp_tab_yjz  tts set tts.zcywtz_sqzf_tzq =nvl(zcywtz_sqzf_tzq.zcywtz_sqzf_tzq,0)
368             where tts.zbid= zcywtz_sqzf_tzq.zcywtz_sqzf_tzq_zbid ;
369     --结束游标
370     END LOOP;
371 
372     ----更新  (授权支付)  调整后金额
373      for  zcywtz_sqzf_tzh IN  zcywtz_sqzf_tzh_loop loop  --遍历游标
374          update   tmp_tab_yjz  tts set tts.zcywtz_sqzf_tzh =nvl(zcywtz_sqzf_tzh.zcywtz_sqzf_tzh,0)
375             where tts.zbid= zcywtz_sqzf_tzh.zcywtz_sqzf_tzh_zbid ;
376     --结束游标
377     END LOOP;
378 
379     ----更新  (一般支付)  支出数信息
380      for  ybzf_zc IN  ybzf_zc_loop loop  --遍历游标
381          update   tmp_tab_yjz  tts set tts.ybzf_zc =nvl(ybzf_zc.ybzf_zc,0)
382             where tts.zbid= ybzf_zc.ybzf_zc_zbid ;
383     --结束游标
384     END LOOP;
385 
386      ----更新  (一般支付)  退款金额
387      for  ybzf_tk IN  ybzf_tk_loop loop  --遍历游标
388          update   tmp_tab_yjz  tts set tts.ybzf_tk =nvl(ybzf_tk.ybzf_tk,0)
389             where tts.zbid= ybzf_tk.ybzf_tk_zbid ;
390     --结束游标
391     END LOOP;
392 
393     ----更新  (一般支付)  调整前金额
394      for  zcywtz_ybzf_tzq IN  zcywtz_ybzf_tzq_loop loop  --遍历游标
395          update   tmp_tab_yjz  tts set tts.zcywtz_ybzf_tzq =nvl(zcywtz_ybzf_tzq.zcywtz_ybzf_tzq,0)
396             where tts.zbid= zcywtz_ybzf_tzq.zcywtz_ybzf_tzq_zbid ;
397     --结束游标
398     END LOOP;
399 
400     ----更新  (一般支付)  调整后金额
401      for  zcywtz_ybzf_tzh IN  zcywtz_ybzf_tzh_loop loop  --遍历游标
402          update   tmp_tab_yjz  tts set tts.zcywtz_ybzf_tzh =nvl(zcywtz_ybzf_tzh.zcywtz_ybzf_tzh,0)
403             where tts.zbid= zcywtz_ybzf_tzh.zcywtz_ybzf_tzh_zbid ;
404     --结束游标
405     END LOOP;
406 
407     ----更新  总额
408 
409     for tmpsum in tmp_tab_yjz_loop loop
410          update   tmp_tab_yjz  tts set tts.zjzf_zc_sum =
411          nvl(nvl(tts.zjzf_zc, 0) - nvl(tts.zjzf_qetk, 0) - nvl(tts.zjzf_bftk,0)- nvl(tts.zcywtz_zjzf_tzq,0)+nvl(tts.zcywtz_zjzf_tzh,0),0),
412          tts.sqzf_zc_sum=
413          nvl((nvl(tts.sqzf_zc, 0) - nvl(tts.sqzf_qetk, 0) - nvl(tts.sqzf_bftk, 0)-nvl(tts.zcywtz_sqzf_tzq,0)+nvl(tts.zcywtz_sqzf_tzh,0)), 0),
414          tts.ybzf_sum=
415          nvl((nvl(tts.ybzf_zc, 0) - nvl(tts.ybzf_tk, 0) - nvl(tts.zcywtz_ybzf_tzq,0)+nvl(tts.zcywtz_ybzf_tzh,0) ), 0),
416          tts.zc_sum=
417               nvl(((nvl(tts.zjzf_zc, 0) - nvl(tts.zjzf_qetk, 0) - nvl(tts.zjzf_bftk, 0)-nvl(tts.zcywtz_zjzf_tzq,0)
418               +nvl(tts.zcywtz_zjzf_tzh,0)  ) + (nvl(tts.sqzf_zc, 0) - nvl(tts.sqzf_qetk, 0) - nvl(tts.sqzf_bftk, 0)
419               -nvl(tts.zcywtz_sqzf_tzq,0)+nvl(tts.zcywtz_sqzf_tzh,0)) + (nvl(tts.ybzf_zc, 0) - nvl(tts.ybzf_tk, 0))), 0)
420 
421          where tts.zbid= tmpsum.zbid ;
422     end loop;
423 
424     ----更新  direct_amt-zjzf_zc_sum zbjy_zjzf,accredit_amt-sqzf_zc_sum zbjy_sqzf,tradition_amt-ybzf_sum zbjy_ybzf,zb_amt-zc_sum zbjy_sum
425     for tmpsum in tmp_tab_yjz_loop loop
426          update   tmp_tab_yjz  tts set
427          tts.zbjy_zjzf =nvl(tts.direct_amt,0)-nvl(tts.zjzf_zc_sum,0),
428          tts.zbjy_sqzf=nvl(tts.accredit_amt,0)-nvl(tts.sqzf_zc_sum,0),
429          tts.zbjy_ybzf=nvl(tts.tradition_amt,0)-nvl(tts.ybzf_sum,0),
430          tts.zbjy_sum=nvl(tts.zb_amt,0)-nvl(tts.zc_sum,0)
431          where tts.zbid= tmpsum.zbid ;
432     end loop;
433 
434     --插入预结转数据
435     for tmpsum in tmp_tab_yjz_loop loop
436               insert into  gk_yearbal_yjz (
437                  gk_yearbal_yjz_id,gk_yearbal_heding_id,zbz_bal_id,year,unitno,src_id,budgetno,bdgt_id_type,itemno,prj_code,zb_project_type,org_id,
438                  direct_amt,accredit_amt,tradition_amt,direct_payamt,accredit_payamt,tradition_payamt,cz_hezhun_apldir,cz_hezhun_aplart,
439                  cz_hezhun_apltra,cz_hezhun_direct,cz_hezhun_accredit,cz_hezhun_tradition,remark,make_date,maker_accountid,maker_org_id
440               )
441               values(
442                  nvl((select max(gk_yearbal_yjz_id)+1 from gk_yearbal_yjz),0),tmpsum.heding_id,tmpsum.zbid,tmpsum.bdgyear,tmpsum.unitno,tmpsum.src_id,tmpsum.budgetno,tmpsum.bdgt_id_type,tmpsum.itemno,tmpsum.prj_code,tmpsum.zb_project_type,tmpsum.org_id,
443                  tmpsum.direct_amt,tmpsum.accredit_amt,tmpsum.tradition_amt,tmpsum.zjzf_zc_sum,tmpsum.sqzf_zc_sum,tmpsum.ybzf_sum,tmpsum.zbjy_zjzf,tmpsum.zbjy_sqzf,
444                  tmpsum.zbjy_ybzf,tmpsum.zbjy_zjzf,tmpsum.zbjy_sqzf,tmpsum.zbjy_ybzf,'',timetemp,oper_account,oper_org
445               ) ;
446     end loop;
447 
448     --更新预结转数 (根据指标是否结转字段,否:结转数设为0;是:与参数比较,小于参数0,大于参数不改)
449     for tmpsum in tmp_tab_yjz_loop loop
450       if(tmpsum.is_heding=0) then
451 
452            update gk_yearbal_yjz jz set
453            jz.cz_hezhun_apldir=0,jz.cz_hezhun_aplart=0,jz.cz_hezhun_apltra=0,
454            jz.cz_hezhun_direct=0,jz.cz_hezhun_accredit=0,jz.cz_hezhun_tradition=0
455            where jz.zbz_bal_id=tmpsum.ZBID;
456         end if;
457        if(tmpsum.is_heding!=0) then
458            if(tmpsum.zbjy_zjzf+tmpsum.zbjy_sqzf<jzstandard) then
459 
460                update gk_yearbal_yjz jz set
461                jz.cz_hezhun_apldir=0,jz.cz_hezhun_direct=0,jz.cz_hezhun_aplart=0,jz.cz_hezhun_accredit=0
462                where jz.zbz_bal_id=tmpsum.ZBID;
463              end if;
464 
465             if(tmpsum.zbjy_ybzf<ybstandard) then
466 
467              update gk_yearbal_yjz jz set
468              jz.cz_hezhun_apltra=0,jz.cz_hezhun_tradition=0
469              where jz.zbz_bal_id=tmpsum.ZBID;
470 
471              end if;
472        end if;
473 
474     end loop;
475 
476 
477 /*  OPEN v_cur FOR v_sql;*/
478 
479    commit;
480 
481 end pro_yearbal_yjz ;

 

 

 

示例2:声明游标,遍历游标

 

  1 create or replace procedure pro_yearbal_toback_end(gatherid in varchar2) is
  2  zbz_bal_id number(20);
  3 
  4 
  5  ---汇总表下所有核定数据
  6  CURSOR hedings  IS
  7   select t.*,a.account_name from gk_yearbal_heding t,gk_yearbal_heding_toback tb,pwp_account a
  8    where t.gk_heding_id=tb.heding_id and tb.gather_id = gatherid and a.account_id=t.maker_accountid;
  9 
 10  --一条指标数据
 11   CURSOR zbs  IS
 12   select * from zb_bal where id=zbz_bal_id;
 13 
 14  begin
 15   ----新建汇总表数据
 16   for  heding IN  hedings loop  --遍历游标
 17       zbz_bal_id:=heding.zbz_bal_id;
 18       for zb in zbs loop
 19          update zb_bal set zb_amt=
 20          (zb.zb_amt*10-(heding.direct_amt-heding.direct_payamt-heding.cz_hezhun_direct)*10-(heding.accredit_amt-heding.accredit_payamt-heding.cz_hezhun_accredit)*10
 21          -(heding.tradition_amt-heding.tradition_payamt-heding.cz_hezhun_tradition)*10)/10,
 22          direct_amt=(zb.direct_amt*10-(heding.direct_amt-heding.direct_payamt-heding.cz_hezhun_direct)*10)/10,
 23          accredit_amt=(zb.accredit_amt*10-(heding.accredit_amt-heding.accredit_payamt-heding.cz_hezhun_accredit)*10)/10,
 24          tradition_amt=(zb.tradition_amt*10-(heding.tradition_amt-heding.tradition_payamt-heding.cz_hezhun_tradition)*10)/10,
 25          toback_amt=((heding.direct_amt-heding.direct_payamt-heding.cz_hezhun_direct)*10+(heding.accredit_amt-heding.accredit_payamt-heding.cz_hezhun_accredit)*10
 26          +(heding.tradition_amt-heding.tradition_payamt-heding.cz_hezhun_tradition)*10)/10,
 27          bz=(case when zb.bz is null then '' else zb.bz||''||sysdate||''||heding.account_name||'通过年终结转指标收回。' end),
 28          is_toback='1',
 29          toback_date=sysdate where id=zbz_bal_id;
 30 
 31 
 32       end loop;
 33   END LOOP;
 34 
 35 end pro_yearbal_toback_end;
 36 
  1 create or replace procedure pro_yearbal_toback(orgid in varchar2 ,
  2                                               accountid in varchar2,
  3                                               bdgyear in varchar2)
  4 is
  5 
  6    gatherid number(20);
  7    srctemp varchar2(20);
  8    orgtemp varchar2(20);
  9 
 10  ---所有资金来源、科室类型
 11  CURSOR kszj  IS
 12  select distinct src_id,org_id
 13      from gk_yearbal_heding hd where (hd.direct_amt-hd.direct_payamt-hd.cz_hezhun_direct)
 14      +(hd.accredit_amt-hd.accredit_payamt-hd.cz_hezhun_accredit)+(hd.tradition_amt-hd.tradition_payamt-hd.cz_hezhun_tradition) !=0 and biz_status='9'
 15      and hd.is_recover='1' and hd.gk_heding_id not in ( select heding_id from gk_yearbal_heding_toback tb,gk_yearbal_toback_gather g where
 16      g.id=tb.gather_id and g.toback_issued_status='1') and hd.year=bdgyear;
 17 
 18  ---所有要汇总的数据(下达)    
 19  CURSOR alldata  IS
 20   select *
 21      from gk_yearbal_heding hd where (hd.direct_amt-hd.direct_payamt-hd.cz_hezhun_direct)
 22      +(hd.accredit_amt-hd.accredit_payamt-hd.cz_hezhun_accredit)+(hd.tradition_amt-hd.tradition_payamt-hd.cz_hezhun_tradition) !=0 and biz_status='9'
 23      and hd.is_recover='1' and hd.gk_heding_id not in ( select heding_id from gk_yearbal_heding_toback tb,gk_yearbal_toback_gather g where
 24      g.id=tb.gather_id and g.toback_issued_status='1') and hd.year=bdgyear and hd.src_id=srctemp and hd.org_id=orgtemp;
 25 
 26 
 27 
 28  begin
 29   ----新建汇总表数据
 30   for  ks IN  kszj loop  --遍历游标
 31        insert into gk_yearbal_toback_gather (id,toback_issued_status,year,src_id,org_id,biz_status,make_date,maker_accountid,maker_org_id)
 32        values ((select nextid('GK_YEARBAL_TOBACK_GATHER_SEQ') from dual),'1',bdgyear,ks.src_id,ks.org_id,'0',sysdate,accountid,orgid);
 33        select id into gatherid from gk_yearbal_toback_gather g where g.id =(select max(id) from gk_yearbal_toback_gather);
 34        srctemp:=ks.src_id;
 35        orgtemp:=ks.org_id;
 36        for data in alldata loop
 37           insert into gk_yearbal_heding_toback (TOBACK_ID,GATHER_ID,HEDING_ID)
 38           values (nvl((select max(TOBACK_ID)+1 from gk_yearbal_heding_toback),0),gatherid,data.gk_heding_id);
 39        end loop;
 40   END LOOP;
 41 
 42 end pro_yearbal_toback;
 43 

 

  1 create or replace procedure pro_yearbal_issue_end(gatherid in varchar2,bdgyear in varchar2)
  2 is
  3    zbz_bal_id number(20);
  4    exzb number(20);
  5    ---exzbinfo zb_bal%rowtype;
  6 
  7 
  8 
  9 
 10  ---汇总表下所有核定数据
 11  CURSOR hedings  IS
 12   select t.*,a.account_name from gk_yearbal_heding t,gk_yearbal_heding_toback tb,pwp_account a
 13    where t.gk_heding_id=tb.heding_id and tb.gather_id = gatherid and a.account_id=t.maker_accountid;
 14 
 15  --一条指标数据
 16   CURSOR zbs  IS
 17   select * from zb_bal where id=zbz_bal_id;
 18 
 19  begin
 20   ----新建汇总表数据
 21   for  heding IN  hedings loop  --遍历游标
 22       zbz_bal_id:=heding.zbz_bal_id;
 23       update zb_bal set yearbal_status='1' where id=heding.zbz_bal_id;
 24       --获取核定表对应指标信息
 25       for zb in zbs loop
 26         ---判断指标是否已经存在
 27         if(zb.entire_manage is null) then
 28           select max(id) into exzb from zb_bal where bdgyear=zb.bdgyear+1 and unitno=zb.unitno and prj_id=zb.prj_id and BDGT_ID_TYPE=zb.BDGT_ID_TYPE
 29           and BUDGETNO=zb.BUDGETNO and src_id=(select  concat('1',substr(to_char(zb.src_id), 2)) from dual) and org_id=zb.org_id and entire_manage is null ;
 30 
 31        else
 32           select max(id) into exzb from zb_bal where bdgyear=zb.bdgyear+1 and unitno=zb.unitno and prj_id=zb.prj_id and BDGT_ID_TYPE=zb.BDGT_ID_TYPE
 33           and BUDGETNO=zb.BUDGETNO and src_id=(select  concat('1',substr(to_char(zb.src_id), 2)) from dual) and org_id=zb.org_id and entire_manage = zb.entire_manage;
 34 
 35        end if;
 36 
 37         if(exzb is not null) then
 38 
 39 
 40             update zb_bal set
 41             zb_amt=zb_amt+heding.cz_hezhun_direct+heding.cz_hezhun_accredit+heding.cz_hezhun_tradition,
 42             direct_amt=direct_amt+heding.cz_hezhun_direct,
 43             accredit_amt=accredit_amt+heding.cz_hezhun_accredit,
 44             tradition_amt=tradition_amt+heding.cz_hezhun_tradition,
 45             early_amt=early_amt+heding.cz_hezhun_direct+heding.cz_hezhun_accredit+heding.cz_hezhun_tradition,
 46             bz = bz|| ''||zb.id||'指标于'||sysdate||'下达生成。',
 47             budgetid=(select id from bs_gnflyskm gn where gn.func_bdgid=zb.budgetno and gn.bdgyear=zb.bdgyear+1
 48             and gn.func_bdg_type=zb.bdgt_id_type)
 49             where id= exzb;
 50 
 51 
 52             update gk_yearbal_heding set issue_zb =(exzb) where zbz_bal_id =heding.zbz_bal_id;
 53         end if;
 54 
 55         if(exzb is null) then
 56         insert into zb_bal (id,is_heding,bdgyear,unitid,src_id,bdgt_id_type,
 57           budgetid,prj_id, item_id,zb_amt,
 58           direct_amt,  accredit_amt, direct_plan,accredit_plan, tradition_amt,org_id, adjlevel,yearbal_status,
 59           zb_project_type,early_amt,
 60           early_change_amt,additional_amt,tradition_num, fundtype,issue_num,
 61           bz,
 62           is_unify, is_freeze,origin_id,entire_manage,send_status,unitno,budgetno,itemno,prj_code,create_date,
 63           source_zb_id,yearbal_no,is_toback,zb_issuedtype)
 64          values
 65          ((select NEXTID('ZB_BAL_SEQ') from dual),'1',zb.bdgyear+1,zb.unitid,(select  concat('1',substr(to_char(zb.src_id), 2)) from dual),zb.bdgt_id_type,
 66          zb.budgetid,zb.prj_id,zb.item_id,heding.cz_hezhun_direct+heding.cz_hezhun_accredit+heding.cz_hezhun_tradition,
 67          heding.cz_hezhun_direct,heding.cz_hezhun_accredit,'0','0',heding.cz_hezhun_tradition,zb.org_id,zb.adjlevel,'0',
 68          zb.zb_project_type,heding.cz_hezhun_direct+heding.cz_hezhun_accredit+heding.cz_hezhun_tradition,
 69          '0','0','0',zb.fundtype,'1',
 70          ''||zb.id||'指标于'||sysdate||'下达生成。',
 71          zb.is_unify, zb.is_freeze, zb.origin_id, zb.entire_manage,'0',zb.unitno,zb.budgetno,zb.itemno,zb.prj_code,sysdate,
 72          zb.id, (case when zb.yearbal_no=0 then 1 when zb.yearbal_no=1 then 2 when zb.yearbal_no>=2 then 2 end) ,'0','2' );
 73 
 74          update zb_bal set budgetid=(select id from bs_gnflyskm gn where gn.func_bdgid=zb.budgetno and gn.bdgyear=zb.bdgyear+1
 75          and gn.func_bdg_type=zb.bdgt_id_type) where id=(select nextid-1 from pwp_nodtl n where n.noid='ZB_BAL_SEQ');
 76 
 77          update gk_yearbal_heding set issue_zb =(select id from zb_bal where id =
 78          (select nextid-1 from pwp_nodtl n where n.noid='ZB_BAL_SEQ')) where zbz_bal_id =heding.zbz_bal_id;
 79          end if;
 80 
 81        end loop;
 82   END LOOP;
 83 
 84 end pro_yearbal_issue_end;
 85 

 

  1 create or replace procedure pro_yearbal_issue(orgid in varchar2 ,
  2                                               accountid in varchar2,
  3                                               bdgyear in varchar2)
  4 is
  5 
  6    gatherid number(20);
  7    srctemp varchar2(20);
  8    orgtemp varchar2(20);
  9 
 10  ---所有资金来源、科室类型
 11  CURSOR kszj  IS
 12  select distinct src_id,org_id from gk_yearbal_heding hd where hd.cz_hezhun_direct+hd.cz_hezhun_accredit+hd.cz_hezhun_tradition !=0 and biz_status='9'
 13      and hd.is_issued='1' and hd.gk_heding_id not in ( select heding_id from gk_yearbal_heding_toback tb,gk_yearbal_toback_gather g where g.toback_issued_status='2'
 14      and g.id=tb.gather_id ) and hd.year=bdgyear;
 15 
 16  ---所有要汇总的数据(下达)    
 17  CURSOR alldata  IS
 18   select * from gk_yearbal_heding hd where hd.cz_hezhun_direct+hd.cz_hezhun_accredit+hd.cz_hezhun_tradition !=0 and biz_status='9'
 19      and hd.is_issued='1' and hd.gk_heding_id not in ( select heding_id from gk_yearbal_heding_toback tb,gk_yearbal_toback_gather g where g.toback_issued_status='2'
 20      and g.id=tb.gather_id ) and hd.year=bdgyear and hd.src_id=srctemp and hd.org_id=orgtemp;
 21 
 22 
 23 
 24  begin
 25   ----新建汇总表数据
 26   for  ks IN  kszj loop  --遍历游标
 27        insert into gk_yearbal_toback_gather (id,toback_issued_status,year,src_id,org_id,biz_status,make_date,maker_accountid,maker_org_id)
 28        values ((select nextid('GK_YEARBAL_TOBACK_GATHER_SEQ') from dual),'2',bdgyear,ks.src_id,ks.org_id,'0',sysdate,accountid,orgid);
 29        select id into gatherid from gk_yearbal_toback_gather g where g.id =(select max(id) from gk_yearbal_toback_gather);
 30        srctemp:=ks.src_id;
 31        orgtemp:=ks.org_id;
 32        for data in alldata loop
 33           insert into gk_yearbal_heding_toback (TOBACK_ID,GATHER_ID,HEDING_ID)
 34           values (nvl((select max(TOBACK_ID)+1 from gk_yearbal_heding_toback),0),gatherid,data.gk_heding_id);
 35        end loop;
 36   END LOOP;
 37 
 38 end pro_yearbal_issue;
 39 

 

 

  1 create or replace procedure pro_yearbal_collect(orgid in varchar2 ,
  2                                               accountid in varchar2,
  3                                               bdgyear in varchar2)
  4 is
  5 
  6    spid number(20);
  7 
  8 
  9  ---所有当前科室未汇总数据
 10  CURSOR hedings  IS
 11  select * from gk_yearbal_heding t where t.org_id=orgid and t.biz_status='3';
 12 
 13 
 14  begin
 15 
 16    ---新建汇总表数据
 17    insert into gk_yearbal_heding_sp (id,year,org_id,make_date,maker_accountid,maker_org_id,data_flow_link,audit_status)
 18    values ((select nextid('GK_YEARBAL_HEDING_SP_SEQ') from dual),bdgyear,orgid,sysdate,accountid,orgid,'0','0');
 19 
 20    select nextid-1 into spid from pwp_nodtl n where n.noid=('GK_YEARBAL_HEDING_SP_SEQ');
 21 
 22   ----新建汇总明细数据,更新核定表数据
 23   for  heding IN  hedings loop
 24 
 25        insert into gk_yearbal_heding_spmx (heding_spmxid,heging_spid,heding_id)
 26        values (nextid('GK_YEARBAL_HEDING_SPMX_SEQ'),spid,heding.gk_heding_id);
 27 
 28        update gk_yearbal_heding set biz_status=4 where gk_heding_id = heding.gk_heding_id;
 29 
 30   END LOOP;
 31 
 32 end pro_yearbal_collect;
 33 

示例3:入参 字符串;返回结果集合

 

  1 CREATE OR REPLACE PACKAGE PKG_QUERY IS
  2 
  3   -- Author  : ADMINISTRATOR
  4   -- Created : 2016/12/8 星期四 10:28:37
  5   -- Purpose : 用做查询游标
  6 
  7   -- Public type declarations
  8   TYPE CUR_QUERY IS REF CURSOR;
  9 
 10 END PKG_QUERY;
 11 

 

  1 create or replace procedure pro_annual_spend_summary( startyear in varchar2 /*起始年度*/,
  2                                                              endyear/*终止年度*/ in varchar2,
  3                                                              startmonth in varchar2 /*起始月份*/,
  4                                                              endmonth  in varchar2 /*终止月份*/ ,
  5                                                              orgsql in varchar2 /*当前机构id*/,
  6                                                               v_cur              out pkg_query.cur_query )--返回的结果集
  7 is
  8 
  9   --用于判断临时表是否存在中间变量
 10 /*  TABEXT  VARCHAR2(10);*/
 11   --查询所有语句
 12   v_sql VARCHAR2(4000);
 13   delete_sql   VARCHAR2(50); --删除临时表记录语句
 14   --删表语句
 15 /*  delete_sql VARCHAR2(4000);*/
 16   --建表语句
 17 /*  create_sql VARCHAR2(4000);*/
 18 
 19 ---===============================================================================================================================================
 20 ---========================================   声明: 指标信息  游标  ================================================================================
 21 ---===============================================================================================================================================
 22 
 23  CURSOR  zbinfo_loop  IS
 24       select (select u.unit_name from bs_bdg_unit u where u.unitno = z.unitno ) unit_name  ,
 25      (select  zj.fund  from bs_zjly zj where zj.fundno = z.src_id ) src_name ,
 26      (select  (case zj.org_type when '1' then '预算内' else '预算外' end) src_typename  from bs_zjly zj where zj.fundno = z.src_id ) src_typename ,
 27      (select   zj.org_type  from bs_zjly zj where zj.fundno = z.src_id ) src_type ,
 28      (select   pd.dict_text   from pwp_dict p ,pwp_dict_detail pd where p.dict_id=pd.dict_id  and p.dict_name ='budgetType' and pd.dict_value=z.bdgt_id_type  ) bdgt_id_typename ,
 29      ( select  bg.func_bdgname  from bs_gnflyskm bg where bg.func_bdgid = z.budgetno and bg.bdgyear=z.bdgyear and z.budgetid=bg.id) budgetname ,
 30      (select  bx.prj_name from bs_xmk bx where bx.prj_code=z.prj_code  ) prj_codename ,
 31      (select  bj.econ_bdg from bs_jjflyskm bj where bj.bdgyear=z.bdgyear and (  bj.econ_bdgid=z.itemno) )  itemname ,
 32      (select  po.org_name from pwp_org po where po.org_id= z.org_id ) org_name ,
 33      (case z.adjlevel when '0' then '本级' when '1' then '上级'  end ) adjlevel_name ,
 34      (case z.yearbal_status when '0' then '' when '1' then '' end  ) yearbal_name ,
 35      ( select   pd.dict_text   from pwp_dict p ,pwp_dict_detail pd where p.dict_id=pd.dict_id  and p.dict_name ='prjType' and pd.dict_value=z.zb_project_type ) pro_type_name  ,
 36       (case z.fundtype when '1' then '人员经费' when '2' then '公用经费' when '3' then '项目经费' when '4' then '其他经费' end  )  fundtype_name ,
 37  z.*  from  zb_bal z
 38       where z.bdgyear >= startyear
 39       and   z.bdgyear <= endyear
 40       order by id ;
 41 
 42 
 43 ---===============================================================================================================================================
 44 ---======================================== 声明:查询(直接支付)支出数   信息的游标     =======================================================
 45 ---===============================================================================================================================================
 46 
 47   CURSOR zjzf_zc_loop  IS
 48   select zjzf_zc_zbid,sum(zjzf_zc_amt) as zjzf_zc from (select gz.zbz_bal_id as zjzf_zc_zbid,
 49           to_char(gz.affirm_date, 'yyyyMM') as zjzf_zc_adutiem,
 50           nvl(sum(gz.amt), 0) as zjzf_zc_amt
 51      from gk_zfpz gz
 52     where gz.check_status in ('1','2','02') /*正常支付*/
 53       and gz.wf_status = '9' /*审结状态*/
 54       and gz.voucher_type = '0' /*支付凭证类型(直接为'0' */
 55     group by gz.zbz_bal_id, to_char(gz.affirm_date, 'yyyyMM')) x
 56     where x.zjzf_zc_adutiem >= startyear||startmonth
 57     and x.zjzf_zc_adutiem <= endyear||endmonth
 58     group by zjzf_zc_zbid;
 59 
 60 ---===============================================================================================================================================
 61 ---======================================== 声明:查询(直接支付)全额退款   信息的游标     =======================================================
 62 ---===============================================================================================================================================
 63  CURSOR zjzf_qetk_loop  IS
 64 select zjzf_qetk_zbid,sum(zjzf_qetk_amt) as zjzf_qetk from (select gz.zbz_bal_id as zjzf_qetk_zbid,
 65           to_char(gz.back_oper_date, 'yyyyMM') as zjzf_qetk_adutiem,
 66           nvl(sum(gz.amt), 0) as zjzf_qetk_amt
 67      from gk_zfpz gz
 68     where gz.check_status = '2' /*确认全额退款*/
 69       and gz.wf_status = '9' /*审结状态*/
 70       and gz.voucher_type = '0' /*支付凭证类型(直接为'0' */
 71     group by gz.zbz_bal_id, to_char(gz.back_oper_date, 'yyyyMM')) x1
 72      where x1.zjzf_qetk_adutiem >= startyear||startmonth
 73     and x1.zjzf_qetk_adutiem <= endyear||endmonth
 74     group by zjzf_qetk_zbid;
 75 
 76 ---===============================================================================================================================================
 77 ---======================================== 声明:查询(直接支付)部分退款   信息的游标     =======================================================
 78 ---===============================================================================================================================================
 79  CURSOR zjzf_bftk_loop  IS
 80 select zjzf_bftk_zbid,sum(zjzf_bftk_amt) as zjzf_bftk from (select gpr.zbz_bal_id as zjzf_bftk_zbid,
 81           to_char(gpr.collate_date, 'yyyyMM') as zjzf_bftk_adutiem,
 82           nvl(sum(gpr.amt), 0) as zjzf_bftk_amt
 83      from gk_part_refundment gpr
 84     where gpr.audit_status = '9' /*流程审结状态*/
 85 
 86       and gpr.voucher_type = '0' /*支付凭证类型(直接为'0' */
 87     group by gpr.zbz_bal_id, to_char(gpr.collate_date, 'yyyyMM')) x2
 88      where x2.zjzf_bftk_adutiem >= startyear||startmonth
 89     and x2.zjzf_bftk_adutiem <= endyear||endmonth
 90     group by zjzf_bftk_zbid;
 91 
 92 ---===============================================================================================================================================
 93 ---======================================== 声明:查询(直接支付)调整前金额   信息的游标     =======================================================
 94 ---===============================================================================================================================================
 95  CURSOR zcywtz_zjzf_tzq_loop  IS
 96 select zcywtz_zjzf_tzq_zbid,sum(zcywtz_zjzf_tzq_amt) as zcywtz_zjzf_tzq from (select gad.df_zba_id as  zcywtz_zjzf_tzq_zbid ,/*调整前指标*/
 97             to_char(ga.create_dt,'yyyyMM')  as  zcywtz_zjzf_tzq_adutiem ,/*调整前:调整年份*/
 98             sum(gad.balance )as zcywtz_zjzf_tzq_amt  /*调整前:调整金额*/
 99         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
100              gk_adjust ga /*支出账务调整业务_主表*/
101        where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
102         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
103         and  ga.expenditure_type='0' /* 支出类型(0直接支付,1授权支付) */
104         /*and  to_char(ga.create_dt,'yyyyMM') >=201701
105         and  to_char(ga.create_dt,'yyyyMM')<= 201712*/
106    group by  gad.df_zba_id, to_char(ga.create_dt ,'yyyyMM')) x3
107     where x3.zcywtz_zjzf_tzq_adutiem >= startyear||startmonth
108     and x3.zcywtz_zjzf_tzq_adutiem <= endyear||endmonth
109     group by zcywtz_zjzf_tzq_zbid;
110 
111 
112 ---===============================================================================================================================================
113 ---======================================== 声明:查询(直接支付)调整后金额   信息的游标     =======================================================
114 ---===============================================================================================================================================
115  CURSOR zcywtz_zjzf_tzh_loop  IS
116 select zcywtz_zjzf_tzh_zbid,sum(zcywtz_zjzf_tzh_amt) as zcywtz_zjzf_tzh from (select gad.jf_zba_id as zcywtz_zjzf_tzh_zbid ,/*调整后指标*/
117             to_char(ga.create_dt ,'yyyyMM')  as zcywtz_zjzf_tzh_adutiem ,/*调整后:调整年份*/
118             sum(gad.balance) as zcywtz_zjzf_tzh_amt /*调整后:调整金额*/
119         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
120              gk_adjust ga /*支出账务调整业务_主表*/
121         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
122         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
123         and  ga.expenditure_type='0' /* 支出类型(0直接支付,1授权支付) */
124         group by gad.jf_zba_id  ,to_char(ga.create_dt ,'yyyyMM')) x4
125         where x4.zcywtz_zjzf_tzh_adutiem >= startyear||startmonth
126         and x4.zcywtz_zjzf_tzh_adutiem <= endyear||endmonth
127         group by zcywtz_zjzf_tzh_zbid;
128 
129 ---===============================================================================================================================================
130 ---======================================== 声明:查询 (授权支付)支出数 信息的游标   ===========================================================
131 ---===============================================================================================================================================
132 
133 
134  CURSOR  sqzf_zc_loop IS
135  select sqzf_zc_zbid,sum(sqzf_zc_amt) as sqzf_zc from (select gz.zbz_bal_id as sqzf_zc_zbid,
136           to_char(gz.affirm_date, 'yyyyMM') as sqzf_zc_adutiem,
137           nvl(sum(gz.amt), 0) as sqzf_zc_amt
138      from gk_zfpz gz
139     where gz.check_status in ('1','2','02') /*正常支付*/
140       and gz.wf_status = '9' /*审结状态*/
141       and gz.voucher_type = '1' /*支付凭证类型(授权支付为'1' */
142     group by gz.zbz_bal_id, to_char(gz.affirm_date, 'yyyyMM')) sq1
143     where sq1.sqzf_zc_adutiem >=startyear||startmonth
144     and sq1.sqzf_zc_adutiem <= endyear||endmonth
145     group by sqzf_zc_zbid;
146 
147 
148 ---===============================================================================================================================================
149 ---======================================== 声明:查询 (授权支付)全额退款 信息的游标   ===========================================================
150 ---===============================================================================================================================================
151  CURSOR sqzf_qetk_loop IS
152 select sqzf_qetk_zbid,sum(sqzf_qetk_amt) as sqzf_qetk from (select gz.zbz_bal_id as sqzf_qetk_zbid,
153           to_char(gz.back_oper_date, 'yyyyMM') as sqzf_qetk_adutiem,
154           nvl(sum(gz.amt), 0) as sqzf_qetk_amt
155      from gk_zfpz gz
156     where gz.check_status = '2' /*确认全额退款*/
157       and gz.wf_status = '9' /*审结状态*/
158       and gz.voucher_type = '1' /*支付凭证类型(授权支付为'1' */
159     group by gz.zbz_bal_id, to_char(gz.back_oper_date, 'yyyyMM')) sq2
160      where sq2.sqzf_qetk_adutiem >=startyear||startmonth
161     and sq2.sqzf_qetk_adutiem <= endyear||endmonth
162     group by sqzf_qetk_zbid;
163 
164 
165 ---===============================================================================================================================================
166 ---======================================== 声明:查询 (授权支付)部分退款 信息的游标   ===========================================================
167 ---===============================================================================================================================================
168  CURSOR sqzf_bftk_loop IS
169 select sqzf_bftk_zbid,sum(sqzf_bftk_amt) as sqzf_bftk from (select gpr.zbz_bal_id as sqzf_bftk_zbid,
170           to_char(gpr.collate_date, 'yyyyMM') as sqzf_bftk_adutiem,
171           nvl(sum(gpr.amt), 0) as sqzf_bftk_amt
172      from gk_part_refundment gpr
173     where gpr.audit_status = '9' /*流程审结状态*/
174 
175       and gpr.voucher_type = '1' /*支付凭证类型(授权支付为'1' */
176     group by gpr.zbz_bal_id, to_char(gpr.collate_date, 'yyyyMM')) sq3
177      where sq3.sqzf_bftk_adutiem >=startyear||startmonth
178     and sq3.sqzf_bftk_adutiem <= endyear||endmonth
179     group by sqzf_bftk_zbid;
180 
181 
182 ---===============================================================================================================================================
183 ---======================================== 声明:查询 (授权支付)调整前金额 信息的游标   ===========================================================
184 ---===============================================================================================================================================
185  CURSOR zcywtz_sqzf_tzq_loop IS
186 select zcywtz_sqzf_tzq_zbid,sum(zcywtz_sqzf_tzq_amt) as zcywtz_sqzf_tzq from (select gad.df_zba_id as  zcywtz_sqzf_tzq_zbid ,/*调整前指标*/
187             to_char(ga.create_dt ,'yyyyMM')  as  zcywtz_sqzf_tzq_adutiem ,/*调整前:调整年份*/
188             sum(gad.balance )as zcywtz_sqzf_tzq_amt  /*调整前:调整金额*/
189         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
190              gk_adjust ga /*支出账务调整业务_主表*/
191         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
192         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
193         and  ga.expenditure_type='1' /* 支出类型(0直接支付,1授权支付) */
194    group by  gad.df_zba_id, to_char(ga.create_dt ,'yyyyMM')) sq4
195      where sq4.zcywtz_sqzf_tzq_adutiem >=startyear||startmonth
196     and sq4.zcywtz_sqzf_tzq_adutiem <= endyear||endmonth
197     group by zcywtz_sqzf_tzq_zbid;
198 
199 
200 ---===============================================================================================================================================
201 ---======================================== 声明:查询 (授权支付)全额退款 信息的游标   ===========================================================
202 ---===============================================================================================================================================
203  CURSOR zcywtz_sqzf_tzh_loop IS
204 select zcywtz_sqzf_tzh_zbid,sum(zcywtz_sqzf_tzh_amt) as zcywtz_sqzf_tzh from (select gad.jf_zba_id as zcywtz_sqzf_tzh_zbid ,/*调整后指标*/
205             to_char(ga.create_dt ,'yyyyMM')  as zcywtz_sqzf_tzh_adutiem ,/*调整后:调整年份*/
206             sum(gad.balance) as zcywtz_sqzf_tzh_amt /*调整后:调整金额*/
207         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
208              gk_adjust ga /*支出账务调整业务_主表*/
209         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
210         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
211         and  ga.expenditure_type='1' /* 支出类型(0直接支付,1授权支付) */
212         group by gad.jf_zba_id  ,to_char(ga.create_dt ,'yyyyMM')) sq5
213      where sq5.zcywtz_sqzf_tzh_adutiem >=startyear||startmonth
214     and sq5.zcywtz_sqzf_tzh_adutiem <= endyear||endmonth
215     group by zcywtz_sqzf_tzh_zbid;
216 
217 ---===============================================================================================================================================
218 ---======================================== 声明:查询 (一般支付)支出数 信息的游标   ===========================================================
219 ---===============================================================================================================================================
220   CURSOR  ybzf_zc_loop IS
221      select ybzf_zc_zbid,sum(ybzf_amt) as ybzf_zc from (select ybzf.zbz_bal_id as ybzf_zc_zbid,
222           to_char(ybzf.checker_date, 'yyyyMM') as ybzf_adutiem,
223           nvl(sum(ybzf.amt), 0) as ybzf_amt
224      from gk_zfpz ybzf
225      where ybzf.voucher_type ='3'
226      and ybzf.wf_status ='9'
227     group by ybzf.zbz_bal_id, to_char(ybzf.checker_date, 'yyyyMM')) yb1
228      where yb1.ybzf_adutiem >=startyear||startmonth
229     and yb1.ybzf_adutiem <= endyear||endmonth
230     group by ybzf_zc_zbid;
231 
232 
233 ---===============================================================================================================================================
234 ---======================================== 声明:查询 (一般支付)退款金额 信息的游标   ===========================================================
235 ---===============================================================================================================================================
236   CURSOR  ybzf_tk_loop IS
237 select ybzf_tk_zbid,sum(ybzf_tk_amt) as ybzf_tk from (select crbd.zbz_bal_id as ybzf_tk_zbid,
238           to_char(crb.checker_date, 'yyyyMM') as ybzf_tk_adutiem,
239           nvl(sum(crbd.back_amt), 0) as ybzf_tk_amt
240      from  common_req_back_detail crbd,common_req_back crb
241      where crb.id = crbd.common_req_back_id and crb.wf_status ='9'
242     group by crbd.zbz_bal_id, to_char(crb.checker_date, 'yyyyMM')) yb2
243      where yb2.ybzf_tk_adutiem >=startyear||startmonth
244     and yb2.ybzf_tk_adutiem <= endyear||endmonth
245     group by ybzf_tk_zbid;
246 
247 
248 ---===============================================================================================================================================
249 ---======================================== 声明:查询 (一般支付)调整前金额 信息的游标   ===========================================================
250 ---===============================================================================================================================================
251   CURSOR  zcywtz_ybzf_tzq_loop IS
252 select zcywtz_ybzf_tzq_zbid,sum(zcywtz_sqzf_tzq_amt) as zcywtz_ybzf_tzq from (select gad.df_zba_id as  zcywtz_ybzf_tzq_zbid ,/*调整前指标*/
253             to_char(ga.create_dt ,'yyyyMM')  as  zcywtz_ybzf_tzq_adutiem ,/*调整前:调整年份*/
254             sum(gad.balance )as zcywtz_sqzf_tzq_amt  /*调整前:调整金额*/
255         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
256              gk_adjust ga /*支出账务调整业务_主表*/
257         where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
258         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
259         and  ga.expenditure_type='3' /* 支出类型(0直接支付,1授权支付) */
260    group by  gad.df_zba_id, to_char(ga.create_dt ,'yyyyMM')) yb3
261      where yb3.zcywtz_ybzf_tzq_adutiem >=startyear||startmonth
262     and yb3.zcywtz_ybzf_tzq_adutiem <= endyear||endmonth
263     group by zcywtz_ybzf_tzq_zbid;
264 
265 
266 ---===============================================================================================================================================
267 ---======================================== 声明:查询 (一般支付)调整前金额 信息的游标   ===========================================================
268 ---===============================================================================================================================================
269   CURSOR  zcywtz_ybzf_tzh_loop IS
270 select zcywtz_ybzf_tzh_zbid,sum(zcywtz_sqzf_tzh_amt) as zcywtz_ybzf_tzh from (select gad.jf_zba_id as zcywtz_ybzf_tzh_zbid ,/*调整后指标*/
271             to_char(ga.create_dt ,'yyyyMM')  as zcywtz_ybzf_tzh_adutiem ,/*调整后:调整年份*/
272             sum(gad.balance) as zcywtz_sqzf_tzh_amt /*调整后:调整金额*/
273         from gk_adjust_detail gad,/*支出账务调整业务_明细*/
274              gk_adjust ga /*支出账务调整业务_主表*/
275          where gad.gk_adjust_id  = ga.id /*支出账务调整业务主表 与 支出账务调整业务_明细表 关联*/
276         and  ga.biz_status='9'/*取:一般支付主表已经处于审结状态的数据*/
277         and  ga.expenditure_type='3' /* 支出类型(0直接支付,1授权支付) */
278         group by gad.jf_zba_id  ,to_char(ga.create_dt ,'yyyyMM')) yb4
279      where yb4.zcywtz_ybzf_tzh_adutiem >=startyear||startmonth
280     and yb4.zcywtz_ybzf_tzh_adutiem <= endyear||endmonth
281     group by zcywtz_ybzf_tzh_zbid;
282 
283 ---===============================================================================================================================================
284 ---======================================== 声明:全部数据   ===========================================================
285 ---===============================================================================================================================================
286  CURSOR  tmp_tab_summary_loop IS
287     select * from tmp_tab_summary;
288 
289 ---===============================================================================================================================================
290 ---========================================         脚本程序块:开始执行区域             ===========================================================
291 ---===============================================================================================================================================
292 
293 
294 begin
295 ----对参数进行判断空校验
296 if startyear  is null then
297    dbms_output.put_line('起始年度不能为空');
298    END IF;
299 if endyear    is null  then
300    dbms_output.put_line('终止年度不能为空');
301    END IF;
302 if startmonth    is null  then
303    dbms_output.put_line('起始月份不能为空');
304    END IF;
305 if endmonth    is null  then
306    dbms_output.put_line('终止月份不能为空');
307    END IF;
308 
309 v_sql :='select id,zbid,bdgyear,fundtype,unitno,unitid,org_id,src_id,
310           prj_code,prj_id,zb_project_type,bdgt_id_type,budgetno,
311          budgetid,itemno,item_id,entire_manage,adjlevel,
312           is_heding,direct_amt,accredit_amt,tradition_amt,zb_amt,zjzf_zc_sum,
313           sqzf_zc_sum,ybzf_sum,zc_sum
314           from tmp_tab_summary t
315           where t.bdgyear >='||startyear||
316           'and   t.bdgyear <='||endyear||
317           'and ((direct_amt-zjzf_zc_sum) >= 0 or (accredit_amt-sqzf_zc_sum) >= 0 or (tradition_amt -ybzf_sum) >= 0) '||
318          orgsql||
319           'and zbid not in (select zbz_bal_id from gk_yearbal_heding )';
320 
321 
322 
323 
324 /*select b.id,b.bdgyear,b.fundtype,b.unitno,b.unitid,b.org_id,b.src_id,
325           b.prj_code,b.prj_id,x.zb_project_type,x.prj_end_year,b.bdgt_id_type,b.budgetno,
326          b.budgetid,b.itemno,b.item_id,b.entire_manage,b.adjlevel,
327           b.is_heding,b.yearbal_no,b.direct_amt,b.accredit_amt,b.tradition_amt,b.zb_amt,s.*,
328           (b.direct_amt-s.direct_payamt) zbjy_zjzf,(b.accredit_amt-s.accredit_payamt) zbjy_sqzf,(b.tradition_amt -s.tradition_payamt) zbjy_ybzf,(b.zb_amt-s.sum_payamt) zbjy_sum
329      from (select * from zb_bal where not exists(select * from gk_yearbal_heding where zb_bal.id=gk_yearbal_heding.zbz_bal_id)) b,
330 
331       (select zbid,sum(zjzf_zc_sum) direct_payamt,sum(sqzf_zc_sum) accredit_payamt,
332                sum(ybzf_sum) tradition_payamt,sum(zc_sum) sum_payamt
333           from VIEW_ANNUAL_SPEND_SUMMARY
334          group by zbid) s,(select id,prj_type zb_project_type from bs_xmk) x
335        where b.id = s.zbid(+) and b.prj_id = x.id and b.bdgyear='2017'
336        and ((b.direct_amt-s.direct_payamt) > 0 or (b.accredit_amt-s.accredit_payamt) > 0 or (b.tradition_amt -s.tradition_payamt) > 0)
337 and b.org_id = '106'
338     order by b.fundtype,b.src_id,b.is_heding,b.id*/
339 
340 
341 delete_sql := 'delete from tmp_tab_summary';
342 EXECUTE IMMEDIATE delete_sql;
343 
344 /*select count(*)
345      INTO TABEXT
346      FROM ALL_TABLES
347     WHERE TABLE_NAME = 'tmp_tab_summary';*/
348 
349 /*IF TABEXT = 0 THEN
350    --不存在临时表就创建一个
351    EXECUTE IMMEDIATE create_sql;
352    DBMS_OUTPUT.PUT_LINE('创建临时表成功!');
353 ELSE
354    EXECUTE IMMEDIATE delete_sql;
355    DBMS_OUTPUT.PUT_LINE('删除记录完成!');
356 END IF;*/
357 
358 
359 
360    ---- 向 临时表tmp_tab_summary 中插入  指标信息
361     for  zbinfo IN  zbinfo_loop loop  --遍历游标
362         insert into  tmp_tab_summary ( ZBID,BDGYEAR,UNITID,UNITNO,UNIT_NAME,SRC_ID,SRC_NAME,SRC_TYPENAME,SRC_TYPE,
363     BDGT_ID_TYPE,BDGT_ID_TYPENAME,BUDGETID,BUDGETNO,BUDGETNAME,PRJ_ID,PRJ_CODE,PRJ_CODENAME,ZB_PROJECT_TYPE,PRO_TYPE_NAME,
364     ITEM_ID,ITEMNO,ITEMNAME,ORG_ID,ORG_NAME,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,ADJLEVEL,
365     ADJLEVEL_NAME,YEARBAL_STATUS,YEARBAL_NAME,IS_HEDING,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,
366     FUNDTYPE_NAME,ISSUE_NUM,BZ,IS_UNIFY,IS_FREEZE,ORIGIN_ID,ENTIRE_MANAGE,
367     STARTYM,ENDYM
368     /*ZJZF_ZC,ZJZF_QETK,ZJZF_BFTK,ZCYWTZ_ZJZF_TZQ,ZCYWTZ_ZJZF_TZH,
369     SQZF_ZC,SQZF_QETK,SQZF_BFTK,ZCYWTZ_SQZF_TZQ,ZCYWTZ_SQZF_TZH,
370     YBZF_ZC,YBZF_TK,ZCYWTZ_YBZF_TZQ,ZCYWTZ_YBZF_TZH,
371     ZJZF_ZC_SUM,SQZF_ZC_SUM,YBZF_SUM,ZC_SUM,ZBJY_SUM,ZBJY_ZJZF,ZBJY_SQZF,ZBJY_YBZF*/
372     )
373     values(zbinfo.id,zbinfo.BDGYEAR,zbinfo.UNITID,zbinfo.UNITNO,zbinfo.UNIT_NAME,zbinfo.SRC_ID,zbinfo.SRC_NAME,zbinfo.SRC_TYPENAME,zbinfo.SRC_TYPE,
374     zbinfo.BDGT_ID_TYPE,zbinfo.BDGT_ID_TYPENAME,zbinfo.BUDGETID,zbinfo.BUDGETNO,zbinfo.BUDGETNAME,zbinfo.PRJ_ID,zbinfo.PRJ_CODE,zbinfo.PRJ_CODENAME,zbinfo.ZB_PROJECT_TYPE,zbinfo.PRO_TYPE_NAME,
375     zbinfo.ITEM_ID,zbinfo.ITEMNO,zbinfo.ITEMNAME,zbinfo.ORG_ID,zbinfo.ORG_NAME,zbinfo.ZB_AMT,zbinfo.DIRECT_AMT,zbinfo.ACCREDIT_AMT,zbinfo.DIRECT_PLAN,zbinfo.ACCREDIT_PLAN,zbinfo.TRADITION_AMT,zbinfo.ADJLEVEL,
376     zbinfo.ADJLEVEL_NAME,zbinfo.YEARBAL_STATUS,zbinfo.YEARBAL_NAME,zbinfo.IS_HEDING,zbinfo.EARLY_AMT,zbinfo.EARLY_CHANGE_AMT,zbinfo.ADDITIONAL_AMT,zbinfo.TRADITION_NUM,zbinfo.FUNDTYPE,
377     zbinfo.FUNDTYPE_NAME,zbinfo.ISSUE_NUM,zbinfo.BZ,zbinfo.IS_UNIFY,zbinfo.IS_FREEZE,zbinfo.ORIGIN_ID,zbinfo.ENTIRE_MANAGE,
378     startyear||startmonth,endyear||endmonth) ;
379     --结束游标
380     END LOOP;
381 
382 
383     ----更新  (直接支付)  支出数信息
384      for  zjzf_zc IN  zjzf_zc_loop loop  --遍历游标
385          update   tmp_tab_summary  tts set tts.zjzf_zc=nvl(zjzf_zc.zjzf_zc,0)
386             where tts.zbid= zjzf_zc.zjzf_zc_zbid;
387     --结束游标
388     END LOOP;
389 
390       ----更新  (直接支付) 全额退款 信息
391      for  zjzf_qetk IN  zjzf_qetk_loop loop  --遍历游标
392          update   tmp_tab_summary  tts set tts.zjzf_qetk=nvl(zjzf_qetk.zjzf_qetk,0)
393             where tts.zbid= zjzf_qetk.zjzf_qetk_zbid;
394     --结束游标
395     END LOOP;
396 
397       ----更新  (直接支付) 部分退款 信息
398      for  zjzf_bftk IN  zjzf_bftk_loop loop  --遍历游标
399          update   tmp_tab_summary  tts set tts.zjzf_bftk=nvl(zjzf_bftk.zjzf_bftk,0)
400             where tts.zbid= zjzf_bftk.zjzf_bftk_zbid;
401     --结束游标
402     END LOOP;
403 
404       ----更新  (直接支付) 调整前金额 信息
405      for  zcywtz_zjzf_tzq IN  zcywtz_zjzf_tzq_loop loop  --遍历游标
406          update   tmp_tab_summary  tts set tts.zcywtz_zjzf_tzq=nvl(zcywtz_zjzf_tzq.zcywtz_zjzf_tzq,0)
407             where tts.zbid= zcywtz_zjzf_tzq.zcywtz_zjzf_tzq_zbid;
408     --结束游标
409     END LOOP;
410 
411      ----更新  (直接支付) 调整后金额 信息
412      for  zcywtz_zjzf_tzh IN  zcywtz_zjzf_tzh_loop loop  --遍历游标
413          update   tmp_tab_summary  tts set tts.zcywtz_zjzf_tzh=nvl(zcywtz_zjzf_tzh.zcywtz_zjzf_tzh,0)
414             where tts.zbid= zcywtz_zjzf_tzh.zcywtz_zjzf_tzh_zbid;
415     --结束游标
416     END LOOP;
417 
418 
419     ----更新  (授权支付)  支出数信息
420      for  sqzf_zc IN  sqzf_zc_loop loop  --遍历游标
421          update   tmp_tab_summary  tts set tts.sqzf_zc =nvl(sqzf_zc.sqzf_zc,0)
422             where tts.zbid= sqzf_zc.sqzf_zc_zbid ;
423     --结束游标
424     END LOOP;
425 
426     ----更新  (授权支付)  全额退款金额
427      for  sqzf_qetk IN  sqzf_qetk_loop loop  --遍历游标
428          update   tmp_tab_summary  tts set tts.sqzf_qetk =nvl(sqzf_qetk.sqzf_qetk,0)
429             where tts.zbid= sqzf_qetk.sqzf_qetk_zbid ;
430     --结束游标
431     END LOOP;
432 
433     ----更新  (授权支付)  部分退款金额
434      for  sqzf_bftk IN  sqzf_bftk_loop loop  --遍历游标
435          update   tmp_tab_summary  tts set tts.sqzf_bftk =nvl(sqzf_bftk.sqzf_bftk,0)
436             where tts.zbid= sqzf_bftk.sqzf_bftk_zbid ;
437     --结束游标
438     END LOOP;
439 
440     ----更新  (授权支付)  调整前金额
441      for  zcywtz_sqzf_tzq IN  zcywtz_sqzf_tzq_loop loop  --遍历游标
442          update   tmp_tab_summary  tts set tts.zcywtz_sqzf_tzq =nvl(zcywtz_sqzf_tzq.zcywtz_sqzf_tzq,0)
443             where tts.zbid= zcywtz_sqzf_tzq.zcywtz_sqzf_tzq_zbid ;
444     --结束游标
445     END LOOP;
446 
447     ----更新  (授权支付)  调整后金额
448      for  zcywtz_sqzf_tzh IN  zcywtz_sqzf_tzh_loop loop  --遍历游标
449          update   tmp_tab_summary  tts set tts.zcywtz_sqzf_tzh =nvl(zcywtz_sqzf_tzh.zcywtz_sqzf_tzh,0)
450             where tts.zbid= zcywtz_sqzf_tzh.zcywtz_sqzf_tzh_zbid ;
451     --结束游标
452     END LOOP;
453 
454     ----更新  (一般支付)  支出数信息
455      for  ybzf_zc IN  ybzf_zc_loop loop  --遍历游标
456          update   tmp_tab_summary  tts set tts.ybzf_zc =nvl(ybzf_zc.ybzf_zc,0)
457             where tts.zbid= ybzf_zc.ybzf_zc_zbid ;
458     --结束游标
459     END LOOP;
460 
461      ----更新  (一般支付)  退款金额
462      for  ybzf_tk IN  ybzf_tk_loop loop  --遍历游标
463          update   tmp_tab_summary  tts set tts.ybzf_tk =nvl(ybzf_tk.ybzf_tk,0)
464             where tts.zbid= ybzf_tk.ybzf_tk_zbid ;
465     --结束游标
466     END LOOP;
467 
468     ----更新  (一般支付)  调整前金额
469      for  zcywtz_ybzf_tzq IN  zcywtz_ybzf_tzq_loop loop  --遍历游标
470          update   tmp_tab_summary  tts set tts.zcywtz_ybzf_tzq =nvl(zcywtz_ybzf_tzq.zcywtz_ybzf_tzq,0)
471             where tts.zbid= zcywtz_ybzf_tzq.zcywtz_ybzf_tzq_zbid ;
472     --结束游标
473     END LOOP;
474 
475     ----更新  (一般支付)  调整后金额
476      for  zcywtz_ybzf_tzh IN  zcywtz_ybzf_tzh_loop loop  --遍历游标
477          update   tmp_tab_summary  tts set tts.zcywtz_ybzf_tzh =nvl(zcywtz_ybzf_tzh.zcywtz_ybzf_tzh,0)
478             where tts.zbid= zcywtz_ybzf_tzh.zcywtz_ybzf_tzh_zbid ;
479     --结束游标
480     END LOOP;
481 
482     ----更新  总额
483     for tmpsum in tmp_tab_summary_loop loop
484          update   tmp_tab_summary  tts set
485          tts.zjzf_zc_sum =
486          nvl(nvl(tts.zjzf_zc, 0) - nvl(tts.zjzf_qetk, 0) - nvl(tts.zjzf_bftk,0)- nvl(tts.zcywtz_zjzf_tzq,0)+nvl(tts.zcywtz_zjzf_tzh,0),0),
487          tts.sqzf_zc_sum=
488          nvl((nvl(tts.sqzf_zc, 0) - nvl(tts.sqzf_qetk, 0) - nvl(tts.sqzf_bftk, 0)-nvl(tts.zcywtz_sqzf_tzq,0)+nvl(tts.zcywtz_sqzf_tzh,0)), 0),
489          tts.ybzf_sum=
490          nvl((nvl(tts.ybzf_zc, 0) - nvl(tts.ybzf_tk, 0) - nvl(tts.zcywtz_ybzf_tzq,0)+nvl(tts.zcywtz_ybzf_tzh,0) ), 0),
491          tts.zc_sum=
492               nvl(((nvl(tts.zjzf_zc, 0) - nvl(tts.zjzf_qetk, 0) - nvl(tts.zjzf_bftk, 0)-nvl(tts.zcywtz_zjzf_tzq,0)
493               +nvl(tts.zcywtz_zjzf_tzh,0)  ) + (nvl(tts.sqzf_zc, 0) - nvl(tts.sqzf_qetk, 0) - nvl(tts.sqzf_bftk, 0)
494               -nvl(tts.zcywtz_sqzf_tzq,0)+nvl(tts.zcywtz_sqzf_tzh,0)) + (nvl(tts.ybzf_zc, 0) - nvl(tts.ybzf_tk, 0)
495               - nvl(tts.zcywtz_ybzf_tzq,0)+nvl(tts.zcywtz_ybzf_tzh,0))), 0)
496          where tts.zbid= tmpsum.zbid ;
497     end loop;
498 
499 
500 
501   OPEN v_cur FOR v_sql;
502 
503    commit;
504 
505 end pro_annual_spend_summary ;
506 

 

 

示例4:拼接sql,返回数据结果集合

 

  1 CREATE OR REPLACE PACKAGE PACKAGE_SUPER_INCOME
  2 AS
  3 TYPE CURSOR_SUPER_INCOME
  4 IS
  5   REF
  6   CURSOR;
  7   END PACKAGE_SUPER_INCOME;
  8 

 

  1 CREATE OR REPLACE PROCEDURE PROC_SUPER_INCOME(
  2     YEAR        IN VARCHAR2,
  3     start_time  IN VARCHAR2,
  4     end_time    IN VARCHAR2,
  5     start_month IN VARCHAR2,
  6     end_month   IN VARCHAR2,
  7     P_CURSOR OUT PACKAGE_SUPER_INCOME.CURSOR_SUPER_INCOME)
  8 AS
  9   sqlStr LONG;
 10 BEGIN
 11   sqlStr := 'SELECT NULL RN,NULL PRJ_LEVEL, NULL GP, NULL FUNC_BDGID, NULL FUNC_BDGNAME,null src_id,null src_name, NULL PRJ_NO, ''上级补助收入总计'' PRJ_NAME, NULL FILE_WORD, NULL ZB_ID, NULL BDG_NO, NULL BDG_NAME, t.amt, t.ZB_AMT,t.PAY_AMT, NULL BDG_UNIT, NULL UNIT_NO, NULL UNIT_NAME, NULL INCOME_TIME, NULL DT , NULL CONCLUDE_DT, NULL PAY_COMPLETE_DT, NULL ORG_NAME, NULL HAVE_LZ, NULL HAVE_SUBSIDY ,NULL EARLY_ASSIGNED,NULL ZB_FILE_WORD,NULL COMMENTS,NULL RANK
 12 FROM
 13 (SELECT SUM(v.AMT) amt,
 14 SUM(
 15 CASE
 16 WHEN v.HAVE_LZ=1
 17 THEN v.ZB_AMT
 18 WHEN v.HAVE_SUBSIDY=1
 19 AND v.bdg_UNITNO        =''sys00000''
 20 THEN v.ZB_AMT
 21 ELSE (
 22 CASE NVL(v.ZB_ID,-1)
 23 WHEN           -1
 24 THEN 0
 25 ELSE (
 26 CASE
 27 WHEN v.BIZ_STATUS=9
 28 AND v.CONCLUDE_DT   is null
 29 THEN v.ZB_AMT
 30 WHEN v.BIZ_STATUS=9
 31 AND (v.CONCLUDE_DT BETWEEN to_date(''' ||
 32   start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')  )
 33 THEN v.ZB_AMT
 34 ELSE 0
 35 END)
 36 END)
 37 END
 38 
 39 ) ZB_AMT,
 40 sum(
 41 case
 42 when v.ZJ_TYPE=1 then 0
 43 else (
 44 CASE
 45 WHEN v.HAVE_LZ=1
 46 THEN v.AMT
 47 WHEN v.HAVE_SUBSIDY=1
 48 AND v.bdg_UNITNO        =''sys00000''
 49 THEN v.AMT
 50 ELSE
 51 (SELECT SUM(ZC_SUM) PAY_AMT
 52 FROM VIEW_ANNUAL_SPEND_SUMMARY
 53 WHERE ZBID=v.ZB_ID and BDGYEARMON BETWEEN ''' || start_month || ''' AND ''' || end_month || '''
 54 GROUP BY ZBID
 55 )
 56 END) end) PAY_AMT
 57 FROM VIEW_SUPER_INCOME_IDX_TAB v
 58 where v.LZ_YEAR=''' || YEAR || ''' AND v.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
 59   ''',''yyyy-mm-dd'')
 60 )t
 61 UNION ALL
 62 select * from(
 63 select
 64 
 65 t4.*,rank() over(partition BY t4.gp order by t4.rn asc) rank
 66 from(
 67 SELECT rownum rn,t3.*
 68 FROM
 69 (SELECT DECODE(t1.num,5,1, 4, 2, 3, 3, 2, 4, 1, 5) PRJ_LEVEL,
 70 DECODE(t1.num,5,1,
 71 4, 11,
 72 3, t1.BDG_TYPE || 3,
 73 2, t1.BDG_TYPE || t1.BDG_NO_THREE || 5,
 74 1, t1.BDG_TYPE || t1.BDG_NO_FIVE || 7) gp,
 75 t2.FUNC_BDGID,
 76 t2.FUNC_BDGNAME,
 77 t2.src_id,
 78 t2.src_name,
 79 t2.PRJ_NO,
 80 DECODE(t1.num,5,''一、专项转移支付收入合计'', 4,
 81 (SELECT dd.dict_text
 82 FROM pwp_dict pd
 83 LEFT JOIN pwp_dict_detail dd
 84 ON pd.dict_id    =dd.dict_id
 85 WHERE dict_name  = ''funBudgetType''
 86 AND dd.dict_value=t1.BDG_TYPE
 87 ), 3,
 88 (SELECT bg.FUNC_BDGNAME
 89 FROM BS_GNFLYSKM bg
 90 WHERE t1.BDG_TYPE   =bg.FUNC_BDG_TYPE
 91 AND t1.BDG_NO_THREE =bg.FUNC_BDGID
 92 AND bg.BDGYEAR      =' || YEAR ||
 93   '      AND bg.IS_ON          =''Y''
 94 ), 2,
 95 (SELECT SUBSTR(bg.FUNC_BDGNAME,(instr(bg.FUNC_BDGNAME,''--'',-1)+2))
 96 FROM BS_GNFLYSKM bg
 97 WHERE t1.BDG_TYPE  =bg.FUNC_BDG_TYPE
 98 AND t1.BDG_NO_FIVE =bg.FUNC_BDGID
 99 AND bg.BDGYEAR     =' || YEAR || '    AND bg.IS_ON          =''Y''
100 ), 1,
101 (SELECT SUBSTR(bg.FUNC_BDGNAME,(instr(bg.FUNC_BDGNAME,''--'',-1)+2))
102 FROM BS_GNFLYSKM bg
103 WHERE t1.BDG_TYPE=bg.FUNC_BDG_TYPE
104 AND t1.BDG_NO    =bg.FUNC_BDGID
105 AND bg.BDGYEAR   =' || YEAR ||
106   '    AND bg.IS_ON          =''Y''
107 ), t2.PRJ_NAME) PRJ_NAME,
108 t2.FILE_WORD,
109 t2.ZB_ID,
110 t2.BDG_NO,
111 t2.BDG_NAME,
112 t1.amt,
113 t1.ZB_AMT,
114 t1.PAY_AMT,
115 t2.BDG_UNIT,
116 t2.UNIT_NO,
117 t2.UNIT_NAME,
118 TO_CHAR(t2.INCOME_TIME,''yyyy-mm-dd'') INCOME_TIME,
119 to_char(t2.DT,''yyyy-mm-dd'') DT,
120 to_char(
121 
122 
123 (CASE
124 WHEN t2.HAVE_LZ=1
125 THEN t2.CONCLUDE_DT
126 WHEN t2.HAVE_SUBSIDY=1
127 AND t2.bdg_UNITNO        =''sys00000''
128 THEN t2.CONCLUDE_DT
129 ELSE (
130 CASE
131 WHEN t2.BIZ_STATUS=9
132 AND (t2.CONCLUDE_DT BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
133   ''',''yyyy-mm-dd'')  )
134 THEN t2.CONCLUDE_DT
135 ELSE null
136 END
137 )
138 END)
139 ,''yyyy-mm-dd'') CONCLUDE_DT,
140 to_char((case
141 when t1.ZB_AMT=t1.PAY_AMT then t2.PAY_COMPLETE_DT
142 else null
143 end),''yyyy-mm-dd'') PAY_COMPLETE_DT,
144 t2.ORG_NAME,
145 t2.HAVE_LZ,
146 t2.HAVE_SUBSIDY ,
147 t2.EARLY_ASSIGNED,
148 t2.ZB_FILE_WORD,
149 t2.COMMENTS
150 FROM
151 (SELECT t.yzd_id,
152 t.BDG_TYPE,
153 T.BDG_NO_THREE,
154 T.BDG_NO_FIVE,
155 t.bdg_no,
156 grouping(t.yzd_id)+grouping(t.BDG_TYPE)+grouping(t.BDG_NO_THREE)+grouping(t.BDG_NO_FIVE)+grouping(t.bdg_no) num,
157 SUM(t.AMT) amt,
158 SUM( CASE
159 WHEN t.HAVE_LZ=1
160 THEN t.ZB_AMT
161 WHEN t.HAVE_SUBSIDY=1
162 AND t.bdg_UNITNO        =''sys00000''
163 THEN t.ZB_AMT
164 ELSE (
165 CASE NVL(t.ZB_ID,-1)
166 WHEN           -1
167 THEN 0
168 ELSE (
169 CASE
170 WHEN t.BIZ_STATUS=9
171 AND t.CONCLUDE_DT   is null
172 THEN t.ZB_AMT
173 WHEN t.BIZ_STATUS=9
174 AND (t.CONCLUDE_DT BETWEEN to_date('''
175   || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')  )
176 THEN t.ZB_AMT
177 ELSE 0
178 END)
179 END)
180 END ) ZB_AMT,
181 sum(
182 case
183 when t.ZJ_TYPE=1 then 0
184 else (
185 CASE
186 WHEN t.HAVE_LZ=1
187 THEN t.AMT
188 WHEN t.HAVE_SUBSIDY=1
189 AND t.bdg_UNITNO        =''sys00000''
190 THEN t.AMT
191 ELSE
192 (SELECT SUM(ZC_SUM) PAY_AMT
193 FROM VIEW_ANNUAL_SPEND_SUMMARY
194 WHERE ZBID=t.ZB_ID and BDGYEARMON BETWEEN ''' || start_month || ''' AND ''' || end_month || '''
195 GROUP BY ZBID
196 )
197 END) end) PAY_AMT
198 FROM
199 (SELECT SUBSTR(v.bdg_no,0,3) bdg_no_three,
200 SUBSTR(v.BDG_NO,0,5) bdg_no_five,
201 v.*
202 FROM VIEW_SUPER_INCOME_IDX_TAB v
203 WHERE (v.FUNC_BDGID IS NULL
204 OR (v.FUNC_BDGID NOT LIKE ''11002%''
205 AND v.FUNC_BDGID NOT LIKE ''11001%''
206 AND v.FUNC_BDGID NOT LIKE ''11011%''))
207 AND  v.LZ_YEAR='''
208   || YEAR || ''' AND  v.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')
209 ) t
210 GROUP BY rollup(t.BDG_TYPE,T.BDG_NO_THREE,T.BDG_NO_FIVE,t.bdg_no,t.yzd_id)
211 )t1
212 LEFT JOIN VIEW_SUPER_INCOME_IDX_TAB t2
213 ON T1.YZD_ID=t2.YZD_ID
214 AND  t2.LZ_YEAR=''' || YEAR || ''' AND  t2.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
215   ''',''yyyy-mm-dd'')
216 ORDER BY t1.BDG_TYPE nulls FIRST,
217 T1.BDG_NO_THREE nulls FIRST,
218 T1.BDG_NO_FIVE nulls FIRST,
219 t1.bdg_no nulls FIRST ,
220 t1.yzd_id nulls FIRST
221 )t3)t4 order by t4.rn asc)
222 UNION ALL
223 --------------------------------------------------------
224 select * from(
225 select
226 
227 t4.*,rank() over(partition BY t4.gp order by t4.rn asc) rank
228 from(
229 SELECT rownum rn,t3.*
230 FROM
231 (SELECT DECODE(t1.num,3,1, 2, 2, 1, 3) PRJ_LEVEL,
232 DECODE(t1.num,3,1,
233 2, 11,
234 1, t1.BDG_TYPE  || 7) gp,
235 t2.FUNC_BDGID,
236 t2.FUNC_BDGNAME,
237 t2.src_id,
238 t2.src_name,
239 t2.PRJ_NO,
240 DECODE(t1.num,3,''二、一般性转移支付收入合计'', 2,
241 (SELECT dd.dict_text
242 FROM pwp_dict pd
243 LEFT JOIN pwp_dict_detail dd
244 ON pd.dict_id    =dd.dict_id
245 WHERE dict_name  = ''funBudgetType''
246 AND dd.dict_value=t1.BDG_TYPE
247 ), 1,
248 (SELECT bg.FUNC_BDGNAME
249 FROM BS_GNFLYSKM bg
250 WHERE
251 --   t1.BDG_TYPE=bg.FUNC_BDG_TYPE AND
252 t1.FUNC_BDGID =bg.FUNC_BDGID
253 AND bg.BDGYEAR  =' || YEAR ||
254   '    AND bg.IS_ON          =''Y''
255 ), t2.PRJ_NAME) PRJ_NAME,
256 t2.FILE_WORD,
257 t2.ZB_ID,
258 t2.BDG_NO,
259 t2.BDG_NAME,
260 t1.amt,
261 t1.ZB_AMT,
262 t1.PAY_AMT,
263 t2.BDG_UNIT,
264 t2.UNIT_NO,
265 t2.UNIT_NAME,
266 TO_CHAR(t2.INCOME_TIME,''yyyy-mm-dd'') INCOME_TIME,
267 to_char(t2.DT,''yyyy-mm-dd'') DT,
268 to_char(
269 (CASE
270 WHEN t2.HAVE_LZ=1
271 THEN t2.CONCLUDE_DT
272 WHEN t2.HAVE_SUBSIDY=1
273 AND t2.bdg_UNITNO        =''sys00000''
274 THEN t2.CONCLUDE_DT
275 ELSE (
276 CASE
277 WHEN t2.BIZ_STATUS=9
278 AND (t2.CONCLUDE_DT BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
279   ''',''yyyy-mm-dd'')  )
280 THEN t2.CONCLUDE_DT
281 
282 ELSE null
283 END
284 
285 
286 )
287 END)
288 ,''yyyy-mm-dd'') CONCLUDE_DT,
289 to_char((case
290 when t1.ZB_AMT=t1.PAY_AMT then t2.PAY_COMPLETE_DT
291 else null
292 end),''yyyy-mm-dd'') PAY_COMPLETE_DT,
293 t2.ORG_NAME,
294 t2.HAVE_LZ,
295 t2.HAVE_SUBSIDY  ,
296 t2.EARLY_ASSIGNED,
297 t2.ZB_FILE_WORD,
298 t2.COMMENTS
299 FROM
300 (SELECT t.yzd_id,
301 t.BDG_TYPE,
302 t.FUNC_BDGID,
303 grouping(t.yzd_id)+grouping(t.BDG_TYPE)+grouping(t.FUNC_BDGID) num,
304 SUM(t.AMT) AMT,
305 SUM( CASE
306 WHEN t.HAVE_LZ=1
307 THEN t.ZB_AMT
308 WHEN t.HAVE_SUBSIDY=1
309 AND t.bdg_UNITNO        =''sys00000''
310 THEN t.ZB_AMT
311 ELSE (
312 CASE NVL(t.ZB_ID,-1)
313 WHEN           -1
314 THEN 0
315 ELSE (
316 CASE
317 WHEN t.BIZ_STATUS=9
318 AND t.CONCLUDE_DT   is null
319 THEN t.ZB_AMT
320 WHEN t.BIZ_STATUS=9
321 AND (t.CONCLUDE_DT BETWEEN to_date('''
322   || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')  )
323 THEN t.ZB_AMT
324 ELSE 0
325 END)
326 END)
327 END) ZB_AMT,
328 sum(
329 case
330 when t.ZJ_TYPE=1 then 0
331 else (
332 CASE
333 WHEN t.HAVE_LZ=1
334 THEN t.AMT
335 WHEN t.HAVE_SUBSIDY=1
336 AND t.bdg_UNITNO        =''sys00000''
337 THEN t.AMT
338 ELSE
339 (SELECT SUM(ZC_SUM) PAY_AMT
340 FROM VIEW_ANNUAL_SPEND_SUMMARY
341 WHERE ZBID=t.ZB_ID and BDGYEARMON BETWEEN ''' || start_month || ''' AND ''' || end_month || '''
342 GROUP BY ZBID
343 )
344 END) end) PAY_AMT
345 FROM
346 (SELECT v.*
347 FROM VIEW_SUPER_INCOME_IDX_TAB v
348 WHERE v.FUNC_BDGID LIKE ''11002%''
349 AND  v.LZ_YEAR=''' || YEAR || ''' AND  v.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
350   ''',''yyyy-mm-dd'')
351 ) t
352 GROUP BY rollup(t.BDG_TYPE,t.FUNC_BDGID,t.yzd_id)
353 )t1
354 LEFT JOIN VIEW_SUPER_INCOME_IDX_TAB t2
355 ON T1.YZD_ID=t2.YZD_ID
356 AND  t2.LZ_YEAR=''' || YEAR || ''' AND  t2.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
357   ''',''yyyy-mm-dd'')
358 ORDER BY t1.BDG_TYPE nulls FIRST,
359 T1.FUNC_BDGID nulls FIRST,
360 t1.yzd_id nulls FIRST
361 )t3 )t4 order by t4.rn asc)
362 UNION ALL
363 --------------------------------------------------------------------
364 select * from(
365 select
366 
367 t4.*,rank() over(partition BY t4.gp order by t4.rn asc) rank
368 from(
369 SELECT rownum rn,t3.*
370 FROM
371 (SELECT DECODE(t1.num,3,1, 2, 2, 1, 3) PRJ_LEVEL,
372 DECODE(t1.num,3,1,
373 2, 11,
374 1, t1.BDG_TYPE  || 7) gp,
375 t2.FUNC_BDGID,
376 t2.FUNC_BDGNAME,
377 t2.src_id,
378 t2.src_name,
379 t2.PRJ_NO,
380 DECODE(t1.num,3,''三、返还性收入合计'', 2,
381 (SELECT dd.dict_text
382 FROM pwp_dict pd
383 LEFT JOIN pwp_dict_detail dd
384 ON pd.dict_id    =dd.dict_id
385 WHERE dict_name  = ''funBudgetType''
386 AND dd.dict_value=t1.BDG_TYPE
387 ), 1,
388 (SELECT bg.FUNC_BDGNAME
389 FROM BS_GNFLYSKM bg
390 WHERE
391 --   t1.BDG_TYPE=bg.FUNC_BDG_TYPE AND
392 t1.FUNC_BDGID =bg.FUNC_BDGID
393 AND bg.BDGYEAR  =' || YEAR ||
394   '    AND bg.IS_ON          =''Y''
395 ), t2.PRJ_NAME) PRJ_NAME,
396 t2.FILE_WORD,
397 t2.ZB_ID,
398 t2.BDG_NO,
399 t2.BDG_NAME,
400 t1.amt,
401 t1.ZB_AMT,
402 t1.PAY_AMT,
403 t2.BDG_UNIT,
404 t2.UNIT_NO,
405 t2.UNIT_NAME,
406 TO_CHAR(t2.INCOME_TIME,''yyyy-mm-dd'') INCOME_TIME,
407 to_char(t2.DT,''yyyy-mm-dd'') DT,
408 to_char(
409 (CASE
410 WHEN t2.HAVE_LZ=1
411 THEN t2.CONCLUDE_DT
412 WHEN t2.HAVE_SUBSIDY=1
413 AND t2.bdg_UNITNO        =''sys00000''
414 THEN t2.CONCLUDE_DT
415 ELSE (
416 CASE
417 WHEN t2.BIZ_STATUS=9
418 AND (t2.CONCLUDE_DT BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
419   ''',''yyyy-mm-dd'')  )
420 THEN t2.CONCLUDE_DT
421 
422 ELSE null
423 END
424 
425 
426 )
427 END)
428 ,''yyyy-mm-dd'') CONCLUDE_DT,
429 to_char((case
430 when t1.ZB_AMT=t1.PAY_AMT then t2.PAY_COMPLETE_DT
431 else null
432 end),''yyyy-mm-dd'') PAY_COMPLETE_DT,
433 t2.ORG_NAME,
434 t2.HAVE_LZ,
435 t2.HAVE_SUBSIDY,
436 t2.EARLY_ASSIGNED,
437 t2.ZB_FILE_WORD,
438 t2.COMMENTS
439 FROM
440 (SELECT t.yzd_id,
441 t.BDG_TYPE,
442 t.FUNC_BDGID,
443 grouping(t.yzd_id)+grouping(t.BDG_TYPE)+grouping(t.FUNC_BDGID) num,
444 SUM(t.AMT) AMT,
445 SUM( CASE
446 WHEN t.HAVE_LZ=1
447 THEN t.ZB_AMT
448 WHEN t.HAVE_SUBSIDY=1
449 AND t.bdg_UNITNO        =''sys00000''
450 THEN t.ZB_AMT
451 ELSE (
452 CASE NVL(t.ZB_ID,-1)
453 WHEN           -1
454 THEN 0
455 ELSE (
456 CASE
457 WHEN t.BIZ_STATUS=9
458 AND t.CONCLUDE_DT   is null
459 THEN t.ZB_AMT
460 WHEN t.BIZ_STATUS=9
461 AND (t.CONCLUDE_DT BETWEEN to_date('''
462   || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')  )
463 THEN t.ZB_AMT
464 ELSE 0
465 END)
466 END)
467 END) ZB_AMT,
468 sum(
469 case
470 when t.ZJ_TYPE=1 then 0
471 else (
472 CASE
473 WHEN t.HAVE_LZ=1
474 THEN t.AMT
475 WHEN t.HAVE_SUBSIDY=1
476 AND t.bdg_UNITNO        =''sys00000''
477 THEN t.AMT
478 ELSE
479 (SELECT SUM(ZC_SUM) PAY_AMT
480 FROM VIEW_ANNUAL_SPEND_SUMMARY
481 WHERE ZBID=t.ZB_ID and BDGYEARMON BETWEEN ''' || start_month || ''' AND ''' || end_month || '''
482 GROUP BY ZBID
483 )
484 END) end) PAY_AMT
485 FROM
486 (SELECT v.*
487 FROM VIEW_SUPER_INCOME_IDX_TAB v
488 WHERE v.FUNC_BDGID LIKE ''11001%''
489 AND  v.LZ_YEAR=''' || YEAR || ''' AND  v.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
490   ''',''yyyy-mm-dd'')
491 ) t
492 GROUP BY rollup(t.BDG_TYPE,t.FUNC_BDGID,t.yzd_id)
493 )t1
494 LEFT JOIN VIEW_SUPER_INCOME_IDX_TAB t2
495 ON T1.YZD_ID=t2.YZD_ID
496 AND  t2.LZ_YEAR=''' || YEAR || ''' AND  t2.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
497   ''',''yyyy-mm-dd'')
498 ORDER BY t1.BDG_TYPE nulls FIRST,
499 T1.FUNC_BDGID nulls FIRST,
500 t1.yzd_id nulls FIRST
501 )t3 )t4 order by t4.rn asc)
502 UNION ALL
503 -------------------------------------------------------
504 select * from(
505 select
506 
507 t4.*,rank() over(partition BY t4.gp order by t4.rn asc) rank
508 from(
509 SELECT rownum rn,t3.*
510 FROM
511 (SELECT DECODE(t1.num,3,1, 2, 2, 1, 3) PRJ_LEVEL,
512 DECODE(t1.num,3,1,
513 2, 11,
514 1, t1.BDG_TYPE  || 7) gp,
515 t2.FUNC_BDGID,
516 t2.FUNC_BDGNAME,
517 t2.src_id,
518 t2.src_name,
519 t2.PRJ_NO,
520 DECODE(t1.num,3,''四、债务转贷收入合计'', 2,
521 (SELECT dd.dict_text
522 FROM pwp_dict pd
523 LEFT JOIN pwp_dict_detail dd
524 ON pd.dict_id    =dd.dict_id
525 WHERE dict_name  = ''funBudgetType''
526 AND dd.dict_value=t1.BDG_TYPE
527 ), 1,
528 (SELECT bg.FUNC_BDGNAME
529 FROM BS_GNFLYSKM bg
530 WHERE
531 --   t1.BDG_TYPE=bg.FUNC_BDG_TYPE AND
532 t1.FUNC_BDGID =bg.FUNC_BDGID
533 AND bg.BDGYEAR  =' || YEAR ||
534   '  AND bg.IS_ON          =''Y''
535 ), t2.PRJ_NAME) PRJ_NAME,
536 t2.FILE_WORD,
537 t2.ZB_ID,
538 t2.BDG_NO,
539 t2.BDG_NAME,
540 t1.amt,
541 t1.ZB_AMT,
542 t1.PAY_AMT,
543 t2.BDG_UNIT,
544 t2.UNIT_NO,
545 t2.UNIT_NAME,
546 TO_CHAR(t2.INCOME_TIME,''yyyy-mm-dd'') INCOME_TIME,
547 to_char(t2.DT,''yyyy-mm-dd'') DT,
548 to_char(
549 (CASE
550 WHEN t2.HAVE_LZ=1
551 THEN t2.CONCLUDE_DT
552 WHEN t2.HAVE_SUBSIDY=1
553 AND t2.bdg_UNITNO        =''sys00000''
554 THEN t2.CONCLUDE_DT
555 ELSE (
556 CASE
557 WHEN t2.BIZ_STATUS=9
558 AND (t2.CONCLUDE_DT BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
559   ''',''yyyy-mm-dd'')  )
560 THEN t2.CONCLUDE_DT
561 
562 ELSE null
563 END
564 
565 
566 )
567 END)
568 ,''yyyy-mm-dd'') CONCLUDE_DT,
569 to_char((case
570 when t1.ZB_AMT=t1.PAY_AMT then t2.PAY_COMPLETE_DT
571 else null
572 end),''yyyy-mm-dd'') PAY_COMPLETE_DT,
573 t2.ORG_NAME,
574 t2.HAVE_LZ,
575 t2.HAVE_SUBSIDY,
576 t2.EARLY_ASSIGNED,
577 t2.ZB_FILE_WORD,
578 t2.COMMENTS
579 FROM
580 (SELECT t.yzd_id,
581 t.BDG_TYPE,
582 t.FUNC_BDGID,
583 grouping(t.yzd_id)+grouping(t.BDG_TYPE)+grouping(t.FUNC_BDGID) num,
584 SUM(t.AMT) AMT,
585 SUM( CASE
586 WHEN t.HAVE_LZ=1
587 THEN t.ZB_AMT
588 WHEN t.HAVE_SUBSIDY=1
589 AND t.bdg_UNITNO        =''sys00000''
590 THEN t.ZB_AMT
591 ELSE (
592 CASE NVL(t.ZB_ID,-1)
593 WHEN           -1
594 THEN 0
595 ELSE (
596 CASE
597 WHEN t.BIZ_STATUS=9
598 AND t.CONCLUDE_DT   is null
599 THEN t.ZB_AMT
600 WHEN t.BIZ_STATUS=9
601 AND (t.CONCLUDE_DT BETWEEN to_date('''
602   || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')  )
603 THEN t.ZB_AMT
604 ELSE 0
605 END)
606 END)
607 END) ZB_AMT,
608 sum(
609 case
610 when t.ZJ_TYPE=1 then 0
611 else (
612 CASE
613 WHEN t.HAVE_LZ=1
614 THEN t.AMT
615 WHEN t.HAVE_SUBSIDY=1
616 AND t.bdg_UNITNO        =''sys00000''
617 THEN t.AMT
618 ELSE
619 (SELECT SUM(ZC_SUM) PAY_AMT
620 FROM VIEW_ANNUAL_SPEND_SUMMARY
621 WHERE ZBID=t.ZB_ID and BDGYEARMON BETWEEN ''' || start_month || ''' AND ''' || end_month || '''
622 GROUP BY ZBID
623 )
624 END) end) PAY_AMT
625 FROM
626 (SELECT v.*
627 FROM VIEW_SUPER_INCOME_IDX_TAB v
628 WHERE v.FUNC_BDGID LIKE ''11011%''
629 AND  v.LZ_YEAR=''' || YEAR || ''' AND  v.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time ||
630   ''',''yyyy-mm-dd'')
631 ) t
632 GROUP BY rollup(t.BDG_TYPE,t.FUNC_BDGID,t.yzd_id)
633 )t1
634 LEFT JOIN VIEW_SUPER_INCOME_IDX_TAB t2
635 ON T1.YZD_ID=t2.YZD_ID
636 
637 AND  t2.LZ_YEAR=''' || YEAR || ''' AND  t2.INCOME_TIME BETWEEN to_date(''' || start_time || ''',''yyyy-mm-dd'') AND to_date(''' || end_time || ''',''yyyy-mm-dd'')
638 ORDER BY t1.BDG_TYPE nulls FIRST,
639 T1.FUNC_BDGID nulls FIRST,
640 t1.yzd_id nulls FIRST
641 )t3 )t4 order by t4.rn asc) ';
642   OPEN P_CURSOR FOR sqlStr;
643 END;
644 

 

 

  1 CREATE OR REPLACE PACKAGE PACKAGE_PRJ_PAY_INDEX
  2 AS
  3 TYPE CURSOR_PRJ_PAY_INDEX
  4 IS
  5   REF
  6   CURSOR;
  7   END PACKAGE_PRJ_PAY_INDEX;
  8 
  9 
 10 
 11 
 12 CREATE OR REPLACE PROCEDURE PROC_PRJ_PAY_INDEX(
 13     bdgyear     IN VARCHAR2,
 14     pre_bdgyear IN VARCHAR2,
 15     unitno      IN VARCHAR2,
 16     P_CURSOR OUT PACKAGE_PRJ_PAY_INDEX.CURSOR_PRJ_PAY_INDEX)
 17 AS
 18   sqlStr LONG;
 19 BEGIN
 20   sqlStr := '
 21 select
 22 DECODE(num,4,1, 3, 2, 0, 3) lev,
 23 DECODE(num,3,DECODE(ENTIRE_MANAGE,''0'',''一、日常业务性专项'',''1'',''二、政策、基建及债务专项''),0,PRJ_NAME)
 24 PRJ_NAME,subject,total,pre_bdg_funds,pre_fee_income,pre_fund_income,pre_cur_other,
 25 bdg_funds,fee_income,  fund_Income,  spec_bal, normal_bal,cur_other,  direct_pay, auth_pay
 26 from(
 27 select  grouping(ENTIRE_MANAGE)+grouping(PRJ_NAME)+grouping(subject)+grouping(BUDGET_YEAR) num,
 28 ENTIRE_MANAGE,PRJ_NAME,subject,BUDGET_YEAR,
 29 SUM(amt) total,
 30 SUM(pre_bdg_funds) pre_bdg_funds,
 31 SUM(pre_fee_income) pre_fee_income,
 32 SUM(pre_fund_income) pre_fund_income,
 33 SUM(pre_cur_other) pre_cur_other,
 34 SUM(bdg_funds) bdg_funds,
 35 SUM(fee_income) fee_income,
 36 SUM(fund_Income) fund_Income,
 37 SUM(spec_bal) spec_bal,
 38 SUM(normal_bal) normal_bal,
 39 SUM(cur_other) cur_other,
 40 SUM(direct_pay) direct_pay,
 41 SUM(auth_pay) auth_pay
 42 from (select * from view_prj_pay_index where UNITNO=''' || unitno || ''' and BUDGET_YEAR=''' || bdgyear ||
 43   '''  
 44 union all
 45 select * from VIEW_PRE_PRJ_PAY_INDEX where UNITNO=''' || unitno || ''' and BUDGET_YEAR=''' || pre_bdgyear || ''')
 46 group by rollup(ENTIRE_MANAGE,(PRJ_NAME,subject,BUDGET_YEAR)) order by ENTIRE_MANAGE nulls first,BUDGET_YEAR desc nulls first,PRJ_NAME nulls first,subject nulls first
 47 ) where num <> 4';
 48   OPEN P_CURSOR FOR sqlStr;
 49 END;

 

  1 CREATE OR REPLACE PACKAGE PACKAGE_finan_income_pay_bdg
  2 AS
  3 TYPE CURSOR_finan_income_pay_bdg
  4 IS
  5   REF
  6   CURSOR;
  7   END;
  8 
  9 
 10 create or replace procedure proc_finan_income_pay_bdg( unitno IN VARCHAR2,BDGYEAR in VARCHAR2,pre_BDGYEAR in VARCHAR2,
 11     p_CURSOR OUT PACKAGE_finan_income_pay_bdg.CURSOR_finan_income_pay_bdg)
 12     as
 13     sqlStr long;
 14     begin
 15     sqlStr := '
 16     select m.income_item,m.footing_amt income_footing_amt,n.gn_no,n.footing_amt pay_footing_amt from(
 17 -------收入项目
 18 select t1.rn,t1.income_item,t1.footing_amt from (
 19 -- 一、一般公共预算
 20 select 1 rn,''一、一般公共预算'' income_item,t.footing_amt from(
 21 select sum(amt) footing_amt from VIEW_BASIC_DATA where src_no=''000'' and BUDGET_TYPE=''2''
 22 and UNITNO=''' || unitno || ''' and BDGYEAR=''' || BDGYEAR || '''
 23 ) t
 24 -- 二、政府性基金预算
 25 union all
 26 select 2 rn,''二、政府性基金预算'' income_item,t.footing_amt from(
 27 select sum(amt) footing_amt from VIEW_BASIC_DATA where src_no=''000'' and BUDGET_TYPE=''4''
 28 and UNITNO=''' || unitno || ''' and BDGYEAR=''' || BDGYEAR || '''
 29 )t
 30 -- 三、国有资本经营预算
 31 union all
 32 select 3 rn,''三、国有资本经营预算'' income_item,t.footing_amt from(
 33 select sum(amt) footing_amt from VIEW_BASIC_DATA where src_no=''000'' and BUDGET_TYPE=''10''
 34 and UNITNO=''' || unitno || ''' and BDGYEAR=''' || BDGYEAR || '''
 35 )t
 36 --八、财政账户上年项目结转
 37 union all
 38 select 4 rn,''四、财政账户上年项目结转'' income_item,t.footing_amt from
 39 (select sum(gyhd.CZ_HEZHUN_AMT) footing_amt from old_gk_yearbal_heding gyh
 40 left join old_gk_yearbal_heding_detail gyhd on gyh.GK_HEDING_ID=gyhd.GK_HEDING_ID
 41 where gyh.unit_id=''' || unitno || ''' and gyh.YEAR=''' || pre_BDGYEAR || '''
 42 )t
 43 )t1)m
 44 full join
 45 -----------------------------------------------------------------------
 46 ------支出项目
 47 (select t2.gn_no,t2.footing_amt,rownum rn from(
 48 select t1.gn_no,t1.footing_amt from(
 49 select t.gn_no,sum(amt) footing_amt from(
 50 select BUDGET_TYPE,substr(BUDGETNO,0,3) gn_no,amt from VIEW_BASIC_DATA where src_no=''000'' and UNITNO=''' || unitno || ''' and BDGYEAR=''' || BDGYEAR || '''
 51 union all
 52 select gyhd.BDGT_ID_TYPE,substr(gyhd.bdgt_id,0,3) gn_no,gyhd.CZ_HEZHUN_AMT amt from old_gk_yearbal_heding gyh
 53 left join old_gk_yearbal_heding_detail gyhd on gyh.GK_HEDING_ID=gyhd.GK_HEDING_ID
 54 where gyh.unit_id=''' || unitno || ''' and gyh.YEAR=''' || pre_BDGYEAR || '''
 55 )t group by t.gn_no
 56 ) t1
 57 order by t1.gn_no)t2)n on m.rn=n.rn';
 58 
 59 OPEN p_CURSOR FOR sqlStr;
 60 end;
 61 

 

 

 

 

示例5:无入参无出参

 

 

 

  1 create or replace procedure proc_newfile is
  2 begin
  3  --更新新附件状态
  4 update  PWP_UPLOAD set NEWFILE = 0;
  5 ---有新附件(无发票)改为由附件
  6 update GK_ZJZFSQ set IS_INVOICE = 1 where IS_INVOICE=2;
  7  commit;
  8 end proc_newfile;

 

示例6:仅仅入参

  1 CREATE OR REPLACE PROCEDURE proc_import_lastyear_gyzcbz(
  2     pre_bdgyear IN NUMBER,
  3     cur_bdgyear IN NUMBER)
  4 AS
  5   CURSOR ft_cur
  6   IS
  7     SELECT t.* FROM YS_GYZCBZGL t WHERE t.BDGYEAR=pre_bdgyear ;
  8   ft_row ft_cur%ROWTYPE;
  9   PNEXTID pwp_nodtl.NEXTID%TYPE;
 10 BEGIN
 11   DELETE FROM YS_GYZCBZGL WHERE BDGYEAR=cur_bdgyear ;
 12   SELECT NEXTID INTO PNEXTID FROM pwp_nodtl WHERE noid='YS_GYZCBZGL_SEQ';
 13   OPEN ft_cur;
 14   LOOP
 15     FETCH ft_cur INTO ft_row;
 16     IF ft_cur%NOTFOUND THEN
 17       EXIT;
 18     ELSE
 19       INSERT
 20       INTO YS_GYZCBZGL
 21         (
 22           ID,
 23           BDGYEAR,
 24           BIZ_STATUS,
 25           STANDARD_VAL,
 26           STANDARD_NO,
 27           STANDARD_NAME,
 28           ITEMID,
 29           ITEMNO,
 30           ITEM_NAME,
 31           OPER_ACCOUNT,
 32           OPER_DT,
 33           OPER_ORG,
 34           JOINT_ID
 35         )
 36         VALUES
 37         (
 38           PNEXTID,
 39           cur_bdgyear,
 40           ft_row.BIZ_STATUS,
 41           ft_row.STANDARD_VAL,
 42           ft_row.STANDARD_NO,
 43           ft_row.STANDARD_NAME,
 44           ft_row.ITEMID,
 45           ft_row.ITEMNO,
 46           ft_row.ITEM_NAME,
 47           ft_row.OPER_ACCOUNT,
 48           ft_row.OPER_DT,
 49           ft_row.OPER_ORG,
 50           ft_row.JOINT_ID
 51         );
 52       PNEXTID := PNEXTID + 1;
 53     END IF;
 54   END LOOP;
 55   UPDATE pwp_nodtl SET NEXTID=PNEXTID WHERE noid='YS_GYZCBZGL_SEQ';
 56   COMMIT;
 57   CLOSE ft_cur;
 58 END;
 59 

 

 

  1 CREATE OR REPLACE PROCEDURE proc_drop_temp_prj_pay_index(
  2     a IN NUMBER)
  3 AS
  4   truncate_sql VARCHAR2(500);
  5   drop_isql    VARCHAR2(500);
  6 BEGIN
  7   truncate_sql:='truncate table temp_prj_pay_index';
  8   EXECUTE immediate truncate_sql;
  9   drop_isql:='drop table temp_prj_pay_index ';
 10   EXECUTE immediate drop_isql;
 11   truncate_sql:='truncate table temp_pre_index';
 12   EXECUTE immediate truncate_sql;
 13   drop_isql:='drop table  temp_pre_index ';
 14   EXECUTE immediate drop_isql;
 15   truncate_sql:='truncate table temp_zc';
 16   EXECUTE immediate truncate_sql;
 17   drop_isql:='drop table temp_zc ';
 18   EXECUTE immediate drop_isql;
 19   truncate_sql:='truncate table temp_rc';
 20   EXECUTE immediate truncate_sql;
 21   drop_isql:='drop table temp_rc ';
 22   EXECUTE immediate drop_isql;
 23   truncate_sql:='truncate table temp_pre_balance';
 24   EXECUTE immediate truncate_sql;
 25   drop_isql:='drop table  temp_pre_balance ';
 26   EXECUTE immediate drop_isql;
 27   truncate_sql:='truncate table temp_prj_index';
 28   EXECUTE immediate truncate_sql;
 29   drop_isql:='drop table temp_prj_index ';
 30   EXECUTE immediate drop_isql;
 31 END;
 32 

 

 

  1 CREATE OR REPLACE PROCEDURE PROC_DELEGATE_PROCESS IS
  2   P_SQL CLOB;
  3 BEGIN
  4   -- 查询授权信息 (0: 失效, 1: 有效)
  5   FOR DRI IN (SELECT DRI.ID, DRI.ACCOUNT, DRI.DELEGATE_ACCOUNT
  6                 FROM DELEGATE_PROCESS_INFO DRI
  7                WHERE SYSDATE > END_TIME
  8                  AND ENABLE = 1) LOOP
  9     P_SQL := 'BEGIN ';
 10     -- 处理失效数据
 11     -- 查询授权信息对应的流程任务 (并且是代理人未完成的 STATUS = '0')
 12     FOR DTH IN (SELECT DTH.TASKID, DTH.DELEGATE_ACCOUNT
 13                   FROM DELEGATE_TASK_HISTORY DTH
 14                  WHERE STATUS = 0
 15                    AND MAININFO_ID = DRI.ID) LOOP
 16       -- 删掉失效的流程代理数据
 17       P_SQL := P_SQL ||
 18                ' DELETE FROM ACT_RU_IDENTITYLINK WHERE TYPE_ = ''candidate'' AND TASK_ID_ = ' ||
 19                DTH.TASKID || ' AND USER_ID_ = ''' || DTH.DELEGATE_ACCOUNT ||
 20                '''; DELETE FROM ACT_HI_IDENTITYLINK WHERE TYPE_ = ''candidate'' AND TASK_ID_ = ' ||
 21                DTH.TASKID || ' AND USER_ID_ = ''' || DTH.DELEGATE_ACCOUNT ||
 22                ''';';
 23       -- 批处理
 24       IF LENGTH(P_SQL) > 10000 THEN
 25         P_SQL := P_SQL || ' END;';
 26         PROC_DELEGATE_PROCESS_HANDLE(P_SQL);
 27         P_SQL := 'BEGIN ';
 28       END IF;
 29     END LOOP;
 30     -- 删掉失效的授权信息
 31     P_SQL := P_SQL ||
 32              ' DELETE FROM DELEGATE_TASK_HISTORY WHERE MAININFO_ID = ' ||
 33              DRI.ID || '; END;';
 34     PROC_DELEGATE_PROCESS_HANDLE(P_SQL);
 35   END LOOP;
 36 END PROC_DELEGATE_PROCESS;
 37 

 

 

示例7:分页查询存储过程

 

  1 CREATE OR REPLACE PROCEDURE prc_query
  2        (p_tableName        in  varchar2,   --表名
  3         p_strWhere         in  varchar2,   --查询条件
  4         p_child_query      in  varchar2,   --子查询
  5         p_orderColumn      in  varchar2,   --排序的列
  6         p_orderStyle       in  varchar2,   --排序方式
  7         p_curPage          in out Number,  --当前页
  8         p_pageSize         in out Number,  --每页显示记录条数
  9         p_totalRecords     out Number,     --总记录数
 10         p_totalPages       out Number,     --总页数
 11         v_cur              out pkg_query.cur_query)   --返回的结果集
 12 IS
 13    v_sql VARCHAR2(4000) := '';      --sql语句
 14    v_startRecord Number(7);         --开始显示的记录条数
 15    v_endRecord Number(7);           --结束显示的记录条数
 16 BEGIN
 17    --记录中总记录条数
 18    v_sql := 'SELECT TO_NUMBER(COUNT(*)) FROM ' || p_tableName || ' WHERE 1=1';
 19    IF p_strWhere IS NOT NULL  THEN
 20        v_sql := v_sql || p_strWhere;
 21    END IF;
 22    dbms_output.put_line(v_sql);
 23    EXECUTE IMMEDIATE v_sql INTO p_totalRecords;
 24    p_totalPages := 0;
 25 --   if p_totalRecords <> 0 then
 26 
 27      --验证页面记录大小
 28      IF p_pageSize < 0 THEN
 29          p_pageSize := 0;
 30      END IF;
 31 
 32      --根据页大小计算总页数
 33      IF MOD(p_totalRecords,p_pageSize) = 0 THEN
 34          p_totalPages := floor(p_totalRecords / p_pageSize);
 35      ELSE
 36          p_totalPages := floor(p_totalRecords / p_pageSize) + 1;
 37      END IF;
 38 
 39 
 40 
 41      --实现分页查询
 42      v_startRecord := (p_curPage - 1) * p_pageSize + 1;
 43      v_endRecord := p_curPage * p_pageSize;
 44      v_sql := 'SELECT b.*,' || p_child_query || ' FROM (SELECT A.*, rownum r FROM ' ||
 45               '(SELECT * FROM ' || p_tableName;
 46      IF p_strWhere IS NOT NULL  THEN
 47          v_sql := v_sql || ' WHERE 1=1 ' || p_strWhere;
 48      END IF;
 49      IF p_orderColumn IS NOT NULL THEN
 50          v_sql := v_sql || ' ORDER BY ' || p_orderColumn || '' || p_orderStyle;
 51      END IF;
 52      v_sql := v_sql || ') A WHERE rownum <= ' || v_endRecord || ') B WHERE r >= '
 53               || v_startRecord;
 54      DBMS_OUTPUT.put_line(v_sql);
 55      OPEN v_cur FOR v_sql;
 56  --  end if;
 57 
 58 END prc_query;
 59 

 

 

示例8:游标sql可以拼接,增加事务回滚机制

 

    

  1 
  2 
  3 
  4 create or replace procedure proc_yszxtz_aduit (
  5   yszxtz_ids in varchar2,  /* 预算执行调整表id,其值为: 1,2,3,4,5,6,7,8 */
  6    out_return out varchar2 --返回结果
  7 )
  8 is
  9 --全局变量
 10 errorexception exception; --申明异常
 11 errorcode number; --异常代号
 12 errormsg varchar2(1000) := ''; --异常信息
 13 flag varchar2(10);
 14 v_raise exception; /*错误对象*/
 15 v_raise_over exception;/*终止凌晨审批*/
 16 
 17 type ref_cursor_type is ref cursor;  /*声明:一个动态游标类型*/
 18 
 19 
 20 cursor_yszxtz ref_cursor_type;     /*声明:查询 ys_zxtz 表 数据 的游标对象 */
 21 v_row_yszxtz ys_zxtz%rowtype    ; /*声明:预算执行调整主表 单条数据对象 */
 22 
 23 cursor_yszxtzmx    ref_cursor_type;     /*声明:查询 view_yszxtzms_adjustmx 表 数据 的游标对象 */
 24 v_row_yszxtzmx  view_yszxtzms_adjustmx%rowtype;/*声明:view_yszxtzms_adjustmx 单条数据对象*/
 25 
 26 cursor_gkykjhquota    ref_cursor_type;     /*声明:查询 gk_ykjh_quota 表 数据 的游标对象 */
 27 v_row_gkykjhquota gk_ykjh_quota%rowtype;/*声明:gk_ykjh_quota 的查询结果*/
 28 --v_rowcount_ykjhquota gk_ykjh_quota%rowtype; /*统计游标有多少条数据 用于 游标的for循环判断条件中*/
 29 
 30 --cursor_jzzf_zbbal    ref_cursor_type;     /*声明:查询 zb_bal 表 数据 的游标对象 */
 31 --v_row_jzzf_zbbal zb_bal%rowtype;/*声明:gk_ykjh_quota 的查询结果*/
 32 
 33 type rocord_zbbal_type  is record(id  zb_bal.id%type,canpayamt zb_bal.direct_amt%type,
 34        org_id zb_bal.org_id%type ,n_fundtype zb_bal.fundtype%type,
 35        unitno zb_bal.unitno%type,unit_name bs_bdg_unit.unit_name%type );
 36 v_r_zbbal_info rocord_zbbal_type ;
 37 
 38 cursor_zbbal ref_cursor_type;/*声明指标表 zb_bal 游标 */
 39 v_row_zbbal zb_bal%rowtype; /*声明 zb_bal 查询结果*/
 40 
 41 
 42 v_gkadjustid number(20);/*声明:获取 gk_adjust 表主键 对象*/
 43 v_adjust_liststr varchar2(4000);/*拼接 gk_adjust 表主键 的字符串 */
 44 v_mxloop_no  number(10) :=0 ;/*记录明细表数据条数*/
 45 
 46 v_gkykjhid gk_ykjh.id%type;/*声明:gk_ykjh表的主键  */
 47 
 48 v_sub_amt number(16,2);/*记录:额度表可以支付的金额-调帐需要支付的金额的差值*/
 49 
 50 begin
 51     dbms_output.put_line('============================================预算执行调整审批:审结后业务处理开始============================================ ');
 52 /*进行:入参*/
 53 if yszxtz_ids is   null then
 54      dbms_output.put_line(' 预算执行调整主表的id值不允许 null');     /*则输出异常提示信息*/
 55      raise  v_raise; /*跳转到异常部分代码*/
 56 end if;
 57 
 58 --循环开始
 59    --打开游标
 60   open cursor_yszxtz for 'select  *  from ys_zxtz z where  1=1 and  z.id in ('||   yszxtz_ids ||' )' ;
 61     dbms_output.put_line('============================================ 预算执行调整的 业务逻辑处理 开始:执行的sql为: '|| 'select  *  from ys_zxtz z where  1=1 and  z.id in ('||   yszxtz_ids ||' )============================================'  );     /*则输出异常提示信息*/
 62   fetch cursor_yszxtz   into  v_row_yszxtz;/*先让指针指向结果集中的第一行,并将值保存到emp_row 中*/
 63 
 64   while cursor_yszxtz%found loop
 65         dbms_output.put_line('============================================预算执行调整的 业务逻辑处理 开始:    其id:' || v_row_yszxtz.id ||';gk_adjust 表主键值:v_gkadjustid='||v_gkadjustid||'===========================================' );
 66     v_adjust_liststr:='';
 67   v_mxloop_no:=0;
 68 --========================================================================================================================
 69 --=======================   结束:查询预算执行调整明细---_  数据转换逻辑处理             ========================
 70 ---======================   查询 预算执行调整审批的明细数据                                           ========================
 71 ---========================================================================================================================
 72     open cursor_yszxtzmx   for  select  *  from  view_yszxtzms_adjustmx vya where vya.df_ys_zxtz_id =v_row_yszxtz.id ;
 73      fetch cursor_yszxtzmx      into  v_row_yszxtzmx;/*先让指针指向结果集中的第一行,并将值保存到 v_row_yszxtz 中*/
 74     while cursor_yszxtzmx  %found loop
 75 
 76       ----------------------------------------------------------------------
 77       ----=========注:支出账务调整:调整前(贷方):追加方   左边 =========----
 78       ----=========注:支出账务调整:调整后(借方):追减方   右边 =========----
 79       -----------------------------------------------------------------------
 80 
 81       v_gkadjustid := nextid('GK_ADJUST_SEQ');/*获取预算执行调整主表的id值*/
 82       ---拼接 ys_zxtz 表的 gk_adjust_id 字段的值
 83       if  v_mxloop_no =0   then
 84           v_adjust_liststr := v_gkadjustid||',' ;
 85           v_mxloop_no:=v_mxloop_no+1;
 86       elsif v_mxloop_no =cursor_yszxtzmx%rowcount then
 87           v_adjust_liststr :=v_adjust_liststr||v_gkadjustid;
 88           v_mxloop_no:=0;
 89       else
 90           v_adjust_liststr :=v_adjust_liststr||v_gkadjustid||',';
 91           v_mxloop_no:=v_mxloop_no+1;
 92       end if ;
 93 
 94 
 95 
 96 /*判断贷方(调整前、追加方)指标id 是否为空*/
 97 
 98 ---------贷方指标 不为 null
 99        if  v_row_yszxtzmx.df_id is not null  then /*进行《支出账务调整》的业务逻辑处理*/
100 
101           ---借方指标  不为 null
102           if  v_row_yszxtzmx.jf_zb_id  is not null then  /*借方有指标id值:*/
103 
104 
105 
106 -----------------------------------------------------------------------------------------------------------
107        ----进行 借方指标id 的  额度判断
108         /* 借方判断额度是否够这次的支付(1:本调整月份支付已经做过计划,2:额度是否够支付):
109                           如果不够支付,则判断其指标是否够金额够这次金额的支付:
110                               如果够支付则 做用款计划申请
111                               如果不够支付,则结束整个审批操作,
112                               数据库层面事物数据回滚,返回数据操作失败操作。如果应用程序层面事物回滚
113          */
114 
115 
116                         ---如果支付方式为:直接支付
117                        if  v_row_yszxtz.voucher_type ='0' then
118 
119               --授权支付不需要插入调账表
120               dbms_output.put_line('====进行《支出账务调整》的业务逻辑处理:借方有指标id值:'|| v_row_yszxtzmx.jf_zb_id||'==== ' );
121               ---插入gk_adjust 主表数据
122              insert into gk_adjust
123                (id, is_accounting, adjustment_type, expenditure_type, create_dt, oper_account_id, remark, biz_status, process_instance_id, status, oper_dt, summary, process_status, gk_zfpz_id, oper_orgid)
124              values
125                (v_gkadjustid, '1', '0', v_row_yszxtz.voucher_type,  sysdate, v_row_yszxtz.oper_account, v_row_yszxtz.remark, '9', '', '', sysdate, v_row_yszxtz.remarks, '9', v_row_yszxtzmx.df_gk_zfpzid, v_row_yszxtz.oper_orgid) ;
126 
127              --- 插入 gk_adjust_detail 明细数据
128 
129              insert into gk_adjust_detail
130                (gk_adjust_detail_id, gk_adjust_id, jf_unitno, jf_bdgid, jf_bdgt_type, jf_prj_code, jf_src_id, jf_zba_id, jf_item_id, df_unitno, df_bdgid, df_bdgt_type, df_prj_code, df_src_id, df_zba_id, df_item_id, balance, tocredit_amt, todebit_amt)
131              values
132                (nextid('GK_ADJUST_DETAIL_SEQ'), v_gkadjustid,  v_row_yszxtzmx.jf_unitno , v_row_yszxtzmx.jf_budgetno, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_prjno, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_zb_id, v_row_yszxtzmx.jf_itemno,
133                v_row_yszxtzmx.df_unitno,  v_row_yszxtzmx.df_budgetno,  v_row_yszxtzmx.df_budget_type, v_row_yszxtzmx.df_prjno, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_zb_id,v_row_yszxtzmx.df_itemno,  v_row_yszxtzmx.adjust_amt, 0, 0);
134 
135 
136                                --- 打开 查询用款计划额度表的游标
137                                open cursor_gkykjhquota   for   select * into v_row_gkykjhquota   from gk_ykjh_quota q where q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny =to_char(sysdate,'yyyyMM');
138                               fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
139                                --当 额度表没有当前支付月份的该借方指标的额度数据的时候;
140                                 if cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null then
141                                     dbms_output.put_line('======如果:该借方指标id('||v_row_yszxtzmx.jf_zb_id ||')在额度表不存在数据 则新增额度表数据======');
142 
143                                  ---判断借方指标该支付指标的金额是否够本次调整金额的支付
144                                     --1:查询查询指标是否可支付
145                                    select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
146                                      (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
147                                       into v_r_zbbal_info
148                                      from (  select  z.*,(case when  v_row_yszxtz.voucher_type ='0' then nvl(nvl(z.direct_amt,0)-nvl(direct_plan ,0),0)- v_row_yszxtzmx.adjust_amt
149                                                         when  v_row_yszxtz.voucher_type ='1' then nvl(nvl(z.accredit_amt ,0)-nvl(accredit_plan ,0),0)- v_row_yszxtzmx.adjust_amt
150                                                         end) as canpayamt,(case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
151                                                          from zb_bal z where z.id =v_row_yszxtzmx.jf_zb_id ) vv ;
152 
153 
154                                    if  v_r_zbbal_info.canpayamt >=0 then
155                                        dbms_output.put_line('====');
156                                     ---如果够支付,则新增已经审结了用款计划数据(正的用款计划额度)
157 
158                                          ---向用款计划主表插入数据
159                                          v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
160                                          insert into gk_ykjh
161                                           (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
162                                          values
163                                           (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_r_zbbal_info.org_id , v_r_zbbal_info.n_fundtype , v_r_zbbal_info.unitno, v_r_zbbal_info.unit_name);
164 
165                                           ---向用款计划明细表插入数据
166                                           insert into gk_ykjh_mx
167                                             (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
168                                           values
169                                             (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_r_zbbal_info.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', v_row_yszxtzmx.adjust_amt,  v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
170 
171                                     --增加额度表的数据
172                                        insert into gk_ykjh_quota
173                                          (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
174                                        values
175                                          (nextid('GK_YKJH_QUOTA_SEQ'), v_r_zbbal_info.id, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.adjust_amt, v_row_yszxtzmx.adjust_amt, 0, 0);
176                                     --修改指标报表的 对应支付方式的 已报用款计划 字段的金额
177                                         if v_row_yszxtz.voucher_type='0' then  /*直接支付*/
178                                            update zb_bal z set z.direct_plan  =z.direct_plan+v_row_yszxtzmx.adjust_amt where z.id=v_row_yszxtzmx.jf_zb_id;
179                                         elsif v_row_yszxtz.voucher_type='1'then  /*授权支付*/
180                                            update zb_bal z set z.accredit_plan  =z.accredit_plan+v_row_yszxtzmx.adjust_amt where z.id=v_row_yszxtzmx.jf_zb_id;
181                                        end if;
182 
183                                   elsif  v_r_zbbal_info.canpayamt < 0  then
184                                   ---则 整个业务存储过程 本次执行业务回滚 ,应用程序进行审批操作事务回滚,终止预算执行调整审批的审结操作 。
185                                         raise  v_raise_over; /*跳转到异常部分代码*/
186                                   end if;
187 
188                                 else  /*当额度表该支付月份有支付额度数据时:*/
189 
190                                     while cursor_gkykjhquota%found loop
191                                         --判断 借方指标 id 在额度表中的 可以支付额度是否够本次调整支付金额支付。
192 
193                                           /*直接支付*/
194 
195                                              ---获取:额度表可以支付的额度 - 本次调整需要支付的支出数=需要支付的支出额
196                                              v_sub_amt := nvl((nvl(v_row_gkykjhquota.direct_apply,0) -nvl(v_row_gkykjhquota.direct_execute,0)),0)  /*额度表可支付额度*/ -  nvl(v_row_yszxtzmx.adjust_amt,0)/*调整金额*/ ;
197 
198                                              if v_sub_amt  >= 0  then
199                                                 --如果 额度表的支付额度 够 支付,则直接加大额度表直接支付的支出数
200                                                 update gk_ykjh_quota q set q.direct_execute=q.direct_execute+v_row_yszxtzmx.adjust_amt where  q.id=v_row_gkykjhquota.id  and q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny=to_char(sysdate,'yyyyMM');
201 
202                                              elsif   v_sub_amt  < 0  then
203 
204                                                 --如果 额度表的支付额度 不够 支付,则需要判断指标的可以支付金额是否够支付。
205                                                  dbms_output.put_line('======== ' );
206                                                   --1:查询查询指标是否可支付
207                                                    select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
208                                                      (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
209                                                       into v_r_zbbal_info
210                                                    from (  select  z.*, nvl(nvl(z.direct_amt,0)-nvl(direct_plan ,0),0)+ v_sub_amt   as canpayamt,
211                                                                   (case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
212                                                            from zb_bal z where z.id =v_row_yszxtzmx.jf_zb_id ) vv ;
213 
214                                                   --如果 指标的可支付额度 够支付 额度表不够支付的差额
215                                                   if v_r_zbbal_info.canpayamt >0 then
216                                                      -- 则:插入用款计划主表数据
217                                                       v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
218                                                       insert into gk_ykjh
219                                                         (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
220                                                       values
221                                                         (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_r_zbbal_info.org_id , v_r_zbbal_info.n_fundtype , v_r_zbbal_info.unitno, v_r_zbbal_info.unit_name);
222 
223 
224                                                      --     插入用款计划明细表数据
225                                                       insert into gk_ykjh_mx
226                                                         (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
227                                                       values
228                                                         (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_r_zbbal_info.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', 0-v_sub_amt,  0-v_sub_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
229 
230 
231                                                      --     更新用款计划额度表数据的额度和支出数
232 
233                                                       update gk_ykjh_quota q set q.direct_execute=q.direct_execute+v_row_yszxtzmx.adjust_amt,q.direct_apply =q.direct_apply-v_sub_amt
234                                                          where  q.id=v_row_gkykjhquota.id  and q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny=to_char(sysdate,'yyyyMM');
235 
236 
237                                                      --     更新指标表 直接支付 已报用款计划  字段的值
238                                                      update zb_bal z set z.direct_plan =z.direct_plan-v_sub_amt where z.id=v_r_zbbal_info.id;
239 
240                                                   --如果指标的可支付额度   不够支付   额度表不够支付的差额
241                                                   elsif v_r_zbbal_info.canpayamt<0 then
242                                                     -- 则: 退出 整个存储过程执行,应用程序 预算执行调整审批 审结操作进行事物回滚
243                                                      raise  v_raise_over; /*跳转到异常部分代码*/
244                                                   end if ;
245                                               end if ;
246 
247 
248 
249                                     fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
250                                     exit when cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null;
251                                     end loop;
252                                     close  cursor_gkykjhquota;/*关闭游标*/
253                                 end if;
254             /*授权支付*/
255                         elsif v_row_yszxtz.voucher_type='1' then
256 
257                 ---20180305 troy
258                 ---判断累计额度是否够支出
259      /*           select sum(accredit_apply-accredit_execute)-v_row_yszxtzmx.adjust_amt  into v_sub_amt from gk_ykjh_quota q where
260                 q.zbz_bal_id = v_row_yszxtzmx.jf_zb_id;
261 
262                 if v_sub_amt>=0 then
263                    ---判断是否存在本月额度
264                  open cursor_gkykjhquota   for   select * into v_row_gkykjhquota   from gk_ykjh_quota q where q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny =to_char(sysdate,'yyyyMM');
265                                  fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
266 
267                  if cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null then
268                     ---如果不存在,生成当月额度
269                     --增加额度表的数据
270                    insert into gk_ykjh_quota
271                      (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
272                    values
273                      (nextid('GK_YKJH_QUOTA_SEQ'), v_row_yszxtzmx.jf_zb_id, to_char(sysdate,'yyyyMM'), 0, 0, 0, v_row_yszxtzmx.adjust_amt);
274                  else
275                    while cursor_gkykjhquota%found loop
276                     ---如果存在,改变额度数据
277                     update gk_ykjh_quota q set q.accredit_execute=q.accredit_execute+v_row_yszxtzmx.adjust_amt where
278                     q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny=to_char(sysdate,'yyyyMM');
279 
280                      fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
281                      exit when cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null;
282                      end loop;
283                      close  cursor_gkykjhquota;\*关闭游标*\
284                  end if;
285 
286 
287                 elsif v_sub_amt<0 then*/
288                    --判断指标剩余指标金额是否够支出
289                    select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
290                  (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
291                  into v_r_zbbal_info
292                  from (  select  z.*,(case when  v_row_yszxtz.voucher_type ='0' then nvl(nvl(z.direct_amt,0)-nvl(direct_plan ,0),0)-v_row_yszxtzmx.adjust_amt
293                           when  v_row_yszxtz.voucher_type ='1' then nvl(nvl(z.accredit_amt ,0)-nvl(accredit_plan ,0),0)-v_row_yszxtzmx.adjust_amt
294                           end) as canpayamt,(case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
295                            from zb_bal z where z.id =v_row_yszxtzmx.jf_zb_id ) vv ;
296 
297                  --如果指标够支付,生成审结的用款计划
298                  if  v_r_zbbal_info.canpayamt >=0 then
299                    ---向用款计划主表插入数据
300                    v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
301                    insert into gk_ykjh
302                     (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
303                    values
304                     (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_r_zbbal_info.org_id , v_r_zbbal_info.n_fundtype , v_r_zbbal_info.unitno, v_r_zbbal_info.unit_name);
305 
306                    ---向用款计划明细表插入数据
307                    insert into gk_ykjh_mx
308                     (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
309                    values
310                     (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_r_zbbal_info.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', v_row_yszxtzmx.adjust_amt,  v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
311 
312                    --修改指标报表的 对应支付方式的 已报用款计划 字段的金额
313                    update zb_bal z set z.accredit_plan  =z.accredit_plan+v_row_yszxtzmx.adjust_amt where z.id=v_row_yszxtzmx.jf_zb_id;
314                  --指标不够支付
315                 elsif  v_r_zbbal_info.canpayamt < 0  then
316                                   ---则 整个业务存储过程 本次执行业务回滚 ,应用程序进行审批操作事务回滚,终止预算执行调整审批的审结操作 。
317                                      raise  v_raise_over;
318                                  end if;
319 
320                 /* end if;*/
321 
322                         ---如果支付方式为: 一般支付
323                         elsif v_row_yszxtz.voucher_type='3' then
324               --授权支付不需要插入调账表
325               dbms_output.put_line('====进行《支出账务调整》的业务逻辑处理:借方有指标id值:'|| v_row_yszxtzmx.jf_zb_id||'==== ' );
326               ---插入gk_adjust 主表数据
327                insert into gk_adjust
328                  (id, is_accounting, adjustment_type, expenditure_type, create_dt, oper_account_id, remark, biz_status, process_instance_id, status, oper_dt, summary, process_status, gk_zfpz_id, oper_orgid)
329                values
330                  (v_gkadjustid, '1', '0', v_row_yszxtz.voucher_type,  sysdate, v_row_yszxtz.oper_account, v_row_yszxtz.remark, '9', '', '', sysdate, v_row_yszxtz.remarks, '9', v_row_yszxtzmx.df_gk_zfpzid, v_row_yszxtz.oper_orgid) ;
331 
332                --- 插入 gk_adjust_detail 明细数据
333 
334                insert into gk_adjust_detail
335                  (gk_adjust_detail_id, gk_adjust_id, jf_unitno, jf_bdgid, jf_bdgt_type, jf_prj_code, jf_src_id, jf_zba_id, jf_item_id, df_unitno, df_bdgid, df_bdgt_type, df_prj_code, df_src_id, df_zba_id, df_item_id, balance, tocredit_amt, todebit_amt)
336                values
337                  (nextid('GK_ADJUST_DETAIL_SEQ'), v_gkadjustid,  v_row_yszxtzmx.jf_unitno , v_row_yszxtzmx.jf_budgetno, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_prjno, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_zb_id, v_row_yszxtzmx.jf_itemno,
338                  v_row_yszxtzmx.df_unitno,  v_row_yszxtzmx.df_budgetno,  v_row_yszxtzmx.df_budget_type, v_row_yszxtzmx.df_prjno, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_zb_id,v_row_yszxtzmx.df_itemno,  v_row_yszxtzmx.adjust_amt, 0, 0);
339 
340                              ----则需要判断 一般支付指标金额-一般支付的实际支出数=剩余可以支付的金额 是否可以够本次支付
341                              select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
342                                (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
343                              into v_r_zbbal_info
344                              from
345                              ( select z.* ,nvl (nvl(z.tradition_amt,0)-nvl(z.tradition_num,0)- nvl(v_row_yszxtzmx.adjust_amt,0) ,0 ) as canpayamt ,
346                                      (case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
347                               from zb_bal z where z.id =v_row_yszxtzmx.jf_zb_id  ) vv ;
348 
349                              if v_r_zbbal_info.canpayamt >=0 then
350 
351                                 update zb_bal z set z.tradition_num =z.tradition_num+v_row_yszxtzmx.adjust_amt where z.id=v_row_yszxtzmx.jf_zb_id;
352 
353                              elsif v_r_zbbal_info.canpayamt < 0 then
354                                 ---则 整个业务存储过程 本次执行业务回滚 ,应用程序进行审批操作事务回滚,终止预算执行调整审批的审结操作 。
355                                 raise  v_raise_over; /*跳转到异常部分代码*/
356                              end if;
357 
358                         end if;
359 -----------------------------------------------------------------------------------------------------------
360          ----进行贷方指标  额度判断:
361 
362              /* 贷方 1:判断该贷方指标在本支付年月是否操作额度数据:如果没有,则在额度表生成本支付月份的0值额度数据
363                                       如果有,则判断该支付月份是否有过支付数发生。
364                                                 如果有,则在原值上面减去支付发生数
365                                                 如果没有,则用0值减去 本次的支付金额
366                      2:做 贷方冲销的用款计划
367 
368                      3:减小 贷方指标的已报用款计划额度
369 
370              */
371 
372                 ---判断支付方式
373 
374                   --如果是 直接支付
375                   if v_row_yszxtz.voucher_type='0' then
376 
377 
378                       ----查询 贷方指标 在额度表中是否有数据
379                         --- 打开 查询用款计划额度表  的  游标
380                        open cursor_gkykjhquota   for   select * into v_row_gkykjhquota
381                                from gk_ykjh_quota q where q.zbz_bal_id=v_row_yszxtzmx.df_zb_id and q.plan_ny =to_char(sysdate,'yyyyMM');
382 
383                                fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
384                         ---如果没有数据,
385                          if cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null then
386 
387                               ---直接支付
388 
389 
390                                  --插入一条 所有 0 值 额度计划数据,并把支付数(执行金额)的金额填上
391                                  insert into gk_ykjh_quota
392                                    (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
393                                  values
394                                    (nextid('GK_YKJH_QUOTA_SEQ'), v_row_yszxtzmx.df_zb_id, to_char(sysdate,'yyyyMM'), 0-v_row_yszxtzmx.adjust_amt, 0-v_row_yszxtzmx.adjust_amt, 0, 0);
395 
396                                   --则 插入一条 冲销的 gk_ykjh  gk_ykjh_mx 的数据
397 
398                                      v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
399 
400                                     insert into gk_ykjh
401                                        (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
402                                      values
403                                      (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '1', '0', '',
404                                          v_row_yszxtzmx.df_org_id ,decode(v_row_yszxtzmx.df_fundtype,'1','1','2','2','3') , v_row_yszxtzmx.df_unitno,v_row_yszxtzmx.df_unit_name);
405 
406                                      ---向用款计划明细表插入数据
407                                     insert into gk_ykjh_mx
408                                       (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit,
409                                        zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
410                                     values
411                                       (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.df_item_id, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_budget_type,
412                                        v_row_yszxtzmx.df_budgetid, v_row_yszxtzmx.df_prjid , v_row_yszxtzmx.df_adjlevel,  v_row_yszxtzmx.df_org_id, '', '0', '1',
413                                        v_row_yszxtzmx.df_zb_id , v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.df_unitno, v_row_yszxtzmx.df_unit_name,
414                                        '1', -v_row_yszxtzmx.adjust_amt,  -v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.df_budgetno,v_row_yszxtzmx.df_itemno  ,v_row_yszxtzmx.df_prjno );
415 
416 
417                                   --则 更新 zb_bal 的相对应的已报用款计划额度 字段的值(即:减小该值)
418 
419                                      update zb_bal z set z.direct_plan=nvl(z.direct_plan,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
420 
421 
422 
423 
424 
425 
426                         --如果有数据
427                          else
428                                  /*当额度表该支付月份有该指标的支付额度数据时:*/
429 
430                                 while cursor_gkykjhquota%found loop
431 
432                                     --- 如果是直接支付
433 
434                                         --则 更新支付数(执行金额),即:减小执行金额的值。增大可以支付金额
435                                             update gk_ykjh_quota q set q.direct_execute=nvl(q.direct_execute,0)-nvl(v_row_yszxtzmx.adjust_amt,0)  where q.zbz_bal_id=v_row_yszxtzmx.df_zb_id and q.plan_ny=to_char(sysdate,'yyyyMM');
436 
437                                         --则 插入一条 冲销的 gk_ykjh  gk_ykjh_mx 的数据
438                                             v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
439 
440                                             insert into gk_ykjh
441                                                (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
442                                             values
443                                              (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '1', '0', '',
444                                                  v_row_yszxtzmx.df_org_id ,decode(v_row_yszxtzmx.df_fundtype,'1','1','2','2','3') , v_row_yszxtzmx.df_unitno,v_row_yszxtzmx.df_unit_name);
445 
446                                             insert into gk_ykjh_mx
447                                                 (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit,
448                                                  zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
449                                             values
450                                                 (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.df_item_id, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_budget_type,
451                                                  v_row_yszxtzmx.df_budgetid, v_row_yszxtzmx.df_prjid , v_row_yszxtzmx.df_adjlevel,  v_row_yszxtzmx.df_org_id, '', '0', '1',
452                                                  v_row_yszxtzmx.df_zb_id , v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.df_unitno, v_row_yszxtzmx.df_unit_name,
453                                                  '1', -v_row_yszxtzmx.adjust_amt,  -v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.df_budgetno,v_row_yszxtzmx.df_itemno  ,v_row_yszxtzmx.df_prjno );
454 
455 
456                                         --则 更新 zb_bal 的相对应的已报用款计划额度 字段的值(即:减小该值)
457                                            update zb_bal z set z.direct_plan=nvl(z.direct_plan,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
458 
459 
460 
461 
462                                 fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
463                                 exit when cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null;
464                                 end loop;
465                                 close  cursor_gkykjhquota;/*关闭游标*/
466                          end if;
467 
468            --如果是 授权支付
469                    elsif v_row_yszxtz.voucher_type='1' then
470                v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
471                 --授权支付不给动额度,生成用款计划 冲销审结数据
472              insert into gk_ykjh
473              (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
474              values
475              (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '1', '0', '',
476                v_row_yszxtzmx.df_org_id ,decode(v_row_yszxtzmx.df_fundtype,'1','1','2','2','3') , v_row_yszxtzmx.df_unitno,v_row_yszxtzmx.df_unit_name);
477 
478              ---向用款计划明细表插入数据
479             insert into gk_ykjh_mx
480             (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit,
481              zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
482             values
483             (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.df_item_id, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_budget_type,
484              v_row_yszxtzmx.df_budgetid, v_row_yszxtzmx.df_prjid , v_row_yszxtzmx.df_adjlevel,  v_row_yszxtzmx.df_org_id, '', '0', '1',
485              v_row_yszxtzmx.df_zb_id , v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.df_unitno, v_row_yszxtzmx.df_unit_name,
486              '1', -v_row_yszxtzmx.adjust_amt,  -v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.df_budgetno,v_row_yszxtzmx.df_itemno  ,v_row_yszxtzmx.df_prjno );
487 
488           --则 更新 zb_bal 的相对应的已报用款计划额度 字段的值(即:减小该值)
489             update zb_bal z set z.accredit_plan=nvl(z.accredit_plan,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
490 
491                    --如果是 一般支付
492                    elsif v_row_yszxtz.voucher_type='3' then
493 
494                        --更新 该指标的 一般支付的实际支出数 。即:减小该实际支出数
495                         update zb_bal z set z.tradition_num=nvl(z.tradition_num,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
496 
497                  end if;
498 
499           ---借方指标  为  null
500           elsif   v_row_yszxtzmx.jf_zb_id is null then /*借方无指标id值:*/
501 
502 -----------------------------------------------------------------------------------------------------------
503             /*
504                借方无指标编码:
505 
506                    1:判断指标表中是否有当前支付年度符合条件的指标存在
507                        (判断条件: 预算年度、单位编码、资金来源、功能分类编码、功能分类类型、项目编码、项目类型 、是否统发工资、是否封套 )
508 
509 
510 
511                   ---如果不存在,则新增指标
512                                   新增用款计划 数据
513                                   新增额度表数据
514                                   更新指标支出数
515 
516                   ---如果存在,则判断其可支付额度 是否够 本次调账支付
517 
518                      ----如果 够:
519                             --  则判断 额度表是否有额度
520                                        如果有: 则判断该额度是否够支付
521                                               如果够支付。则直接 修改(增大)支出数
522 
523                                               如果不够支付。则  需要判断该指标可支付额度是否够本次支付
524 
525                                                                 如果够支付,则 新增用款计划 审结数据
526                                                                               更新额度表数据,更新指标库支付额度值(即:加大实际支出数)
527                                                                  如果不够支付 则:异常终止本次存储过程的执行。应用程序 本次操作事务回滚
528                                         如果没有, 则 直接新增 用款计划数据
529                                                               额度表数据
530                                                               更新指标 已报用款计划 金额(增大)
531 
532                     ----如果 不够  支付
533                             --  则 终止本次 存储过程执行。应用查询 本次事务操作回滚
534             */
535 
536 -----------------借方 无指标 编码
537               if v_row_yszxtzmx.jf_entire_manage is null then
538                  open cursor_zbbal   for     select * into v_row_zbbal from zb_bal z where      z.unitno =v_row_yszxtzmx.jf_unitno
539                    and  z.src_id =v_row_yszxtzmx.jf_src_id
540                    and  z.bdgyear =v_row_yszxtz.bdgyear
541                    and  z.prj_id =v_row_yszxtzmx.jf_prjid
542                    and  z.zb_project_type =v_row_yszxtzmx.jf_zb_project_type
543                    and  z.budgetid =v_row_yszxtzmx.jf_budgetid
544                    and  z.bdgt_id_type =v_row_yszxtzmx.jf_budget_type
545                    and  z.is_unify =v_row_yszxtzmx.jf_is_unify
546                    and  z.entire_manage is null;
547               else
548                  open cursor_zbbal   for     select * into v_row_zbbal from zb_bal z where      z.unitno =v_row_yszxtzmx.jf_unitno
549                    and  z.src_id =v_row_yszxtzmx.jf_src_id
550                    and  z.bdgyear =v_row_yszxtz.bdgyear
551                    and  z.prj_id =v_row_yszxtzmx.jf_prjid
552                    and  z.zb_project_type =v_row_yszxtzmx.jf_zb_project_type
553                    and  z.budgetid =v_row_yszxtzmx.jf_budgetid
554                    and  z.bdgt_id_type =v_row_yszxtzmx.jf_budget_type
555                    and  z.is_unify =v_row_yszxtzmx.jf_is_unify
556                    and  z.entire_manage=v_row_yszxtzmx.jf_entire_manage;
557               end if;
558 
559 
560               ----查询指标表是否存在 与(无指标id的)借方数据 相同的指标数据存在
561 
562 
563                fetch cursor_zbbal into v_row_zbbal;
564               ---判断:如果 指标表  不存在     与借方相同的指标数据
565                   if cursor_zbbal%notfound or cursor_zbbal%notfound is null then
566 
567                    ---1:判断支付方式:集中支付(直接支付、授权支付)
568             if v_row_yszxtz.voucher_type='0' then --直接支付
569 
570        dbms_output.put_line('====进行《支出账务调整》的业务逻辑处理:借方无指标id值: ==== ' );
571 
572               ---插入gk_adjust 主表数据
573              insert into gk_adjust
574                (id, is_accounting, adjustment_type, expenditure_type, create_dt, oper_account_id, remark, biz_status, process_instance_id, status, oper_dt, summary, process_status, gk_zfpz_id, oper_orgid)
575              values
576                (v_gkadjustid, '1', '0', v_row_yszxtz.voucher_type,  sysdate, v_row_yszxtz.oper_account, v_row_yszxtz.remark, '9', '', '', sysdate, v_row_yszxtz.remarks, '9', v_row_yszxtzmx.df_gk_zfpzid, v_row_yszxtz.oper_orgid) ;
577 
578              --- 插入 gk_adjust_detail 明细数据
579 
580              insert into gk_adjust_detail
581                (gk_adjust_detail_id, gk_adjust_id, jf_unitno, jf_bdgid, jf_bdgt_type, jf_prj_code, jf_src_id, jf_zba_id, jf_item_id, df_unitno, df_bdgid, df_bdgt_type, df_prj_code, df_src_id, df_zba_id, df_item_id, balance, tocredit_amt, todebit_amt)
582              values
583                (nextid('GK_ADJUST_DETAIL_SEQ'), v_gkadjustid,  v_row_yszxtzmx.jf_unitno , v_row_yszxtzmx.jf_budgetno, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_prjno, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_zb_id, v_row_yszxtzmx.jf_itemno,
584                v_row_yszxtzmx.df_unitno,  v_row_yszxtzmx.df_budgetno,  v_row_yszxtzmx.df_budget_type, v_row_yszxtzmx.df_prjno, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_zb_id,v_row_yszxtzmx.df_itemno,  v_row_yszxtzmx.adjust_amt, 0, 0);
585 
586 
587 
588                      ---1:新增指标数据,其指标金额为:为 调账金额。非本支付方式的指标金额皆为0 。
589                         --- 并 其对于的指标已报用款计划 为:调账金额
590             insert into zb_bal (id,BDGYEAR,UNITID,unitno,SRC_ID,BDGT_ID_TYPE,BUDGETID,PRJ_ID,ITEM_ID,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,
591             ORG_ID,ADJLEVEL,ZB_PROJECT_TYPE,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,ISSUE_NUM,ENTIRE_MANAGE,BZ)
592             values (nextid('ZB_BAL_SEQ'),v_row_yszxtz.bdgyear,(select unitid from bs_bdg_unit where unitno=v_row_yszxtzmx.JF_UNITNO),v_row_yszxtzmx.JF_UNITNO,v_row_yszxtzmx.JF_SRC_ID,v_row_yszxtzmx.JF_BUDGET_TYPE,
593             v_row_yszxtzmx.JF_BUDGETID,v_row_yszxtzmx.JF_PRJID,v_row_yszxtzmx.JF_ITEM_ID,v_row_yszxtzmx.adjust_amt,v_row_yszxtzmx.adjust_amt,0,v_row_yszxtzmx.adjust_amt,0,0,
594             v_row_yszxtzmx.JF_ORG_ID,v_row_yszxtzmx.JF_ADJLEVEL,v_row_yszxtzmx.JF_ZB_PROJECT_TYPE,0,0,0,0,v_row_yszxtzmx.JF_FUNDTYPE,0,v_row_yszxtzmx.JF_ENTIRE_MANAGE,'预算执行调整'||v_row_yszxtz.id||'生成');
595 
596             select * into v_row_zbbal from zb_bal where id =(select max(id) from zb_bal);
597 
598              ---2:新增 用款计划 表数据
599              ---向用款计划主表插入数据
600              v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
601              insert into gk_ykjh
602               (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
603              values
604               (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_row_zbbal.org_id , v_row_zbbal.fundtype , v_row_zbbal.unitno, (select unit_name from bs_bdg_unit where unitno=v_row_zbbal.unitno));
605 
606               ---向用款计划明细表插入数据
607               insert into gk_ykjh_mx
608               (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
609               values
610               (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_row_zbbal.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', v_row_yszxtzmx.adjust_amt,  v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
611 
612             ---3:新增  用款计划额度表 数据
613             insert into gk_ykjh_quota
614              (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
615             values
616              (nextid('GK_YKJH_QUOTA_SEQ'), v_row_zbbal.id, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.adjust_amt, v_row_yszxtzmx.adjust_amt, 0, 0);
617 
618                       ---授权支付
619                     elsif v_row_yszxtz.voucher_type='1' then
620               ---1:新增指标数据,其指标金额为:为 调账金额。非本支付方式的指标金额皆为0 。
621                         --- 并 其对于的指标已报用款计划 为:调账金额
622             insert into zb_bal (id,BDGYEAR,UNITID,unitno,SRC_ID,BDGT_ID_TYPE,BUDGETID,PRJ_ID,ITEM_ID,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,
623             ORG_ID,ADJLEVEL,ZB_PROJECT_TYPE,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,ISSUE_NUM,ENTIRE_MANAGE,BZ)
624             values (nextid('ZB_BAL_SEQ'),v_row_yszxtz.bdgyear,(select unitid from bs_bdg_unit where unitno=v_row_yszxtzmx.JF_UNITNO),v_row_yszxtzmx.JF_UNITNO,v_row_yszxtzmx.JF_SRC_ID,v_row_yszxtzmx.JF_BUDGET_TYPE,
625             v_row_yszxtzmx.JF_BUDGETID,v_row_yszxtzmx.JF_PRJID,v_row_yszxtzmx.JF_ITEM_ID,v_row_yszxtzmx.JF_ADJ_ACCREDIT_AMT,0,v_row_yszxtzmx.JF_ADJ_ACCREDIT_AMT,0,v_row_yszxtzmx.JF_ADJ_ACCREDIT_AMT,0,
626             v_row_yszxtzmx.JF_ORG_ID,v_row_yszxtzmx.JF_ADJLEVEL,v_row_yszxtzmx.JF_ZB_PROJECT_TYPE,0,0,0,0,v_row_yszxtzmx.JF_FUNDTYPE,0,v_row_yszxtzmx.JF_ENTIRE_MANAGE,'预算执行调整'||v_row_yszxtz.id||'生成');
627 
628             select * into v_row_zbbal from zb_bal where id =(select max(id) from zb_bal);
629 
630              ---2:新增 用款计划 表数据
631              ---向用款计划主表插入数据
632              v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
633              insert into gk_ykjh
634               (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
635              values
636               (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_row_zbbal.org_id , v_row_zbbal.fundtype , v_row_zbbal.unitno, (select unit_name from bs_bdg_unit where unitno=v_row_zbbal.unitno));
637 
638               ---向用款计划明细表插入数据
639               insert into gk_ykjh_mx
640               (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
641               values
642               (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_row_zbbal.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', v_row_yszxtzmx.adjust_amt,  v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
643 
644             ---3:新增  用款计划额度表 数据
645             /* insert into gk_ykjh_quota
646              (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
647             values
648              (nextid('GK_YKJH_QUOTA_SEQ'), v_row_zbbal.id, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.adjust_amt, v_row_yszxtzmx.adjust_amt, 0, 0);
649  */
650 
651                    ---2: 判断支付方式:一般支付
652                     elsif v_row_yszxtz.voucher_type='3' then
653 
654            dbms_output.put_line('====进行《支出账务调整》的业务逻辑处理:借方无指标id值: ==== ' );
655 
656             ---插入gk_adjust 主表数据
657            insert into gk_adjust
658              (id, is_accounting, adjustment_type, expenditure_type, create_dt, oper_account_id, remark, biz_status, process_instance_id, status, oper_dt, summary, process_status, gk_zfpz_id, oper_orgid)
659            values
660              (v_gkadjustid, '1', '0', v_row_yszxtz.voucher_type,  sysdate, v_row_yszxtz.oper_account, v_row_yszxtz.remark, '9', '', '', sysdate, v_row_yszxtz.remarks, '9', v_row_yszxtzmx.df_gk_zfpzid, v_row_yszxtz.oper_orgid) ;
661 
662            --- 插入 gk_adjust_detail 明细数据
663 
664            insert into gk_adjust_detail
665              (gk_adjust_detail_id, gk_adjust_id, jf_unitno, jf_bdgid, jf_bdgt_type, jf_prj_code, jf_src_id, jf_zba_id, jf_item_id, df_unitno, df_bdgid, df_bdgt_type, df_prj_code, df_src_id, df_zba_id, df_item_id, balance, tocredit_amt, todebit_amt)
666            values
667              (nextid('GK_ADJUST_DETAIL_SEQ'), v_gkadjustid,  v_row_yszxtzmx.jf_unitno , v_row_yszxtzmx.jf_budgetno, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_prjno, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_zb_id, v_row_yszxtzmx.jf_itemno,
668              v_row_yszxtzmx.df_unitno,  v_row_yszxtzmx.df_budgetno,  v_row_yszxtzmx.df_budget_type, v_row_yszxtzmx.df_prjno, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_zb_id,v_row_yszxtzmx.df_itemno,  v_row_yszxtzmx.adjust_amt, 0, 0);
669 
670 
671                        ---1:新增指标数据,其指标金额为:为 调账金额。非本支付方式的指标金额皆为0 。
672                            --- 并 其对于的指标的实际支出数 为:调账金额
673                         insert into zb_bal (id,BDGYEAR,UNITID,unitno,SRC_ID,BDGT_ID_TYPE,BUDGETID,PRJ_ID,ITEM_ID,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,
674             ORG_ID,ADJLEVEL,ZB_PROJECT_TYPE,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,ISSUE_NUM,ENTIRE_MANAGE,BZ)
675             values (nextid('ZB_BAL_SEQ'),v_row_yszxtz.bdgyear,(select unitid from bs_bdg_unit where unitno=v_row_yszxtzmx.JF_UNITNO),v_row_yszxtzmx.JF_UNITNO,v_row_yszxtzmx.JF_SRC_ID,v_row_yszxtzmx.JF_BUDGET_TYPE,
676             v_row_yszxtzmx.JF_BUDGETID,v_row_yszxtzmx.JF_PRJID,v_row_yszxtzmx.JF_ITEM_ID,v_row_yszxtzmx.adjust_amt,0,0,0,0,v_row_yszxtzmx.adjust_amt,
677             v_row_yszxtzmx.JF_ORG_ID,v_row_yszxtzmx.JF_ADJLEVEL,v_row_yszxtzmx.JF_ZB_PROJECT_TYPE,0,0,0,v_row_yszxtzmx.adjust_amt,v_row_yszxtzmx.JF_FUNDTYPE,0,v_row_yszxtzmx.JF_ENTIRE_MANAGE,'预算执行调整'||v_row_yszxtz.id||'生成');
678 
679            end if;
680 
681 
682               ---判断:如果 指标表  存在        与借方相同的指标数据
683                   else
684 
685                       ---如果支付方式为:直接支付
686                        if  v_row_yszxtz.voucher_type ='0' then
687 
688                    dbms_output.put_line('====进行《支出账务调整》的业务逻辑处理:借方无指标id值: ==== ' );
689 
690                 ---插入gk_adjust 主表数据
691                insert into gk_adjust
692                  (id, is_accounting, adjustment_type, expenditure_type, create_dt, oper_account_id, remark, biz_status, process_instance_id, status, oper_dt, summary, process_status, gk_zfpz_id, oper_orgid)
693                values
694                  (v_gkadjustid, '1', '0', v_row_yszxtz.voucher_type,  sysdate, v_row_yszxtz.oper_account, v_row_yszxtz.remark, '9', '', '', sysdate, v_row_yszxtz.remarks, '9', v_row_yszxtzmx.df_gk_zfpzid, v_row_yszxtz.oper_orgid) ;
695 
696                --- 插入 gk_adjust_detail 明细数据
697 
698                insert into gk_adjust_detail
699                  (gk_adjust_detail_id, gk_adjust_id, jf_unitno, jf_bdgid, jf_bdgt_type, jf_prj_code, jf_src_id, jf_zba_id, jf_item_id, df_unitno, df_bdgid, df_bdgt_type, df_prj_code, df_src_id, df_zba_id, df_item_id, balance, tocredit_amt, todebit_amt)
700                values
701                  (nextid('GK_ADJUST_DETAIL_SEQ'), v_gkadjustid,  v_row_yszxtzmx.jf_unitno , v_row_yszxtzmx.jf_budgetno, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_prjno, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_zb_id, v_row_yszxtzmx.jf_itemno,
702                  v_row_yszxtzmx.df_unitno,  v_row_yszxtzmx.df_budgetno,  v_row_yszxtzmx.df_budget_type, v_row_yszxtzmx.df_prjno, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_zb_id,v_row_yszxtzmx.df_itemno,  v_row_yszxtzmx.adjust_amt, 0, 0);
703 
704 
705 
706                                --- 打开 查询用款计划额度表的游标
707                                open cursor_gkykjhquota   for   select * into v_row_gkykjhquota   from gk_ykjh_quota q where q.zbz_bal_id=v_row_zbbal.id and q.plan_ny =to_char(sysdate,'yyyyMM');
708                                fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
709                                --当 额度表没有当前支付月份的该借方指标的额度数据的时候;
710                                 if cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null then
711                                     dbms_output.put_line('======如果:该借方指标id('||v_row_zbbal.id ||')在额度表不存在数据 则新增额度表数据======');
712 
713                                  ---判断借方指标该支付指标的金额是否够本次调整金额的支付
714                                     --1:查询查询指标是否可支付
715                                    select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
716                                      (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
717                                       into v_r_zbbal_info
718                                      from (  select  z.*,(case when  v_row_yszxtz.voucher_type ='0' then nvl(nvl(z.direct_amt,0)-nvl(direct_plan ,0),0)- v_row_yszxtzmx.adjust_amt
719                                                         when  v_row_yszxtz.voucher_type ='1' then nvl(nvl(z.accredit_amt ,0)-nvl(accredit_plan ,0),0)- v_row_yszxtzmx.adjust_amt
720                                                         end) as canpayamt,(case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
721                                                          from zb_bal z where z.id =v_row_zbbal.id ) vv ;
722 
723 
724                                    if  v_r_zbbal_info.canpayamt >=0 then
725                                        dbms_output.put_line('====');
726                                     ---如果够支付,则新增已经审结了用款计划数据(正的用款计划额度)
727 
728                                          ---向用款计划主表插入数据
729                                          v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
730                                          insert into gk_ykjh
731                                           (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
732                                          values
733                                           (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_r_zbbal_info.org_id , v_r_zbbal_info.n_fundtype , v_r_zbbal_info.unitno, v_r_zbbal_info.unit_name);
734 
735                                           ---向用款计划明细表插入数据
736                                           insert into gk_ykjh_mx
737                                             (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
738                                           values
739                                             (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_r_zbbal_info.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', v_row_yszxtzmx.adjust_amt,  v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
740 
741                                     --增加额度表的数据
742                                        insert into gk_ykjh_quota
743                                          (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
744                                        values
745                                          (nextid('GK_YKJH_QUOTA_SEQ'), v_r_zbbal_info.id, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.adjust_amt, v_row_yszxtzmx.adjust_amt, 0, 0);
746                                     --修改指标报表的 对应支付方式的 已报用款计划 字段的金额
747                                         if v_row_yszxtz.voucher_type='0' then  /*直接支付*/
748                                            update zb_bal z set z.direct_plan  =z.direct_plan+v_row_yszxtzmx.adjust_amt where z.id=v_row_zbbal.id;
749                                         elsif v_row_yszxtz.voucher_type='1'then  /*授权支付*/
750                                            update zb_bal z set z.accredit_plan  =z.accredit_plan+v_row_yszxtzmx.adjust_amt where z.id=v_row_zbbal.id;
751                                        end if;
752 
753                                   elsif  v_r_zbbal_info.canpayamt < 0  then
754                                   ---则 整个业务存储过程 本次执行业务回滚 ,应用程序进行审批操作事务回滚,终止预算执行调整审批的审结操作 。
755                                         raise  v_raise_over; /*跳转到异常部分代码*/
756                                   end if;
757 
758                                 else  /*当额度表该支付月份有支付额度数据时:*/
759 
760                                     while cursor_gkykjhquota%found loop
761                                         --判断 借方指标 id 在额度表中的 可以支付额度是否够本次调整支付金额支付。
762 
763                                           /*直接支付*/
764 
765                                              ---获取:额度表可以支付的额度 - 本次调整需要支付的支出数=需要支付的支出额
766                                              v_sub_amt := nvl((nvl(v_row_gkykjhquota.direct_apply,0) -nvl(v_row_gkykjhquota.direct_execute,0)),0)  /*额度表可支付额度*/ -  nvl(v_row_yszxtzmx.adjust_amt,0)/*调整金额*/ ;
767 
768                                              if v_sub_amt  >= 0  then
769                                                 --如果 额度表的支付额度 够 支付,则直接加大额度表直接支付的支出数
770                                                 update gk_ykjh_quota q set q.direct_execute=q.direct_execute+v_row_yszxtzmx.adjust_amt where  q.id=v_row_gkykjhquota.id  and q.zbz_bal_id=v_row_zbbal.id and q.plan_ny=to_char(sysdate,'yyyyMM');
771 
772                                              elsif   v_sub_amt  < 0  then
773 
774                                                 --如果 额度表的支付额度 不够 支付,则需要判断指标的可以支付金额是否够支付。
775                                                  dbms_output.put_line('======== ' );
776                                                   --1:查询查询指标是否可支付
777                                                    select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
778                                                      (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
779                                                       into v_r_zbbal_info
780                                                    from (  select  z.*, nvl(nvl(z.direct_amt,0)-nvl(direct_plan ,0),0)+ v_sub_amt   as canpayamt,
781                                                                   (case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
782                                                            from zb_bal z where z.id =v_row_zbbal.id ) vv ;
783 
784                                                   --如果 指标的可支付额度 够支付 额度表不够支付的差额
785                                                   if v_r_zbbal_info.canpayamt >0 then
786                                                      -- 则:插入用款计划主表数据
787                                                       v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
788                                                       insert into gk_ykjh
789                                                         (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
790                                                       values
791                                                         (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_r_zbbal_info.org_id , v_r_zbbal_info.n_fundtype , v_r_zbbal_info.unitno, v_r_zbbal_info.unit_name);
792 
793 
794                                                      --     插入用款计划明细表数据
795                                                       insert into gk_ykjh_mx
796                                                         (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
797                                                       values
798                                                         (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_r_zbbal_info.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', 0-v_sub_amt,  0-v_sub_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
799 
800 
801                                                      --     更新用款计划额度表数据的额度和支出数
802 
803                                                       update gk_ykjh_quota q set q.direct_execute=q.direct_execute+v_row_yszxtzmx.adjust_amt,q.direct_apply =q.direct_apply-v_sub_amt
804                                                          where  q.id=v_row_gkykjhquota.id  and q.zbz_bal_id=v_row_zbbal.id and q.plan_ny=to_char(sysdate,'yyyyMM');
805 
806 
807                                                      --     更新指标表 直接支付 已报用款计划  字段的值
808                                                      update zb_bal z set z.direct_plan =z.direct_plan-v_sub_amt where z.id=v_r_zbbal_info.id;
809 
810                                                   --如果指标的可支付额度   不够支付   额度表不够支付的差额
811                                                   elsif v_r_zbbal_info.canpayamt<0 then
812                                                     -- 则: 退出 整个存储过程执行,应用程序 预算执行调整审批 审结操作进行事物回滚
813                                                      raise  v_raise_over; /*跳转到异常部分代码*/
814                                                   end if ;
815                                               end if ;
816 
817 
818 
819                                     fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
820                                     exit when cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null;
821                                     end loop;
822                                     close  cursor_gkykjhquota;/*关闭游标*/
823                                 end if;
824             --支付方式为:授权支付
825             elsif v_row_yszxtz.voucher_type='1' then
826 
827                 ---20180305 troy
828                 ---判断累计额度是否够支出
829              /*   select sum(accredit_apply-accredit_execute)-v_row_yszxtzmx.adjust_amt  into v_sub_amt from gk_ykjh_quota q where
830                 q.zbz_bal_id = v_row_yszxtzmx.jf_zb_id;
831 
832                 if v_sub_amt>=0 then
833                    ---判断是否存在本月额度
834                  open cursor_gkykjhquota   for   select * into v_row_gkykjhquota   from gk_ykjh_quota q where q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny =to_char(sysdate,'yyyyMM');
835                                  fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
836 
837                  if cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null then
838                     ---如果不存在,生成当月额度
839                     --增加额度表的数据
840                    insert into gk_ykjh_quota
841                      (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
842                    values
843                      (nextid('GK_YKJH_QUOTA_SEQ'), v_row_yszxtzmx.jf_zb_id, to_char(sysdate,'yyyyMM'), 0, 0, 0, v_row_yszxtzmx.adjust_amt);
844                  else
845                    while cursor_gkykjhquota%found loop
846                     ---如果存在,改变额度数据
847                     update gk_ykjh_quota q set q.accredit_execute=q.accredit_execute+v_row_yszxtzmx.adjust_amt where
848                     q.zbz_bal_id=v_row_yszxtzmx.jf_zb_id and q.plan_ny=to_char(sysdate,'yyyyMM');
849 
850                    fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
851                    exit when cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null;
852                    end loop;
853                    close  cursor_gkykjhquota;\*关闭游标*\
854                  end if;
855 
856 
857                 elsif v_sub_amt<0 then*/
858                    --判断指标剩余指标金额是否够支出
859                    select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
860                  (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
861                  into v_r_zbbal_info
862                  from (  select  z.*,(case when  v_row_yszxtz.voucher_type ='0' then nvl(nvl(z.direct_amt,0)-nvl(direct_plan ,0),0)-v_row_yszxtzmx.adjust_amt
863                           when  v_row_yszxtz.voucher_type ='1' then nvl(nvl(z.accredit_amt ,0)-nvl(accredit_plan ,0),0)-v_row_yszxtzmx.adjust_amt
864                           end) as canpayamt,(case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
865                            from zb_bal z where z.id =v_row_zbbal.id ) vv ;
866 
867                  --如果指标够支付,生成审结的用款计划
868                  if  v_r_zbbal_info.canpayamt >=0 then
869                    ---向用款计划主表插入数据
870                    v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
871                    insert into gk_ykjh
872                     (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
873                    values
874                     (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '0', '0', '', v_r_zbbal_info.org_id , v_r_zbbal_info.n_fundtype , v_r_zbbal_info.unitno, v_r_zbbal_info.unit_name);
875 
876                    ---向用款计划明细表插入数据
877                    insert into gk_ykjh_mx
878                     (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit, zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
879                    values
880                     (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.jf_item_id, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_budgetid, v_row_yszxtzmx.jf_prjid , v_row_yszxtzmx.jf_adjlevel,  v_row_yszxtzmx.jf_org_id, '', '0', '1', v_r_zbbal_info.id, v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.jf_unitno, v_row_yszxtzmx.jf_unit_name, '0', v_row_yszxtzmx.adjust_amt,  v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.jf_budgetno,v_row_yszxtzmx.jf_itemno  ,v_row_yszxtzmx.jf_prjno );
881 
882                    --修改指标报表的 对应支付方式的 已报用款计划 字段的金额
883                    update zb_bal z set z.accredit_plan  =z.accredit_plan+v_row_yszxtzmx.adjust_amt where z.id=v_row_zbbal.id;
884                  --指标不够支付
885                  elsif  v_r_zbbal_info.canpayamt < 0  then
886                                   ---则 整个业务存储过程 本次执行业务回滚 ,应用程序进行审批操作事务回滚,终止预算执行调整审批的审结操作 。
887                                      raise  v_raise_over; /*跳转到异常部分代码*/
888                                  end if;
889 
890               /*  end if;*/
891 
892 
893                         ---如果支付方式为: 一般支付
894                         elsif v_row_yszxtz.voucher_type='3' then
895 
896                  dbms_output.put_line('====进行《支出账务调整》的业务逻辑处理:借方无指标id值: ==== ' );
897 
898                 ---插入gk_adjust 主表数据
899                insert into gk_adjust
900                  (id, is_accounting, adjustment_type, expenditure_type, create_dt, oper_account_id, remark, biz_status, process_instance_id, status, oper_dt, summary, process_status, gk_zfpz_id, oper_orgid)
901                values
902                  (v_gkadjustid, '1', '0', v_row_yszxtz.voucher_type,  sysdate, v_row_yszxtz.oper_account, v_row_yszxtz.remark, '9', '', '', sysdate, v_row_yszxtz.remarks, '9', v_row_yszxtzmx.df_gk_zfpzid, v_row_yszxtz.oper_orgid) ;
903 
904                --- 插入 gk_adjust_detail 明细数据
905 
906                insert into gk_adjust_detail
907                  (gk_adjust_detail_id, gk_adjust_id, jf_unitno, jf_bdgid, jf_bdgt_type, jf_prj_code, jf_src_id, jf_zba_id, jf_item_id, df_unitno, df_bdgid, df_bdgt_type, df_prj_code, df_src_id, df_zba_id, df_item_id, balance, tocredit_amt, todebit_amt)
908                values
909                  (nextid('GK_ADJUST_DETAIL_SEQ'), v_gkadjustid,  v_row_yszxtzmx.jf_unitno , v_row_yszxtzmx.jf_budgetno, v_row_yszxtzmx.jf_budget_type, v_row_yszxtzmx.jf_prjno, v_row_yszxtzmx.jf_src_id, v_row_yszxtzmx.jf_zb_id, v_row_yszxtzmx.jf_itemno,
910                  v_row_yszxtzmx.df_unitno,  v_row_yszxtzmx.df_budgetno,  v_row_yszxtzmx.df_budget_type, v_row_yszxtzmx.df_prjno, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_zb_id,v_row_yszxtzmx.df_itemno,  v_row_yszxtzmx.adjust_amt, 0, 0);
911 
912 
913 
914                              ----则需要判断 一般支付指标金额-一般支付的实际支出数=剩余可以支付的金额 是否可以够本次支付
915                              select vv.id,vv.canpayamt ,vv.org_id ,vv.n_fundtype ,vv.unitno ,
916                                (select u.unit_name from bs_bdg_unit u where u.unitno=vv.unitno) as unit_name
917                              into v_r_zbbal_info
918                              from
919                              ( select z.* ,nvl (nvl(z.tradition_amt,0)-nvl(z.tradition_num,0)- nvl(v_row_yszxtzmx.adjust_amt,0) ,0 ) as canpayamt ,
920                                      (case z.fundtype when '1' then '1' when '2' then '2' else '3' end) n_fundtype
921                               from zb_bal z where z.id =v_row_zbbal.id  ) vv ;
922 
923                              if v_r_zbbal_info.canpayamt >=0 then
924 
925                                 update zb_bal z set z.tradition_num =z.tradition_num+v_row_yszxtzmx.adjust_amt where z.id=v_row_zbbal.id;
926 
927                              elsif v_r_zbbal_info.canpayamt < 0 then
928                                 ---则 整个业务存储过程 本次执行业务回滚 ,应用程序进行审批操作事务回滚,终止预算执行调整审批的审结操作 。
929                                 raise  v_raise_over; /*跳转到异常部分代码*/
930                              end if;
931 
932 
933                         end if;
934               end if ;--是否存在结束
935  -----------------------------------------------------------------------------------------------------------
936              /* 贷方 1:判断该贷方指标在本支付年月是否操作额度数据:如果没有,则在额度表生成本支付月份的0值额度数据
937                                       如果有,则判断该支付月份是否有过支付数发生。
938                                                 如果有,则在原值上面减去支付发生数
939                                                 如果没有,则用0值减去 本次的支付金额
940                      2:做 贷方冲销的用款计划
941 
942                      3:减小 贷方指标的已报用款计划额度
943 
944              */
945         ---判断支付方式
946 
947                   --如果是 直接支付
948                   if v_row_yszxtz.voucher_type='0'  then
949 
950 
951                       ----查询 贷方指标 在额度表中是否有数据
952                         --- 打开 查询用款计划额度表  的  游标
953                        open cursor_gkykjhquota   for   select * into v_row_gkykjhquota
954                                from gk_ykjh_quota q where q.zbz_bal_id=v_row_yszxtzmx.df_zb_id and q.plan_ny =to_char(sysdate,'yyyyMM');
955 
956                                fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
957                         ---如果没有数据,
958                          if cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null then
959 
960                               ---直接支付
961 
962 
963                                  --插入一条 所有 0 值 额度计划数据,并把支付数(执行金额)的金额填上
964                                  insert into gk_ykjh_quota
965                                    (id, zbz_bal_id, plan_ny, direct_apply, direct_execute, accredit_apply, accredit_execute)
966                                  values
967                                    (nextid('GK_YKJH_QUOTA_SEQ'), v_row_yszxtzmx.df_zb_id, to_char(sysdate,'yyyyMM'), 0-v_row_yszxtzmx.adjust_amt,0-v_row_yszxtzmx.adjust_amt, 0, 0);
968 
969                                   --则 插入一条 冲销的 gk_ykjh  gk_ykjh_mx 的数据
970 
971                                      v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
972 
973                                     insert into gk_ykjh
974                                        (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
975                                      values
976                                      (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '1', '0', '',
977                                          v_row_yszxtzmx.df_org_id ,decode(v_row_yszxtzmx.df_fundtype,'1','1','2','2','3') , v_row_yszxtzmx.df_unitno,v_row_yszxtzmx.df_unit_name);
978 
979                                      ---向用款计划明细表插入数据
980                                     insert into gk_ykjh_mx
981                                       (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit,
982                                        zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
983                                     values
984                                       (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.df_item_id, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_budget_type,
985                                        v_row_yszxtzmx.df_budgetid, v_row_yszxtzmx.df_prjid , v_row_yszxtzmx.df_adjlevel,  v_row_yszxtzmx.df_org_id, '', '0', '1',
986                                        v_row_yszxtzmx.df_zb_id , v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.df_unitno, v_row_yszxtzmx.df_unit_name,
987                                        '1', -v_row_yszxtzmx.adjust_amt,  -v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.df_budgetno,v_row_yszxtzmx.df_itemno  ,v_row_yszxtzmx.df_prjno );
988 
989 
990                                   --则 更新 zb_bal 的相对应的已报用款计划额度 字段的值(即:减小该值)
991 
992                                      update zb_bal z set z.direct_plan=nvl(z.direct_plan,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
993 
994                         --如果有数据
995                          else
996                                  /*当额度表该支付月份有该指标的支付额度数据时:*/
997 
998                                 while cursor_gkykjhquota%found loop
999 
1000                                     --- 如果是直接支付
1001 
1002                                         --则 更新支付数(执行金额),即:减小执行金额的值。增大可以支付金额
1003                                             update gk_ykjh_quota q set q.direct_execute=nvl(q.direct_execute,0)-nvl(v_row_yszxtzmx.adjust_amt,0)  where q.zbz_bal_id=v_row_yszxtzmx.df_zb_id and q.plan_ny=to_char(sysdate,'yyyyMM');
1004 
1005                                         --则 插入一条 冲销的 gk_ykjh  gk_ykjh_mx 的数据
1006                                             v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
1007 
1008                                             insert into gk_ykjh
1009                                                (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
1010                                             values
1011                                              (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '1', '0', '',
1012                                                  v_row_yszxtzmx.df_org_id ,decode(v_row_yszxtzmx.df_fundtype,'1','1','2','2','3') , v_row_yszxtzmx.df_unitno,v_row_yszxtzmx.df_unit_name);
1013 
1014                                             insert into gk_ykjh_mx
1015                                                 (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit,
1016                                                  zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
1017                                             values
1018                                                 (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.df_item_id, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_budget_type,
1019                                                  v_row_yszxtzmx.df_budgetid, v_row_yszxtzmx.df_prjid , v_row_yszxtzmx.df_adjlevel,  v_row_yszxtzmx.df_org_id, '', '0', '1',
1020                                                  v_row_yszxtzmx.df_zb_id , v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.df_unitno, v_row_yszxtzmx.df_unit_name,
1021                                                  '1', -v_row_yszxtzmx.adjust_amt,  -v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.df_budgetno,v_row_yszxtzmx.df_itemno  ,v_row_yszxtzmx.df_prjno );
1022 
1023 
1024                                         --则 更新 zb_bal 的相对应的已报用款计划额度 字段的值(即:减小该值)
1025                                            update zb_bal z set z.direct_plan=nvl(z.direct_plan,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
1026 
1027 
1028 
1029 
1030                                 fetch cursor_gkykjhquota   into  v_row_gkykjhquota;
1031                                 exit when cursor_gkykjhquota%notfound or cursor_gkykjhquota%notfound is null;
1032                                 end loop;
1033                                 close  cursor_gkykjhquota;/*关闭游标*/
1034                          end if;
1035 
1036           --授权支付
1037            elsif v_row_yszxtz.voucher_type='1' then
1038                --则 插入一条 冲销的 gk_ykjh  gk_ykjh_mx 的数据
1039              v_gkykjhid :=nextid('GK_YKJH_SEQ'); /*获取:gk_ykjh 表主键*/
1040 
1041             insert into gk_ykjh
1042                (id, ykjh_type, plany_ym, remark, create_dt, status, biz_status, process_instance_id, oper_dt, oper_org_id, oper_account_id, is_writeoff, is_hz, remark_back, org_id, fundtype, unitno, unit_name)
1043              values
1044              (v_gkykjhid, v_row_yszxtz.voucher_type,   to_char(sysdate,'yyyyMM') ,'由预算执行调整生成,其id为 :'||v_row_yszxtz.id , sysdate, '9', '9', '', sysdate,v_row_yszxtz.oper_orgid,v_row_yszxtz.oper_account, '1', '0', '',
1045                v_row_yszxtzmx.df_org_id ,decode(v_row_yszxtzmx.df_fundtype,'1','1','2','2','3') , v_row_yszxtzmx.df_unitno,v_row_yszxtzmx.df_unit_name);
1046 
1047              ---向用款计划明细表插入数据
1048             insert into gk_ykjh_mx
1049               (id, gk_ykjh_id, item_id, src_id, bdgt_id_type, budgetid, prj_id, adjlevel, org_id, gk_hzqsd_id, issued, counting_unit,
1050                zbz_bal_id, ykjh_type, plany_ym, unitno, unit_name, is_writeoff, apply_amt, fin_amt, is_print, budgetno, itemno, prj_code)
1051             values
1052               (nextid('GK_YKJH_MX_SEQ'), v_gkykjhid,  v_row_yszxtzmx.df_item_id, v_row_yszxtzmx.df_src_id, v_row_yszxtzmx.df_budget_type,
1053                v_row_yszxtzmx.df_budgetid, v_row_yszxtzmx.df_prjid , v_row_yszxtzmx.df_adjlevel,  v_row_yszxtzmx.df_org_id, '', '0', '1',
1054                v_row_yszxtzmx.df_zb_id , v_row_yszxtz.voucher_type, to_char(sysdate,'yyyyMM'), v_row_yszxtzmx.df_unitno, v_row_yszxtzmx.df_unit_name,
1055                '1', -v_row_yszxtzmx.adjust_amt,  -v_row_yszxtzmx.adjust_amt, '0', v_row_yszxtzmx.df_budgetno,v_row_yszxtzmx.df_itemno  ,v_row_yszxtzmx.df_prjno );
1056 
1057 
1058             --则 更新 zb_bal 的相对应的已报用款计划额度 字段的值(即:减小该值)
1059             update zb_bal z set z.accredit_plan=nvl(z.accredit_plan,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
1060 
1061                   --如果是 一般支付
1062                    elsif v_row_yszxtz.voucher_type='3' then
1063 
1064                        --更新 该指标的 一般支付的实际支出数 。即:减小该实际支出数
1065                         update zb_bal z set z.tradition_num=nvl(z.tradition_num,0)-nvl(v_row_yszxtzmx.adjust_amt ,0) where z.id=v_row_yszxtzmx.df_zb_id;
1066 
1067                  end if;
1068 
1069 
1070 
1071           else
1072                 raise  v_raise;
1073           end if ;
1074 
1075 ---------贷方指标 为null
1076        elsif  v_row_yszxtzmx.df_id is   null  then   /*进行《预算调整 》的业务逻辑处理*/
1077 
1078         if v_row_yszxtzmx.jf_id is not null then
1079 
1080               if v_row_yszxtzmx.df_entire_manage is null then
1081               ----查询指标表是否存在 与(无指标id的)贷方数据 相同的指标数据存在
1082               open cursor_zbbal   for     select * into v_row_zbbal from zb_bal z where      z.unitno =v_row_yszxtzmx.df_unitno
1083                    and  z.src_id =v_row_yszxtzmx.df_src_id
1084                    and  z.bdgyear =v_row_yszxtz.bdgyear
1085                    and  z.prj_id =v_row_yszxtzmx.df_prjid
1086                    and  z.zb_project_type =v_row_yszxtzmx.df_zb_project_type
1087                    and  z.budgetid =v_row_yszxtzmx.df_budgetid
1088                    and  z.bdgt_id_type =v_row_yszxtzmx.df_budget_type
1089                    and  z.is_unify =v_row_yszxtzmx.df_is_unify
1090                    and  z.entire_manage is null;
1091                else
1092                   open cursor_zbbal   for     select * into v_row_zbbal from zb_bal z where      z.unitno =v_row_yszxtzmx.df_unitno
1093                    and  z.src_id =v_row_yszxtzmx.df_src_id
1094                    and  z.bdgyear =v_row_yszxtz.bdgyear
1095                    and  z.prj_id =v_row_yszxtzmx.df_prjid
1096                    and  z.zb_project_type =v_row_yszxtzmx.df_zb_project_type
1097                    and  z.budgetid =v_row_yszxtzmx.df_budgetid
1098                    and  z.bdgt_id_type =v_row_yszxtzmx.df_budget_type
1099                    and  z.is_unify =v_row_yszxtzmx.df_is_unify
1100                    and  z.entire_manage=v_row_yszxtzmx.df_entire_manage ;
1101                 end if;
1102           fetch cursor_zbbal into v_row_zbbal;
1103         ---判断:如果 指标表  不存在     贷方相同的指标数据
1104         if cursor_zbbal%notfound or cursor_zbbal%notfound is null then
1105 
1106 
1107           if v_row_yszxtz.voucher_type='0' then --直接支付
1108 
1109              --新增指标数据,其指标金额为:为对应支付方式调整金额
1110              insert into zb_bal (id,BDGYEAR,UNITID,unitno,SRC_ID,BDGT_ID_TYPE,BUDGETID,PRJ_ID,ITEM_ID,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,
1111             ORG_ID,ADJLEVEL,ZB_PROJECT_TYPE,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,ISSUE_NUM,ENTIRE_MANAGE,BZ)
1112             values (nextid('ZB_BAL_SEQ'),v_row_yszxtz.bdgyear,(select unitid from bs_bdg_unit where unitno=v_row_yszxtzmx.DF_UNITNO),v_row_yszxtzmx.DF_UNITNO,v_row_yszxtzmx.DF_SRC_ID,v_row_yszxtzmx.DF_BUDGET_TYPE,
1113             v_row_yszxtzmx.DF_BUDGETID,v_row_yszxtzmx.DF_PRJID,v_row_yszxtzmx.DF_ITEM_ID,v_row_yszxtzmx.adjust_amt,v_row_yszxtzmx.adjust_amt,0,0,0,0,
1114             v_row_yszxtzmx.DF_ORG_ID,v_row_yszxtzmx.DF_ADJLEVEL,v_row_yszxtzmx.DF_ZB_PROJECT_TYPE,0,0,0,0,v_row_yszxtzmx.DF_FUNDTYPE,0,v_row_yszxtzmx.DF_ENTIRE_MANAGE,'预算执行调整'||v_row_yszxtz.id||'生成');
1115 
1116              update zb_bal set zb_amt=zb_amt-v_row_yszxtzmx.adjust_amt ,
1117             DIRECT_AMT=DIRECT_AMT-v_row_yszxtzmx.adjust_amt where id=v_row_yszxtzmx.JF_ZB_ID;
1118           elsif v_row_yszxtz.voucher_type='1' then --授权支付
1119 
1120              --新增指标数据,其指标金额为:为对应支付方式调整金额
1121              insert into zb_bal (id,BDGYEAR,UNITID,unitno,SRC_ID,BDGT_ID_TYPE,BUDGETID,PRJ_ID,ITEM_ID,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,
1122             ORG_ID,ADJLEVEL,ZB_PROJECT_TYPE,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,ISSUE_NUM,ENTIRE_MANAGE,BZ)
1123             values (nextid('ZB_BAL_SEQ'),v_row_yszxtz.bdgyear,(select unitid from bs_bdg_unit where unitno=v_row_yszxtzmx.DF_UNITNO),v_row_yszxtzmx.DF_UNITNO,v_row_yszxtzmx.DF_SRC_ID,v_row_yszxtzmx.DF_BUDGET_TYPE,
1124             v_row_yszxtzmx.DF_BUDGETID,v_row_yszxtzmx.DF_PRJID,v_row_yszxtzmx.DF_ITEM_ID,v_row_yszxtzmx.adjust_amt,0,v_row_yszxtzmx.adjust_amt,0,0,0,
1125             v_row_yszxtzmx.DF_ORG_ID,v_row_yszxtzmx.DF_ADJLEVEL,v_row_yszxtzmx.DF_ZB_PROJECT_TYPE,0,0,0,0,v_row_yszxtzmx.DF_FUNDTYPE,0,v_row_yszxtzmx.DF_ENTIRE_MANAGE,'预算执行调整'||v_row_yszxtz.id||'生成');
1126 
1127          update zb_bal set zb_amt=zb_amt-v_row_yszxtzmx.adjust_amt ,
1128             ACCREDIT_AMT=ACCREDIT_AMT-v_row_yszxtzmx.adjust_amt where id=v_row_yszxtzmx.JF_ZB_ID;
1129 
1130           elsif v_row_yszxtz.voucher_type='3' then --一般支付
1131 
1132              --新增指标数据,其指标金额为:为对应支付方式调整金额
1133              insert into zb_bal (id,BDGYEAR,UNITID,unitno,SRC_ID,BDGT_ID_TYPE,BUDGETID,PRJ_ID,ITEM_ID,ZB_AMT,DIRECT_AMT,ACCREDIT_AMT,DIRECT_PLAN,ACCREDIT_PLAN,TRADITION_AMT,
1134             ORG_ID,ADJLEVEL,ZB_PROJECT_TYPE,EARLY_AMT,EARLY_CHANGE_AMT,ADDITIONAL_AMT,TRADITION_NUM,FUNDTYPE,ISSUE_NUM,ENTIRE_MANAGE,BZ)
1135             values (nextid('ZB_BAL_SEQ'),v_row_yszxtz.bdgyear,(select unitid from bs_bdg_unit where unitno=v_row_yszxtzmx.DF_UNITNO),v_row_yszxtzmx.DF_UNITNO,v_row_yszxtzmx.DF_SRC_ID,v_row_yszxtzmx.DF_BUDGET_TYPE,
1136             v_row_yszxtzmx.DF_BUDGETID,v_row_yszxtzmx.DF_PRJID,v_row_yszxtzmx.DF_ITEM_ID,v_row_yszxtzmx.adjust_amt,0,0,0,0,0,
1137             v_row_yszxtzmx.DF_ORG_ID,v_row_yszxtzmx.DF_ADJLEVEL,v_row_yszxtzmx.DF_ZB_PROJECT_TYPE,0,0,0,v_row_yszxtzmx.adjust_amt,v_row_yszxtzmx.DF_FUNDTYPE,0,v_row_yszxtzmx.DF_ENTIRE_MANAGE,'预算执行调整'||v_row_yszxtz.id||'生成');
1138 
1139 
1140             update zb_bal set zb_amt=zb_amt-v_row_yszxtzmx.adjust_amt ,
1141             TRADITION_AMT=TRADITION_AMT-v_row_yszxtzmx.adjust_amt where id=v_row_yszxtzmx.JF_ZB_ID;
1142           end if;
1143         else --指标表存在贷方相同信息的指标
1144 
1145           if v_row_yszxtz.voucher_type='0' then
1146             update zb_bal set zb_amt=zb_amt+v_row_yszxtzmx.adjust_amt ,
1147             DIRECT_AMT=DIRECT_AMT+v_row_yszxtzmx.adjust_amt where id=v_row_zbbal.id;
1148 
1149               update zb_bal set zb_amt=zb_amt-v_row_yszxtzmx.adjust_amt ,
1150             DIRECT_AMT=DIRECT_AMT-v_row_yszxtzmx.adjust_amt where id=v_row_yszxtzmx.JF_ZB_ID;
1151           elsif v_row_yszxtz.voucher_type='1' then
1152             update zb_bal set zb_amt=zb_amt+v_row_yszxtzmx.adjust_amt ,
1153             ACCREDIT_AMT=ACCREDIT_AMT+v_row_yszxtzmx.adjust_amt where id=v_row_zbbal.id;
1154 
1155              update zb_bal set zb_amt=zb_amt-v_row_yszxtzmx.adjust_amt ,
1156             ACCREDIT_AMT=ACCREDIT_AMT-v_row_yszxtzmx.adjust_amt where id=v_row_yszxtzmx.JF_ZB_ID;
1157           elsif v_row_yszxtz.voucher_type='3' then
1158             update zb_bal set zb_amt=zb_amt+v_row_yszxtzmx.adjust_amt ,
1159             TRADITION_AMT=TRADITION_AMT+v_row_yszxtzmx.adjust_amt where id=v_row_zbbal.id;
1160 
1161               update zb_bal set zb_amt=zb_amt-v_row_yszxtzmx.adjust_amt ,
1162             TRADITION_AMT=TRADITION_AMT-v_row_yszxtzmx.adjust_amt where id=v_row_yszxtzmx.JF_ZB_ID;
1163           end if;
1164 
1165         end if;
1166 
1167            else
1168                 raise  v_raise;
1169            end if ;
1170       else
1171                dbms_output.put_line('===查询预算执行调整明细---》支出执行明细表 无明细 df_id 数据===== ' );
1172                raise  v_raise;
1173        end if;
1174 
1175     fetch cursor_yszxtzmx      into  v_row_yszxtzmx;/*先让指针指向结果集中的第一行,并将值保存到 v_row_yszxtz 中*/
1176     /*退出循环的条件*/
1177     exit when cursor_yszxtzmx%notfound or cursor_yszxtzmx%notfound is null;
1178 
1179     end loop;
1180     close cursor_yszxtzmx  ;/*关闭游标*/
1181 --========================================================================================================================
1182 --=======================   结束:查询预算执行调整明细---》支出执行明细表  数据转换逻辑处理             ========================
1183 ---========================================================================================================================
1184   if v_row_yszxtz.voucher_type!='1' then
1185   update ys_zxtz set CONCLUDE_DT = sysdate ,GK_ADJUST_ID = v_adjust_liststr where id =v_row_yszxtz.id ;
1186   end if;
1187   fetch cursor_yszxtz    into  v_row_yszxtz;/*先让指针指向结果集中的第一行,并将值保存到 v_row_yszxtz 中*/
1188    /*退出循环的条件*/
1189    exit when cursor_yszxtz%notfound or cursor_yszxtz%notfound is null;
1190    end loop;
1191 close cursor_yszxtz;/*关闭游标*/
1192 dbms_output.put_line('============================================预算执行调整的 业务逻辑处理结束:关闭游标============================================' );
1193 
1194 ----捕获错误及异常,事务回滚
1195 exception
1196 
1197    when v_raise then
1198         rollback;
1199         flag := 'false';
1200         out_return := 'flag=' || flag || ',errorcode= “ora-00100” ,errormsg=  “未找到数据”';
1201    when v_raise_over then
1202         rollback;
1203         errormsg:= '“预算执行调整其序号为:'||v_row_yszxtz.id ||'的明细数据中编号为:'  ||v_row_yszxtzmx.jf_id ||'的这行数据中的借方指标:'||v_row_yszxtzmx.JF_ZB_ID||'的指标可以支付的剩余指标金额不够本次调整金额的支付”';
1204         flag := 'false';
1205        out_return := 'flag=' || flag || ',errorcode= “ora-00100” ,errormsg= '||errormsg;
1206    when errorexception then
1207         rollback;
1208         errorcode := sqlcode;
1209         errormsg := substr(sqlerrm, 1, 200);
1210         flag := 'false';
1211         out_return := 'flag=' || flag || ',errorcode=' || errorcode || ',errormsg=' || errormsg;
1212    when others then
1213         rollback;
1214         errorcode := sqlcode;
1215         errormsg := substr(sqlerrm, 1, 200);
1216         flag := 'false';
1217         out_return := 'flag=' || flag || ',errorcode=' || errorcode || ',errormsg=' || errormsg;
1218 
1219 ----执行数据入库,返回正确结果
1220 commit;
1221 flag := 'true';
1222 out_return := 'flag=' || flag|| ',errorcode= “ ” ,errormsg=  “ ”' ;
1223 
1224 end proc_yszxtz_aduit;

 

 

 

示例9: 存储过程拼接 sql in 里面的查询条件值

  1 
  2 ----创建 保存界面选择的zfpz表的 id
  3 drop table  GK_ZWVCH_ZFZXZ_ZFPZ_IDS ;
  4 create table   GK_ZWVCH_ZFZXZ_ZFPZ_IDS(
  5  id number(20)  not null primary key ,
  6  pcno number(20) ,
  7  zfpz_ids varchar(3000)
  8 );
  9 
 10 comment on table GK_ZWVCH_ZFZXZ_ZFPZ_IDS is '保存支付中心帐界面选择的所有支付凭证id ';
 11 comment on column GK_ZWVCH_ZFZXZ_ZFPZ_IDS.ID is '主键';
 12 comment on column GK_ZWVCH_ZFZXZ_ZFPZ_IDS.pcno is '批次号';
 13 comment on column GK_ZWVCH_ZFZXZ_ZFPZ_IDS.zfpz_ids is 'gk_zfpz表的主键id:数据格式为:123,124,125';
 14 
 15 ;
 16 
 17 
 18 --创建索引
 19 create index idx_pcno on GK_ZWVCH_ZFZXZ_ZFPZ_IDS (pcno);
 20 
 21 insert into GK_ZWVCH_ZFZXZ_ZFPZ_IDS (ID, PCNO, ZFPZ_IDS) values (0, 0, '0,0');
 22 commit;
 23 
 24 ---创建序列号

 32 
 33 ---创建游标结果集合
 34 CREATE OR REPLACE PACKAGE PKG_QUERY IS
 35 
 36   -- Author  : ADMINISTRATOR
 37   -- Created : 2016/12/8 星期四 10:28:37
 38   -- Purpose : 用做查询游标
 39 
 40   -- Public type declarations
 41   TYPE CUR_QUERY IS REF CURSOR;
 42 
 43 END PKG_QUERY;
 44 

 

  1 create or replace procedure PRO_K3_ZFZXZ(
  2         ZFPZ_IDS_PCH in number ,
  3        v_cur  out pkg_query.cur_query  )
  4 is
  5   type ref_cursor_type is ref cursor;
  6   cursor_ids  ref_cursor_type;      /*声明:查询 GK_ZWVCH_ZFZXZ_ZFPZ_IDS 表 数据 的游标对象 */
  7   v_row_zfzxz_zfpz_ids gk_zwvch_zfzxz_zfpz_ids%rowtype    ; /*声明:GK_ZWVCH_ZFZXZ_ZFPZ_IDS 单条数据对象 */
  8   v_sql VARCHAR2(4000);
  9   v_ids_sql varchar2(4000);
 10   v_ids  varchar2(4000) :='';
 11   v_index number :=0 ;/*循环数据的循环次数*/
 12 begin
 13  v_ids_sql:= 'select   ids.id as id  ,ids.pcno as pcno ,ids.zfpz_ids as zfpz_ids  
 14             from gk_zwvch_zfzxz_zfpz_ids  ids where ids.pcno='||ZFPZ_IDS_PCH ;
 15 open cursor_ids for v_ids_sql ;
 16   /**  判断 是否有id 值查询出来  */
 17   fetch cursor_ids   into  v_row_zfzxz_zfpz_ids;
 18   if cursor_ids%found    then
 19        v_ids :=v_ids|| ' AND ( ' ;
 20       while cursor_ids%found loop
 21         /*循环查询结果拼接sql 判断条件*/
 22          if v_index=0 then
 23             v_ids := v_ids||'   z.id in ('||v_row_zfzxz_zfpz_ids.zfpz_ids||')';
 24              v_index := 1;
 25         else
 26             v_ids :=  v_ids|| ' OR z.id in ('||v_row_zfzxz_zfpz_ids.zfpz_ids ||')';
 27          end if;
 28         fetch cursor_ids   into  v_row_zfzxz_zfpz_ids;/*先让指针指向结果集中的第一行,并将值保存到emp_row 中*/
 29         exit when cursor_ids%notfound or cursor_ids%notfound is null;
 30 
 31       end loop;
 32       v_ids :=v_ids|| ' )' ;
 33       v_index := 0;
 34   end if;
 35 
 36 
 37   v_sql :=   ' select z.id as id ,z.fk_name as fk_name from gk_zfpz z where  1=1 ';
 38  if  length(v_ids) > 1 then
 39    v_sql :=v_sql ||v_ids;
 40  end if;
 41   dbms_output.put_line('====进行PRO_K3_ZFZXZ 调试  GK_ZWVCH_ZFZXZ_ZFPZ_IDS 批次号   v_sql='|| v_sql||'==== ' );
 42 OPEN v_cur FOR v_sql;
 43 close  cursor_ids;/*关闭游标*/
 44 end PRO_K3_ZFZXZ;
 45 

 

 

  1 
  2 select   * from gk_zwvch_zfzxz_zfpz_ids  ids   for update  ;
  3 
  4 select  max(z.pcno)+1   from  GK_ZWVCH_ZFZXZ_ZFPZ_IDS z ;
  5 
  6 SELECT  NEXTID('GK_ZWVCH_ZFZXZ_ZFPZ_IDS_SEQ') FROM DUAL;
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 ----创建 保存界面选择的zfpz表的 id
 17 drop table  GK_ZWVCH_ZFZXZ_ZFPZ_IDS ;
 18 create table   GK_ZWVCH_ZFZXZ_ZFPZ_IDS(
 19  id number(20)  not null primary key ,
 20  pcno number(20) ,
 21  zfpz_ids varchar(3000)
 22 );
 23 
 24 comment on table GK_ZWVCH_ZFZXZ_ZFPZ_IDS is '保存支付中心帐界面选择的所有支付凭证id ';
 25 comment on column GK_ZWVCH_ZFZXZ_ZFPZ_IDS.ID is '主键';
 26 comment on column GK_ZWVCH_ZFZXZ_ZFPZ_IDS.pcno is '批次号';
 27 comment on column GK_ZWVCH_ZFZXZ_ZFPZ_IDS.zfpz_ids is 'gk_zfpz表的主键id:数据格式为:123,124,125';
 28 
 29 ;
 30 
 31 
 32 --创建索引
 33 create index idx_pcno on GK_ZWVCH_ZFZXZ_ZFPZ_IDS (pcno);
 34 
 35 insert into GK_ZWVCH_ZFZXZ_ZFPZ_IDS (ID, PCNO, ZFPZ_IDS) values (0, 0, '0,0');
 36 commit;
 37 
 38 ---创建序列号 
 39 insert into PWP_NO (NOID, PREFIX, INITIALVALUE, BUFFERSIZE, POSTFIX, NOINCREMENT, NONAME, NOLENGTH, NOTYPE)
 40 values ('GK_ZWVCH_ZFZXZ_ZFPZ_IDS_SEQ', null, 1, 10, null, 1, 'GK_ZWVCH_ZFZXZ_ZFPZ_IDS_SEQ', 20, 1);
 41 insert into PWP_NODTL (NOID, PREFIX, NODAY, NEXTID, POSTFIX, NOINCREMENT, NOYEAR, NOMONTH)
 42 values ('GK_ZWVCH_ZFZXZ_ZFPZ_IDS_SEQ', null, 0, 2, null, 1, 2018, 4);
 43 
 44 commit;
 45 
 46 
 47 create or replace view view_k3_zfzxz_zfpz_group as
 48 select z.unitno, z.prjno, z.src_id, z.budget_type, z.budgetno, z.zf_itemno
 49 ----创建视图:进行分组。主要用于存储过程pro_k3_zfzxz 的 rowtype里的 
 50  from view_k3_zfzxz_zfpz z  group by z.unitno,  z.prjno,z.src_id, z.budget_type,z.budgetno,z.bdgt_accid, z.prjno, z.zf_itemno
 51  order by z.unitno, z.prjno,  z.src_id, z.budget_type, z.budgetno,  z.bdgt_accid,  z.prjno, z.zf_itemno ;
 52 comment on table view_k3_zfzxz_zfpz_group is '该视图主要是用于 存储过程  pro_k3_zfzxz 的 rowtype里的  ;作为一个rowtype 类型使用而已 ';
 53 
 54 
 55 
 56 create or replace view view_k3_zfzxz_zfpz_count as     select count(a) as count_no  from (  select  '1' as a from dual );
 57 comment on table view_k3_zfzxz_zfpz_count is '该视图主要是用于 存储过程  pro_k3_zfzxz 的 rowtype里的  ;作为一个rowtype 类型使用而已 ';
 58 
 59 
 60 create or replace view view_k3_zfzxz_zfpz_sum as
 61 select  sum_amt,sum_zf_item_amt,sum_zfpz_amt,list_gk_zfpz_id,list_id,list_origin_id,list_voucher_no,list_purpose,list_remark,list_bm_itemnos from  (
 62 ----该视图主要是用于 存储过程  pro_k3_zfzxz 的 rowtype里的  ;作为一个rowtype 类型使用而已
 63     select  sum(z.amt) as sum_amt ,sum(z.zf_item_amt) as sum_zf_item_amt ,
 64     sum(z.zfpz_amt) as sum_zfpz_amt ,
 65     listagg(z.gk_zfpz_id, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_gk_zfpz_id   ,
 66     listagg(z.id, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_id   ,
 67     listagg(z.origin_id, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_origin_id   ,
 68     listagg(z.voucher_no, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_voucher_no   ,
 69     listagg(z.purpose, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_purpose  ,
 70     listagg(z.remark, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_remark  ,
 71     listagg(z.bm_itemnos, ',') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_bm_itemnos
 72     from view_k3_zfzxz_zfpz z where 1=1
 73     and (z.id in (1475844, 1476130, 1476144) or  z.id in (1485844, 1478130, 1476644))
 74     and  z.unitno=  0021
 75     and  z.prjno=	0000030201
 76     and  z.src_id=	000
 77     and  z.budget_type=	2
 78     and  z.budgetno=	2040201
 79     and  z.zf_itemno=	50299
 80  ) ;
 81 comment on table view_k3_zfzxz_zfpz_sum is '该视图主要是用于 存储过程  pro_k3_zfzxz 的 rowtype里的  ;作为一个rowtype 类型使用而已 ';
 82 
 83 
 84 
 85 drop table gk_zwentry_k3_zfzxz_zfpz_temp ;
 86 
 87 
 88 ---创建 事务级别的临时表 。用来存放进行同单位同资金来源同项目同功能分类科目同经济分类的合并数据
 89 create   global temporary table  gk_zwentry_k3_zfzxz_zfpz_temp  on commit delete rows
 90  as select * from view_k3_zfzxz_zfpz v where 1=2 ;
 91 
 92 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify gk_zfpz_id varchar2(4000);
 93 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify id varchar2(4000);
 94 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify origin_id varchar2(4000);
 95 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify voucher_no  varchar2(4000);
 96 
 97 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify purpose varchar2(4000);
 98 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify remark varchar2(4000);
 99 alter table gk_zwentry_k3_zfzxz_zfpz_temp modify bm_itemnos varchar2(4000);
100 
101 comment on table gk_zwentry_k3_zfzxz_zfpz_temp is '事务级别的临时表 。用来存放对视图view_k3_zfzxz_zfpz进行同单位同资金来源同项目同功能分类科目同经济分类的合并数据 ';
102 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.gk_zfpz_id         is 'gk_zfpz 表id   ' ;
103 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.id                 is 'gk_zfpz 表id    ' ;
104 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.origin_id          is '凭证来源id    ' ;
105 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.voucher_no         is '支付凭证号    ' ;
106 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.make_date          is '支付凭证日期    ' ;
107 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.fk_account         is ' 付款人账号   ' ;
108 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.fk_bank            is ' 付款人开户银行   ' ;
109 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.src_id             is '资金来源代码   ' ;
110 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.sk_name            is '收款人全称    ' ;
111 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.sk_account         is '收款人账号    ' ;
112 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.sk_bank            is ' 收款人开户银行   ' ;
113 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.unitno             is '单位编码    ' ;
114 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.unit_name          is '单位名称    ' ;
115 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.budget_type        is '科目类型代码    ' ;
116 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.bdgt_accid         is '' ;
117 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.budgetno           is '功能分类科目编码    ' ;
118 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.budget_name        is '功能分类科目名称    ' ;
119 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.prjno              is '项目编码    ' ;
120 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.prj_name           is '项目名称    ' ;
121 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.zfpz_amt           is '金额(支付凭证表)    ' ;
122 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.amt                is ' 金额(经济分类表)   ' ;
123 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.purpose            is '用途    ' ;
124 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.remark             is ' 备注   ' ;
125 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.checker            is '审核人   ' ;
126 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.checker_date       is ' 审核日期   ' ;
127 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.affirmer           is '对碰人     ' ;
128 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.affirm_date        is '对碰日期    ' ;
129 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.voucher_type       is '支付凭证类型(参考gk_zfpz表支付凭证类型 )    ' ;
130 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.check_status       is '对碰状态(参考gk_zfpz表对碰状态)  ' ;
131 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.wf_status          is ' 审结状态(0草稿,1未审结,9已审结)   ' ;
132 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.gk_hzqsd_id        is ' 汇总清算单号   ' ;
133 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.fund               is '' ;
134 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.org_type           is '' ;
135 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.back_oper_id       is '' ;
136 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.back_oper_idea     is '' ;
137 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.back_oper_date     is '' ;
138 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.back_checker_id    is '' ;
139 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.back_checker_idea  is '' ;
140 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.back_checker_date  is '' ;
141 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.zf_item_amt        is '政府经济分类支付金额   ' ;
142 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.zf_itemno          is '政府经济分类编码   ' ;
143 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.zf_itemname        is '政府经济分类名称   ' ;
144 comment on column gk_zwentry_k3_zfzxz_zfpz_temp.bm_itemnos         is '部门经济分类编码   ' ;
145 
146 
147 
148 
149 
150 
151 
152 
153 ---创建游标结果集合
154 CREATE OR REPLACE PACKAGE PKG_QUERY IS
155 
156   -- Author  : ADMINISTRATOR
157   -- Created : 2016/12/8 星期四 10:28:37
158   -- Purpose : 用做查询游标
159 
160   -- Public type declarations
161   TYPE CUR_QUERY IS REF CURSOR;
162 
163 END PKG_QUERY;
164 
165 
166 
167 
168 ---创建 获取数据的存储过程
169   create or replace procedure PRO_K3_ZFZXZ(
170         ZFPZ_IDS_PCH in number ,
171        v_cur  out pkg_query.cur_query  )
172 is
173   type ref_cursor_type is ref cursor;
174   cursor_ids  ref_cursor_type;   /*游标*/    /*声明:查询 GK_ZWVCH_ZFZXZ_ZFPZ_IDS 表 数据 的游标对象 */
175   v_row_zfzxz_zfpz_ids gk_zwvch_zfzxz_zfpz_ids%rowtype    ; /*声明:GK_ZWVCH_ZFZXZ_ZFPZ_IDS 单条数据对象 */
176   v_sql VARCHAR2(4000);
177   v_ids_sql varchar2(4000);
178   v_ids  varchar2(4000) :='';
179   v_index number :=0 ;/*循环数据的循环次数*/
180 
181   /* 获取分组数据信息 */
182   cursor_zfzxz_zfpz  ref_cursor_type;  /*游标*/
183   v_row_zfzxz_zfpz view_k3_zfzxz_zfpz_group%rowtype  ;
184   v_zfzxz_zfpz_sql  varchar2(4000) :='';
185 
186   /** 分组求和  **/
187   cursor_gb_zfzxz ref_cursor_type; /*游标*/
188   v_gb_zfzxz_sql varchar2(4000) :='';
189   v_row_gb_zfzxz view_k3_zfzxz_zfpz_sum%rowtype  ;
190 
191   v_sum_amt number(16,2) :=0;
192   v_sum_zf_item_amt number(16,2) :=0;
193   v_sum_zfpz_amt number(16,2) :=0;
194   v_list_gk_zfpz_id  varchar2(4000) :='';
195   v_list_id  varchar2(4000) :='';
196   v_list_origin_id  varchar2(4000) :='';
197   v_list_voucher_no  varchar2(4000) :='';
198   v_list_purpose  varchar2(4000) :='';
199   v_list_remark  varchar2(4000) :='';
200   v_list_bm_itemnos varchar2(4000) :='';
201 
202   /*查询 view_k3_zfzxz_zfpz 的具体信息 */
203   cursor_q_vk3_zfzxzzfpz ref_cursor_type; /*游标*/
204   v_q_vk3_zfzxzzfpz_sql  varchar2(4000) :='' ;
205   v_row_q_vk3_zfzxzzfpz view_k3_zfzxz_zfpz%rowtype  ;
206 
207 
208   /*查询 view_k3_zfzxz_zfpz 的具体有多少条数据信息*/
209   cursor_q_vk3_zfzxzzfpz_count ref_cursor_type; /*游标*/
210   v_row_q_vk3_zfzxzzfpz_count view_k3_zfzxz_zfpz_count%rowtype  ;
211   v_q_vk3_zfzxzzfpz_count_sql  varchar2(4000) :='' ;
212   v_rowcount number :=0;/*获取游标取数的条数*/
213 
214 
215 
216 begin
217  v_ids_sql:= 'select   ids.id as id  ,ids.pcno as pcno ,ids.zfpz_ids as zfpz_ids  
218             from gk_zwvch_zfzxz_zfpz_ids  ids where ids.pcno='||ZFPZ_IDS_PCH ;
219 
220 open cursor_ids for v_ids_sql ;
221   /**  判断 是否有id 值查询出来  */
222   fetch cursor_ids   into  v_row_zfzxz_zfpz_ids;
223   if cursor_ids%found    then
224        v_ids :=v_ids|| ' AND ( ' ;
225       while cursor_ids%found loop
226         /*循环查询结果拼接sql 判断条件*/
227          if v_index=0 then
228             v_ids := v_ids||'   z.id in ('||v_row_zfzxz_zfpz_ids.zfpz_ids||')';
229              v_index := 1;
230         else
231             v_ids :=  v_ids|| ' OR z.id in ('||v_row_zfzxz_zfpz_ids.zfpz_ids ||')';
232          end if;
233         fetch cursor_ids   into  v_row_zfzxz_zfpz_ids;/*先让指针指向结果集中的第一行,并将值保存到emp_row 中*/
234         exit when cursor_ids%notfound or cursor_ids%notfound is null;
235 
236       end loop;
237       v_ids :=v_ids|| ' )' ;
238       v_index := 0;
239   end if;
240 
241 
242 /*获取视图 view_k3_zfzxz_zfpz 的 同单位 同资金来源 同项目 同功能分类科目类型 同功能分类科目编码 同政府经济分类编码 的数据 */
243 v_zfzxz_zfpz_sql :=' select  z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno     from  view_k3_zfzxz_zfpz z where 1=1   ';
244 
245 if  length(v_ids) > 1 then
246    v_zfzxz_zfpz_sql :=v_zfzxz_zfpz_sql ||v_ids;
247 
248 
249    v_zfzxz_zfpz_sql :=v_zfzxz_zfpz_sql||'  group  by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.bdgt_accid,z.prjno,z.zf_itemno    order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.bdgt_accid,z.prjno,z.zf_itemno  ';
250 
251    open cursor_zfzxz_zfpz for v_zfzxz_zfpz_sql ;
252    fetch cursor_zfzxz_zfpz   into  v_row_zfzxz_zfpz;
253    while cursor_zfzxz_zfpz%found loop
254 
255             /*赋值*/
256             v_sum_amt  :=0;
257             v_sum_zf_item_amt  :=0;
258             v_sum_zfpz_amt  :=0;
259             v_list_gk_zfpz_id  :='';
260             v_list_id    :='';
261             v_list_origin_id  :='';
262             v_list_voucher_no  :='';
263             v_list_purpose  :='';
264             v_list_remark  :='';
265             v_list_bm_itemnos :='';
266 
267             /*取出合并的金额、凭证id列表、 */
268              v_gb_zfzxz_sql :='  select  sum(z.amt) as sum_amt ,sum(z.zf_item_amt) as sum_zf_item_amt , sum(z.zfpz_amt) as sum_zfpz_amt ,
269                                   listagg(z.gk_zfpz_id,'','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_gk_zfpz_id   ,
270                                   listagg(z.id, '','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_id   ,
271                                   listagg(z.origin_id, '','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_origin_id   ,
272                                   listagg(z.voucher_no, '','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_voucher_no   ,
273                                   listagg(z.purpose, '','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_purpose  ,
274                                   listagg(z.remark, '','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_remark  ,
275                                   listagg(z.bm_itemnos, '','') within group(order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno ) as  list_bm_itemnos
276                                   from view_k3_zfzxz_zfpz z where 1=1  ' ;
277 
278 
279              v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||v_ids;
280 
281              if v_row_zfzxz_zfpz.unitno is not null then
282                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.unitno='||v_row_zfzxz_zfpz.unitno  ;
283              end if  ;
284              if v_row_zfzxz_zfpz.prjno is not null then
285                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.prjno='||v_row_zfzxz_zfpz.prjno  ;
286              end if  ;
287              if v_row_zfzxz_zfpz.src_id is not null then
288                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.src_id='||v_row_zfzxz_zfpz.src_id  ;
289              end if;
290              if v_row_zfzxz_zfpz.budget_type is not null then
291                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.budget_type='||v_row_zfzxz_zfpz.budget_type  ;
292              end if;
293              if v_row_zfzxz_zfpz.budgetno is not null then
294                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.budgetno='||v_row_zfzxz_zfpz.budgetno  ;
295              end if;
296              if v_row_zfzxz_zfpz.zf_itemno is not null then
297                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.zf_itemno='||v_row_zfzxz_zfpz.zf_itemno  ;
298              end if;
299              /*取出合并的同单位 同资金来源 同项目编码 同功能分类科目类型 同功能分类科目编码 同政府经济分类编码 的金额求和 值 */
300              open cursor_gb_zfzxz for v_gb_zfzxz_sql ;
301              fetch cursor_gb_zfzxz   into  v_row_gb_zfzxz;
302              while cursor_gb_zfzxz%found loop
303                 /*赋值*/
304                 if v_row_gb_zfzxz.sum_amt is not null then
305                   v_sum_amt  :=v_row_gb_zfzxz.sum_amt;
306                 end if;
307                 if v_row_gb_zfzxz.sum_zf_item_amt is not null then
308                   v_sum_zf_item_amt  :=v_row_gb_zfzxz.sum_zf_item_amt;
309                 end if;
310                 if v_row_gb_zfzxz.sum_zfpz_amt is not null then
311                   v_sum_zfpz_amt  :=v_row_gb_zfzxz.sum_zfpz_amt;
312                 end if ;
313                 if v_row_gb_zfzxz.list_gk_zfpz_id is not null then
314                   v_list_gk_zfpz_id  :=v_row_gb_zfzxz.list_gk_zfpz_id;
315                 end if;
316                 if v_row_gb_zfzxz.list_id is not null then
317                   v_list_id    :=v_row_gb_zfzxz.list_id;
318                 end if ;
319                 if v_row_gb_zfzxz.list_origin_id is not null then
320                   v_list_origin_id  :=v_row_gb_zfzxz.list_origin_id;
321                 end if ;
322                 if v_row_gb_zfzxz.list_purpose is not null then
323                   v_list_voucher_no  :=v_row_gb_zfzxz.list_purpose;
324                 end if;
325                 if v_row_gb_zfzxz.list_purpose is not null then
326                   v_list_purpose  :=v_row_gb_zfzxz.list_purpose;
327                 end if;
328                 if  v_row_gb_zfzxz.list_remark is not  null then
329                   v_list_remark  :=v_row_gb_zfzxz.list_remark;
330                 end if;
331                 if   v_row_gb_zfzxz.list_bm_itemnos is not null then
332                   v_list_bm_itemnos :=v_row_gb_zfzxz.list_bm_itemnos;
333                 end if;
334 
335              fetch cursor_gb_zfzxz   into  v_row_gb_zfzxz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
336              exit when cursor_gb_zfzxz%notfound or cursor_gb_zfzxz%notfound is null;
337              end loop;
338 
339              v_q_vk3_zfzxzzfpz_sql :='select  gk_zfpz_id, id, origin_id, voucher_no, make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name, 
340                                       budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer,
341                                       affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date,
342                                       back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos
343                                       from  view_k3_zfzxz_zfpz z where 1=1   ';                                                        
344 
345              v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||v_ids;
346              if v_row_zfzxz_zfpz.unitno is not null then
347                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.unitno='||v_row_zfzxz_zfpz.unitno  ;
348              end if  ;
349              if v_row_zfzxz_zfpz.prjno is not null then
350                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.prjno='||v_row_zfzxz_zfpz.prjno  ;
351              end if  ;
352              if v_row_zfzxz_zfpz.src_id is not null then
353                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.src_id='||v_row_zfzxz_zfpz.src_id  ;
354              end if;
355              if v_row_zfzxz_zfpz.budget_type is not null then
356                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.budget_type='||v_row_zfzxz_zfpz.budget_type  ;
357              end if;
358              if v_row_zfzxz_zfpz.budgetno is not null then
359                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.budgetno='||v_row_zfzxz_zfpz.budgetno  ;
360              end if;
361              if v_row_zfzxz_zfpz.zf_itemno is not null then
362                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.zf_itemno='||v_row_zfzxz_zfpz.zf_itemno  ;
363              end if;
364              dbms_output.put_line('====进行PRO_K3_ZFZXZ 调试  GK_ZWVCH_ZFZXZ_ZFPZ_IDS 批次号   v_q_vk3_zfzxzzfpz_sql='|| v_q_vk3_zfzxzzfpz_sql||'==== ' );
365 
366 
367              v_q_vk3_zfzxzzfpz_count_sql:=  'select count(*) count_no    from  view_k3_zfzxz_zfpz z where 1=1   '  || v_ids
368                || '  and  z.unitno='||v_row_zfzxz_zfpz.unitno ||   '  and  z.prjno='||v_row_zfzxz_zfpz.prjno
369                ||   '  and  z.src_id='||v_row_zfzxz_zfpz.src_id ||   '  and  z.budget_type='||v_row_zfzxz_zfpz.budget_type
370                ||   '  and  z.budgetno='||v_row_zfzxz_zfpz.budgetno   ||   '  and  z.zf_itemno='||v_row_zfzxz_zfpz.zf_itemno  ;
371              v_rowcount:=0;
372              open cursor_q_vk3_zfzxzzfpz_count for v_q_vk3_zfzxzzfpz_count_sql ;
373              fetch cursor_q_vk3_zfzxzzfpz_count   into  v_row_q_vk3_zfzxzzfpz_count;
374 
375              while cursor_q_vk3_zfzxzzfpz_count%found loop
376                v_rowcount:=v_row_q_vk3_zfzxzzfpz_count.count_no;
377 
378              fetch cursor_q_vk3_zfzxzzfpz_count   into  v_row_q_vk3_zfzxzzfpz_count;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
379              exit when cursor_q_vk3_zfzxzzfpz_count%notfound or cursor_q_vk3_zfzxzzfpz_count%notfound is null;
380              end loop;
381 
382 
383 
384 
385 
386              /*取出 view_k3_zfzxz_zfpz 视图中的数据   */
387              open cursor_q_vk3_zfzxzzfpz for v_q_vk3_zfzxzzfpz_sql ;
388              fetch cursor_q_vk3_zfzxzzfpz   into  v_row_q_vk3_zfzxzzfpz;
389               while cursor_q_vk3_zfzxzzfpz%found loop
390                   /*判断游标查询结果为几行数据,如果是1行数据,就直接插入临时表中,如果是大于1行的数据集,则取出第一条数据插入 临时表中 */
391                  if  v_rowcount = 1 then
392 
393                       dbms_output.put_line('====  v_rowcount = 1 ==== ' );
394                       insert into gk_zwentry_k3_zfzxz_zfpz_temp
395                          (gk_zfpz_id, id, origin_id, voucher_no, make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name, budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer, affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date, back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos)
396                       values
397                            (v_row_q_vk3_zfzxzzfpz.gk_zfpz_id, v_row_q_vk3_zfzxzzfpz.id, v_row_q_vk3_zfzxzzfpz.origin_id, v_row_q_vk3_zfzxzzfpz.voucher_no, v_row_q_vk3_zfzxzzfpz.make_date, v_row_q_vk3_zfzxzzfpz.fk_account, v_row_q_vk3_zfzxzzfpz.fk_bank, v_row_q_vk3_zfzxzzfpz.src_id, v_row_q_vk3_zfzxzzfpz.sk_name, v_row_q_vk3_zfzxzzfpz.sk_account, v_row_q_vk3_zfzxzzfpz.sk_bank, v_row_q_vk3_zfzxzzfpz.unitno, v_row_q_vk3_zfzxzzfpz.unit_name, v_row_q_vk3_zfzxzzfpz.budget_type, v_row_q_vk3_zfzxzzfpz.bdgt_accid, v_row_q_vk3_zfzxzzfpz.budgetno, v_row_q_vk3_zfzxzzfpz.budget_name, v_row_q_vk3_zfzxzzfpz.prjno, v_row_q_vk3_zfzxzzfpz.prj_name, v_row_q_vk3_zfzxzzfpz.zfpz_amt, v_row_q_vk3_zfzxzzfpz.amt, v_row_q_vk3_zfzxzzfpz.purpose, v_row_q_vk3_zfzxzzfpz.remark, v_row_q_vk3_zfzxzzfpz.checker, v_row_q_vk3_zfzxzzfpz.checker_date, v_row_q_vk3_zfzxzzfpz.affirmer, v_row_q_vk3_zfzxzzfpz.affirm_date, v_row_q_vk3_zfzxzzfpz.voucher_type, v_row_q_vk3_zfzxzzfpz.check_status, v_row_q_vk3_zfzxzzfpz.wf_status, v_row_q_vk3_zfzxzzfpz.gk_hzqsd_id, v_row_q_vk3_zfzxzzfpz.fund, v_row_q_vk3_zfzxzzfpz.org_type, v_row_q_vk3_zfzxzzfpz.back_oper_id, v_row_q_vk3_zfzxzzfpz.back_oper_idea, v_row_q_vk3_zfzxzzfpz.back_oper_date, v_row_q_vk3_zfzxzzfpz.back_checker_id, v_row_q_vk3_zfzxzzfpz.back_checker_idea, v_row_q_vk3_zfzxzzfpz.back_checker_date, v_row_q_vk3_zfzxzzfpz.zf_item_amt, v_row_q_vk3_zfzxzzfpz.zf_itemno, v_row_q_vk3_zfzxzzfpz.zf_itemname, v_row_q_vk3_zfzxzzfpz.bm_itemnos);
398 
399 
400                  elsif  v_rowcount > 1 then
401 
402                        dbms_output.put_line('====  v_rowcount > 1 ==== ' );
403 
404 						           insert into gk_zwentry_k3_zfzxz_zfpz_temp
405                             (gk_zfpz_id, id, origin_id, voucher_no, make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name, budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer, affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date, back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos)
406                        values
407                             (v_list_gk_zfpz_id,v_list_id, v_list_origin_id, v_list_voucher_no, v_row_q_vk3_zfzxzzfpz.make_date, v_row_q_vk3_zfzxzzfpz.fk_account, v_row_q_vk3_zfzxzzfpz.fk_bank, v_row_q_vk3_zfzxzzfpz.src_id, v_row_q_vk3_zfzxzzfpz.sk_name, v_row_q_vk3_zfzxzzfpz.sk_account, v_row_q_vk3_zfzxzzfpz.sk_bank, v_row_q_vk3_zfzxzzfpz.unitno, v_row_q_vk3_zfzxzzfpz.unit_name, v_row_q_vk3_zfzxzzfpz.budget_type, v_row_q_vk3_zfzxzzfpz.bdgt_accid, v_row_q_vk3_zfzxzzfpz.budgetno, v_row_q_vk3_zfzxzzfpz.budget_name, v_row_q_vk3_zfzxzzfpz.prjno, v_row_q_vk3_zfzxzzfpz.prj_name,v_sum_zfpz_amt, v_sum_amt,v_list_purpose, v_list_remark , v_row_q_vk3_zfzxzzfpz.checker, v_row_q_vk3_zfzxzzfpz.checker_date, v_row_q_vk3_zfzxzzfpz.affirmer, v_row_q_vk3_zfzxzzfpz.affirm_date, v_row_q_vk3_zfzxzzfpz.voucher_type, v_row_q_vk3_zfzxzzfpz.check_status, v_row_q_vk3_zfzxzzfpz.wf_status, v_row_q_vk3_zfzxzzfpz.gk_hzqsd_id, v_row_q_vk3_zfzxzzfpz.fund, v_row_q_vk3_zfzxzzfpz.org_type, v_row_q_vk3_zfzxzzfpz.back_oper_id, v_row_q_vk3_zfzxzzfpz.back_oper_idea, v_row_q_vk3_zfzxzzfpz.back_oper_date, v_row_q_vk3_zfzxzzfpz.back_checker_id, v_row_q_vk3_zfzxzzfpz.back_checker_idea, v_row_q_vk3_zfzxzzfpz.back_checker_date, v_sum_zf_item_amt, v_row_q_vk3_zfzxzzfpz.zf_itemno, v_row_q_vk3_zfzxzzfpz.zf_itemname, v_list_bm_itemnos );
408 
409                     EXIT;/*跳出本循环体 ,继续执行上一级循环体 */
410                  end if;
411 
412              fetch cursor_q_vk3_zfzxzzfpz   into  v_row_q_vk3_zfzxzzfpz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
413              exit when cursor_q_vk3_zfzxzzfpz%notfound or cursor_q_vk3_zfzxzzfpz%notfound is null;
414              end loop;
415 
416 
417               dbms_output.put_line('====进行PRO_K3_ZFZXZ 调试  GK_ZWVCH_ZFZXZ_ZFPZ_IDS 批次号   v_sql='|| v_sql||'==== ' );
418 
419         fetch cursor_zfzxz_zfpz   into  v_row_zfzxz_zfpz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
420         exit when cursor_zfzxz_zfpz%notfound or cursor_zfzxz_zfpz%notfound is null;
421     end loop;
422 
423 
424  end if; /*结束 gk_zfpz表id 的拼接 情况的判断 */
425 
426 
427  v_sql :=   ' select *   from  gk_zwentry_k3_zfzxz_zfpz_temp  z     ';
428 dbms_output.put_line('==== v_sql='|| v_sql||'==== ' );
429 
430 
431 OPEN v_cur FOR v_sql;
432 
433 commit;
434 
435 close  cursor_q_vk3_zfzxzzfpz;/*关闭游标*/
436 close  cursor_gb_zfzxz;/*关闭游标*/
437 close  cursor_zfzxz_zfpz;/*关闭游标*/
438 close  cursor_ids;/*关闭游标*/
439 end PRO_K3_ZFZXZ;
440 

 

  1 create or replace procedure PRO_K3_ZFZXZ_6(
  2         org_type  in varchar2,
  3         opertype  in varchar2,
  4         fdate   in varchar2,
  5         v_cur  out pkg_query.cur_query   )
  6 is
  7   type ref_cursor_type is ref cursor;
  8   v_sql VARCHAR2(4000);
  9 
 10 
 11 
 12   /* 获取分组数据信息 */
 13   cursor_zfzxz_zfpz  ref_cursor_type;  /*游标*/
 14   v_row_zfzxz_zfpz view_k3_zfzxz_zfpz_group%rowtype  ;
 15   v_zfzxz_zfpz_sql  varchar2(4000) :='';
 16 
 17   /** 分组求和  **/
 18   cursor_gb_zfzxz ref_cursor_type; /*游标*/
 19   v_gb_zfzxz_sql varchar2(4000) :='';
 20   v_row_gb_zfzxz gk_zwentry_k3_zfzxz_zfpz_sum%rowtype  ;
 21 
 22   v_sum_amt number(16,2) :=0;
 23   v_sum_zf_item_amt number(16,2) :=0;
 24   v_sum_zfpz_amt number(16,2) :=0;
 25 
 26 
 27 
 28   /*查询 view_k3_zfzxz_zfpz 的具体信息 */
 29   cursor_q_vk3_zfzxzzfpz ref_cursor_type; /*游标*/
 30   v_q_vk3_zfzxzzfpz_sql  varchar2(4000) :='' ;
 31   v_row_q_vk3_zfzxzzfpz view_k3_zfzxz_zfpz%rowtype  ;
 32 
 33 
 34   /*查询 view_k3_zfzxz_zfpz 的具体有多少条数据信息*/
 35   cursor_q_vk3_zfzxzzfpz_count ref_cursor_type; /*游标*/
 36   v_row_q_vk3_zfzxzzfpz_count view_k3_zfzxz_zfpz_count%rowtype  ;
 37   v_q_vk3_zfzxzzfpz_count_sql  varchar2(4000) :='' ;
 38   v_rowcount number :=0;/*获取游标取数的条数*/
 39 
 40   v_zfpzId_sql varchar2(1000) :='';
 41 
 42   v_gk_zwvch_refer_temp_pch number :=0;
 43   v_pch number :=0;/*批次号*/
 44 
 45 begin
 46 dbms_output.enable (buffer_size=>null) ;
 47 
 48   select nextid('GK_ZWVCH_REFER_TEMP_SEQ')  as v_gk_zwvch_refer_temp_pch  into v_gk_zwvch_refer_temp_pch  from dual;
 49   if sql%found then
 50       v_pch :=v_gk_zwvch_refer_temp_pch;
 51   end if;
 52 
 53 
 54 --先判断入参是否有值,如果没有值 整个存储过程返回空值  
 55 --  if  org_type is not null and opertype is not null and  fdate is not null  then
 56       /*   org_type  资金来源类型 0 预算内  1预算外
 57            opertype   操作类型 0' :'正常对碰的直接支付' 1 '正常对碰的授权支付' 2 :'退款的直接支付' 3 :'退款的授权支付' 4 :'已审结的调账申请'
 58            fdate   凭证回单日期  */
 59 
 60          if org_type= '1'  /*预算外*/  then
 61 
 62       if opertype = '0' then
 63          --正常对碰的直接支付
 64          v_zfpzId_sql:= 'and   z.id in  (  select gz.id  from gk_zfpz gz,bs_zjly zjly  where gz.voucher_type =''''0'''' and gz.check_status in ( ''1'',''2'',''02'' ) and gz.src_id=zjly.fundno
 65 
 66                            and zjly.fundno in(''043'', ''058'', ''158'', ''258'', ''013'',  ''113'', ''213'',  ''023'',''123'',''223'',   ''046'',''246'',''049'',''149'',''249'',''048'', ''248'',''045'',''245'',''047'',''247'',  ''055'',''355'',''455'',''155'',''255'', ''059'', ''159'', ''259'', ''061'', ''161'',''261'',  ''026'', ''044'',''144'', ''244'' )
 67                            and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id       and r.fmodule = ''2'' and r.voucher_type=''0'' and r.orign_type=''1''   )
 68                            and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
 69 
 70       elsif opertype = '1' then
 71         --正常对碰的授权支付
 72            v_zfpzId_sql:= 'and     z.id in   (   select gz.id  from gk_zfpz gz,bs_zjly zjly  where gz.voucher_type =''1'' and gz.check_status in ( ''1'',''2'',''02'' ) and gz.src_id=zjly.fundno
 73                            and zjly.fundno in(''043'', ''058'', ''158'', ''258'', ''013'',  ''113'', ''213'',  ''023'',''123'',''223'',   ''046'',''246'',''049'',''149'',''249'',''048'', ''248'',''045'',''245'',''047'',''247'',  ''055'',''355'',''455'',''155'',''255'', ''059'', ''159'', ''259'', ''061'', ''161'',''261'',  ''026'', ''044'',''144'', ''244'' )
 74                            and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id     and r.fmodule = ''2'' and r.voucher_type=''1'' and r.orign_type=''1''  )
 75                            and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
 76 
 77       elsif opertype = '2' then
 78         --全额退款的直接支付
 79          v_zfpzId_sql:= 'and     z.id in   (     select  gz.id from gk_zfpz gz,bs_zjly zjly    where gz.voucher_type =''''0'''' and gz.check_status in (''2'')  and gz.src_id=zjly.fundno
 80                          and zjly.fundno in( ''043'',''058'', ''158'', ''258'', ''013'',  ''113'', ''213'',  ''023'',''123'',''223'',   ''046'',''246'',''049'',''149'',''249'',''048'', ''248'',''045'',''245'',''047'',''247'',  ''055'',''355'',''455'',''155'',''255'', ''059'', ''159'', ''259'', ''061'', ''161'',''261'',  ''026'', ''044'',''144'', ''244'' )
 81                          and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id   and r.fmodule = ''2'' and r.voucher_type=''0'' and r.orign_type=''3''   )
 82                          and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
 83 
 84       elsif opertype = '3' then
 85        -- 全额退款的授权支付
 86          v_zfpzId_sql:= 'and     z.id in   (     select  gz.id  from gk_zfpz gz,bs_zjly zjly  where gz.voucher_type =''1'' and gz.check_status =''2'' and gz.src_id=zjly.fundno
 87                         and zjly.fundno in( ''043'',''058'', ''158'', ''258'', ''013'',  ''113'', ''213'',  ''023'',''123'',''223'',   ''046'',''246'',''049'',''149'',''249'',''048'', ''248'',''045'',''245'',''047'',''247'',  ''055'',''355'',''455'',''155'',''255'', ''059'', ''159'', ''259'', ''061'', ''161'',''261'',  ''026'', ''044'',''144'', ''244'' )
 88                         and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id    and r.fmodule = ''2'' and r.voucher_type=''1'' and r.orign_type=''3'' )
 89                         and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
 90 
 91       end if;
 92 
 93     elsif  org_type= '0' /*预算内 */ then
 94       /*   org_type  资金来源类型 0 预算内  1预算外
 95            opertype   操作类型 0'' :''正常对碰的直接支付'' 1 ''正常对碰的授权支付'' 2 :''退款的直接支付'' 3 :''退款的授权支付'' 4 :''已审结的调账申请''
 96            fdate   凭证回单日期  */
 97       if opertype = 0 then
 98         --正常对碰的直接支付
 99           v_zfpzId_sql:= 'and     z.id in   (
100                           select gz.id  from gk_zfpz gz,bs_zjly zjly
101                           where gz.voucher_type =''0'' and gz.check_status in ( ''1'',''2'',''02'' ) and gz.src_id=zjly.fundno and zjly.org_type=1  and zjly.fundno not  in (''007'',''107'',''207'')
102                           and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id    and r.fmodule = ''1'' and r.voucher_type=''0'' and r.orign_type=''1''  )
103                           and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
104 
105       elsif opertype = '1' then
106         -- 正常对碰的授权支付
107           v_zfpzId_sql:= 'and     z.id in   (
108                           select gz.id  from gk_zfpz gz,bs_zjly zjly
109                           where gz.voucher_type =''0'' and gz.check_status in ( ''1'',''2'',''02'' ) and gz.src_id=zjly.fundno and zjly.org_type=1  and zjly.fundno not  in (''007'',''107'',''207'')
110                           and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id    and r.fmodule = ''1'' and r.voucher_type=''0'' and r.orign_type=''1''  )
111                           and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
112 
113         elsif opertype = '2' then
114         -- 全额退款的直接支付
115          v_zfpzId_sql:= 'and     z.id in   (
116                          select gz.id   from gk_zfpz gz,bs_zjly zjly     where gz.voucher_type =''0''   and gz.check_status =''2'' and gz.src_id=zjly.fundno and zjly.org_type=1   and zjly.fundno not  in (''007'',''107'',''207'')
117                          and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id  and r.fmodule = ''1'' and r.voucher_type=''0'' and r.orign_type=''3''  )
118                          and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
119 
120        elsif opertype = '3' then
121         ---全额退款的授权支付
122         v_zfpzId_sql:= 'and     z.id in   (
123                         select   gz.id   from gk_zfpz gz,bs_zjly zjly  where gz.voucher_type =''1'' and gz.check_status =''2'' and gz.src_id=zjly.fundno and zjly.org_type=1  and zjly.fundno not  in (''007'',''107'',''207'')
124                         and not exists (select r.* from gk_zwvch_refer r where r.origin_teable =''GK_ZFPZ'' and r.orign_id = gz.id    and r.fmodule = ''1'' and r.voucher_type=''1'' and r.orign_type=''3''   )
125                         and  to_char(gz.affirm_date,''yyyy-MM-dd'') = '''||fdate||'''   ) '   ;
126          end if;
127 
128      end if;
129 
130     /*获取视图 view_k3_zfzxz_zfpz 的 同单位 同资金来源 同项目 同功能分类科目类型 同功能分类科目编码 同政府经济分类编码 的数据 */
131     v_zfzxz_zfpz_sql :=' select  z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.zf_itemno     from  view_k3_zfzxz_zfpz z where 1=1   ';
132 
133 
134 
135    v_zfzxz_zfpz_sql :=v_zfzxz_zfpz_sql||v_zfpzId_sql  ||'  group  by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.bdgt_accid,z.prjno,z.zf_itemno    order by z.unitno,z.prjno,z.src_id,z.budget_type,z.budgetno,z.bdgt_accid,z.prjno,z.zf_itemno  ';
136 
137    open cursor_zfzxz_zfpz for v_zfzxz_zfpz_sql ;
138    fetch cursor_zfzxz_zfpz   into  v_row_zfzxz_zfpz;
139    while cursor_zfzxz_zfpz%found loop
140 
141             /*赋值*/
142             v_sum_amt  :=0;
143             v_sum_zf_item_amt  :=0;
144             v_sum_zfpz_amt  :=0;
145 
146 
147 
148             /*取出合并的金额、凭证id列表、 */
149              v_gb_zfzxz_sql :='  select  sum(z.amt) as sum_amt ,sum(z.zf_item_amt) as sum_zf_item_amt , sum(z.zfpz_amt) as sum_zfpz_amt  from view_k3_zfzxz_zfpz z where 1=1  ' ;
150 
151 
152              v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||v_zfpzId_sql ;
153 
154              if v_row_zfzxz_zfpz.unitno is not null then
155                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.unitno='||v_row_zfzxz_zfpz.unitno  ;
156              end if  ;
157              if v_row_zfzxz_zfpz.prjno is not null then
158                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.prjno='||v_row_zfzxz_zfpz.prjno  ;
159              end if  ;
160              if v_row_zfzxz_zfpz.src_id is not null then
161                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.src_id='||v_row_zfzxz_zfpz.src_id  ;
162              end if;
163              if v_row_zfzxz_zfpz.budget_type is not null then
164                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.budget_type='||v_row_zfzxz_zfpz.budget_type  ;
165              end if;
166              if v_row_zfzxz_zfpz.budgetno is not null then
167                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.budgetno='||v_row_zfzxz_zfpz.budgetno  ;
168              end if;
169              if v_row_zfzxz_zfpz.zf_itemno is not null then
170                  v_gb_zfzxz_sql :=v_gb_zfzxz_sql ||   '  and  z.zf_itemno='||v_row_zfzxz_zfpz.zf_itemno  ;
171              end if;
172              /*取出合并的同单位 同资金来源 同项目编码 同功能分类科目类型 同功能分类科目编码 同政府经济分类编码 的金额求和 值 */
173              dbms_output.put_line('====进行PRO_K3_ZFZXZ 调试 v_gb_zfzxz_sql   v_gb_zfzxz_sql='|| v_gb_zfzxz_sql||'==== ' );
174              open cursor_gb_zfzxz for v_gb_zfzxz_sql ;
175              fetch cursor_gb_zfzxz   into  v_row_gb_zfzxz;
176              while cursor_gb_zfzxz%found loop
177                 /*赋值*/
178                 if v_row_gb_zfzxz.sum_amt is not null then
179                   v_sum_amt  :=v_row_gb_zfzxz.sum_amt;
180                 end if;
181                 if v_row_gb_zfzxz.sum_zf_item_amt is not null then
182                   v_sum_zf_item_amt  :=v_row_gb_zfzxz.sum_zf_item_amt;
183                 end if;
184                 if v_row_gb_zfzxz.sum_zfpz_amt is not null then
185                   v_sum_zfpz_amt  :=v_row_gb_zfzxz.sum_zfpz_amt;
186                 end if ;
187 
188 
189              fetch cursor_gb_zfzxz   into  v_row_gb_zfzxz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
190              exit when cursor_gb_zfzxz%notfound or cursor_gb_zfzxz%notfound is null;
191              end loop;
192              close  cursor_gb_zfzxz;/*关闭游标*/
193 
194              v_q_vk3_zfzxzzfpz_sql :='select  gk_zfpz_id, id, origin_id, voucher_no, make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name,
195                                       budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer,
196                                       affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date,
197                                       back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos
198                                       from  view_k3_zfzxz_zfpz z where 1=1   ';
199 
200              v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||v_zfpzId_sql ;
201              if v_row_zfzxz_zfpz.unitno is not null then
202                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.unitno='||v_row_zfzxz_zfpz.unitno  ;
203              end if  ;
204              if v_row_zfzxz_zfpz.prjno is not null then
205                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.prjno='||v_row_zfzxz_zfpz.prjno  ;
206              end if  ;
207              if v_row_zfzxz_zfpz.src_id is not null then
208                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.src_id='||v_row_zfzxz_zfpz.src_id  ;
209              end if;
210              if v_row_zfzxz_zfpz.budget_type is not null then
211                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.budget_type='||v_row_zfzxz_zfpz.budget_type  ;
212              end if;
213              if v_row_zfzxz_zfpz.budgetno is not null then
214                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.budgetno='||v_row_zfzxz_zfpz.budgetno  ;
215              end if;
216              if v_row_zfzxz_zfpz.zf_itemno is not null then
217                  v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||   '  and  z.zf_itemno='||v_row_zfzxz_zfpz.zf_itemno  ;
218              end if;
219 
220 
221              v_q_vk3_zfzxzzfpz_count_sql:=  'select count(*) count_no    from  view_k3_zfzxz_zfpz z where 1=1   '  || v_zfpzId_sql  ;
222 
223              if v_row_zfzxz_zfpz.unitno is not null then
224                  v_q_vk3_zfzxzzfpz_count_sql :=v_q_vk3_zfzxzzfpz_count_sql ||   '  and  z.unitno='||v_row_zfzxz_zfpz.unitno  ;
225              end if  ;
226              if v_row_zfzxz_zfpz.prjno is not null then
227                  v_q_vk3_zfzxzzfpz_count_sql :=v_q_vk3_zfzxzzfpz_count_sql ||   '  and  z.prjno='||v_row_zfzxz_zfpz.prjno  ;
228              end if  ;
229              if v_row_zfzxz_zfpz.src_id is not null then
230                  v_q_vk3_zfzxzzfpz_count_sql :=v_q_vk3_zfzxzzfpz_count_sql ||   '  and  z.src_id='||v_row_zfzxz_zfpz.src_id  ;
231              end if;
232              if v_row_zfzxz_zfpz.budget_type is not null then
233                  v_q_vk3_zfzxzzfpz_count_sql :=v_q_vk3_zfzxzzfpz_count_sql ||   '  and  z.budget_type='||v_row_zfzxz_zfpz.budget_type  ;
234              end if;
235              if v_row_zfzxz_zfpz.budgetno is not null then
236                  v_q_vk3_zfzxzzfpz_count_sql :=v_q_vk3_zfzxzzfpz_count_sql ||   '  and  z.budgetno='||v_row_zfzxz_zfpz.budgetno  ;
237              end if;
238              if v_row_zfzxz_zfpz.zf_itemno is not null then
239                  v_q_vk3_zfzxzzfpz_count_sql :=v_q_vk3_zfzxzzfpz_count_sql ||   '  and  z.zf_itemno='||v_row_zfzxz_zfpz.zf_itemno  ;
240              end if;
241 
242               v_rowcount:=0;
243               dbms_output.put_line('====进行   v_q_vk3_zfzxzzfpz_count_sql='|| v_q_vk3_zfzxzzfpz_count_sql||'==== ' );
244              open cursor_q_vk3_zfzxzzfpz_count for v_q_vk3_zfzxzzfpz_count_sql ;
245 
246              fetch cursor_q_vk3_zfzxzzfpz_count   into  v_row_q_vk3_zfzxzzfpz_count;
247 
248              while cursor_q_vk3_zfzxzzfpz_count%found loop
249                v_rowcount:=v_row_q_vk3_zfzxzzfpz_count.count_no;
250 
251              fetch cursor_q_vk3_zfzxzzfpz_count   into  v_row_q_vk3_zfzxzzfpz_count;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
252              exit when cursor_q_vk3_zfzxzzfpz_count%notfound or cursor_q_vk3_zfzxzzfpz_count%notfound is null;
253              end loop;
254 
255 
256 
257 
258 
259              /*取出 view_k3_zfzxz_zfpz 视图中的数据   */
260              open cursor_q_vk3_zfzxzzfpz for v_q_vk3_zfzxzzfpz_sql ;
261              fetch cursor_q_vk3_zfzxzzfpz   into  v_row_q_vk3_zfzxzzfpz;
262               while cursor_q_vk3_zfzxzzfpz%found loop
263                   /*判断游标查询结果为几行数据,如果是1行数据,就直接插入临时表中,如果是大于1行的数据集,则取出第一条数据插入 临时表中 */
264                  if  v_rowcount = 1 then
265 
266 
267                         insert into gk_zwentry_k3_zfzxz_zfpz_temp
268                          (  gk_zwvch_refer_temp_pch,  gk_zfpz_id, make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name, budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer, affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date, back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos)
269                       values
270                            ( v_pch, v_row_q_vk3_zfzxzzfpz.gk_zfpz_id, v_row_q_vk3_zfzxzzfpz.make_date, v_row_q_vk3_zfzxzzfpz.fk_account, v_row_q_vk3_zfzxzzfpz.fk_bank, v_row_q_vk3_zfzxzzfpz.src_id, v_row_q_vk3_zfzxzzfpz.sk_name, v_row_q_vk3_zfzxzzfpz.sk_account, v_row_q_vk3_zfzxzzfpz.sk_bank, v_row_q_vk3_zfzxzzfpz.unitno, v_row_q_vk3_zfzxzzfpz.unit_name, v_row_q_vk3_zfzxzzfpz.budget_type, v_row_q_vk3_zfzxzzfpz.bdgt_accid, v_row_q_vk3_zfzxzzfpz.budgetno, v_row_q_vk3_zfzxzzfpz.budget_name, v_row_q_vk3_zfzxzzfpz.prjno, v_row_q_vk3_zfzxzzfpz.prj_name, v_row_q_vk3_zfzxzzfpz.zfpz_amt, v_row_q_vk3_zfzxzzfpz.amt, v_row_q_vk3_zfzxzzfpz.purpose, v_row_q_vk3_zfzxzzfpz.remark, v_row_q_vk3_zfzxzzfpz.checker, v_row_q_vk3_zfzxzzfpz.checker_date, v_row_q_vk3_zfzxzzfpz.affirmer, v_row_q_vk3_zfzxzzfpz.affirm_date, v_row_q_vk3_zfzxzzfpz.voucher_type, v_row_q_vk3_zfzxzzfpz.check_status, v_row_q_vk3_zfzxzzfpz.wf_status, v_row_q_vk3_zfzxzzfpz.gk_hzqsd_id, v_row_q_vk3_zfzxzzfpz.fund, v_row_q_vk3_zfzxzzfpz.org_type, v_row_q_vk3_zfzxzzfpz.back_oper_id, v_row_q_vk3_zfzxzzfpz.back_oper_idea, v_row_q_vk3_zfzxzzfpz.back_oper_date, v_row_q_vk3_zfzxzzfpz.back_checker_id, v_row_q_vk3_zfzxzzfpz.back_checker_idea, v_row_q_vk3_zfzxzzfpz.back_checker_date, v_row_q_vk3_zfzxzzfpz.zf_item_amt, v_row_q_vk3_zfzxzzfpz.zf_itemno, v_row_q_vk3_zfzxzzfpz.zf_itemname, v_row_q_vk3_zfzxzzfpz.bm_itemnos);
271 
272                  elsif  v_rowcount > 1 then
273 
274 
275                        insert into gk_zwentry_k3_zfzxz_zfpz_temp
276                             (gk_zwvch_refer_temp_pch,  gk_zfpz_id,  make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name, budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer, affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date, back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos)
277                        values
278                             ( v_pch, v_row_q_vk3_zfzxzzfpz.gk_zfpz_id,v_row_q_vk3_zfzxzzfpz.make_date, v_row_q_vk3_zfzxzzfpz.fk_account, v_row_q_vk3_zfzxzzfpz.fk_bank, v_row_q_vk3_zfzxzzfpz.src_id, v_row_q_vk3_zfzxzzfpz.sk_name, v_row_q_vk3_zfzxzzfpz.sk_account, v_row_q_vk3_zfzxzzfpz.sk_bank, v_row_q_vk3_zfzxzzfpz.unitno, v_row_q_vk3_zfzxzzfpz.unit_name, v_row_q_vk3_zfzxzzfpz.budget_type, v_row_q_vk3_zfzxzzfpz.bdgt_accid, v_row_q_vk3_zfzxzzfpz.budgetno, v_row_q_vk3_zfzxzzfpz.budget_name, v_row_q_vk3_zfzxzzfpz.prjno, v_row_q_vk3_zfzxzzfpz.prj_name,v_sum_zfpz_amt, v_sum_amt,v_row_q_vk3_zfzxzzfpz.purpose, v_row_q_vk3_zfzxzzfpz.remark, v_row_q_vk3_zfzxzzfpz.checker, v_row_q_vk3_zfzxzzfpz.checker_date, v_row_q_vk3_zfzxzzfpz.affirmer, v_row_q_vk3_zfzxzzfpz.affirm_date, v_row_q_vk3_zfzxzzfpz.voucher_type, v_row_q_vk3_zfzxzzfpz.check_status, v_row_q_vk3_zfzxzzfpz.wf_status, v_row_q_vk3_zfzxzzfpz.gk_hzqsd_id, v_row_q_vk3_zfzxzzfpz.fund, v_row_q_vk3_zfzxzzfpz.org_type, v_row_q_vk3_zfzxzzfpz.back_oper_id, v_row_q_vk3_zfzxzzfpz.back_oper_idea, v_row_q_vk3_zfzxzzfpz.back_oper_date, v_row_q_vk3_zfzxzzfpz.back_checker_id, v_row_q_vk3_zfzxzzfpz.back_checker_idea, v_row_q_vk3_zfzxzzfpz.back_checker_date, v_sum_zf_item_amt, v_row_q_vk3_zfzxzzfpz.zf_itemno, v_row_q_vk3_zfzxzzfpz.zf_itemname, v_row_q_vk3_zfzxzzfpz.bm_itemnos );
279 
280                     EXIT;/*跳出本循环体 ,继续执行上一级循环体 */
281                  end if;
282 
283              fetch cursor_q_vk3_zfzxzzfpz   into  v_row_q_vk3_zfzxzzfpz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
284              exit when cursor_q_vk3_zfzxzzfpz%notfound or cursor_q_vk3_zfzxzzfpz%notfound is null;
285              end loop;
286 
287            -- close  cursor_q_vk3_zfzxzzfpz;/*关闭游标*/
288 
289 
290 
291         fetch cursor_zfzxz_zfpz   into  v_row_zfzxz_zfpz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
292         exit when cursor_zfzxz_zfpz%notfound or cursor_zfzxz_zfpz%notfound is null;
293     end loop;
294    -- close  cursor_zfzxz_zfpz;/*关闭游标*/
295 
296       /*GK_ZWVCH_REFER_TEMP 表中插入数据 */
297 
298 
299 
300      v_q_vk3_zfzxzzfpz_sql :='select  gk_zfpz_id, id, origin_id, voucher_no, make_date, fk_account, fk_bank, src_id, sk_name, sk_account, sk_bank, unitno, unit_name,
301                                       budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name, zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer,
302                                       affirm_date, voucher_type, check_status, wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date,
303                                       back_checker_id, back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos
304                                       from  view_k3_zfzxz_zfpz z where 1=1    ';
305 
306      v_q_vk3_zfzxzzfpz_sql :=v_q_vk3_zfzxzzfpz_sql ||v_zfpzId_sql ;
307        /*取出 view_k3_zfzxz_zfpz 视图中的数据   */
308      open cursor_q_vk3_zfzxzzfpz for v_q_vk3_zfzxzzfpz_sql ;
309      fetch cursor_q_vk3_zfzxzzfpz   into  v_row_q_vk3_zfzxzzfpz;
310       while cursor_q_vk3_zfzxzzfpz%found loop
311 
312             insert into gk_zwvch_refer_temp
313               (pch, zfpz_id, zfpz_amt, bm_itemno, zf_itemno, zf_itemname, itemno_amt)
314             values
315               (v_pch, v_row_q_vk3_zfzxzzfpz.gk_zfpz_id,v_row_q_vk3_zfzxzzfpz.zfpz_amt  ,v_row_q_vk3_zfzxzzfpz.bm_itemnos  ,v_row_q_vk3_zfzxzzfpz.zf_itemno ,v_row_q_vk3_zfzxzzfpz.zf_itemname  ,v_row_q_vk3_zfzxzzfpz.zf_item_amt  );
316 
317       fetch cursor_q_vk3_zfzxzzfpz   into  v_row_q_vk3_zfzxzzfpz;/*先让指针指向结果集中的第一行,并将值保存到v_row_zfzxz_zfpz 中*/
318       exit when cursor_q_vk3_zfzxzzfpz%notfound or cursor_q_vk3_zfzxzzfpz%notfound is null;
319       end loop;
320     --  close  cursor_q_vk3_zfzxzzfpz;\*关闭游标*\
321 
322 
323 --end if;
324 
325  v_sql :=' select gk_zwvch_refer_temp_pch as pch,  gk_zfpz_id, make_date, fk_account, fk_bank, src_id, sk_name,
326               sk_account, sk_bank, unitno, unit_name, budget_type, bdgt_accid, budgetno, budget_name, prjno, prj_name,
327               zfpz_amt, amt, purpose, remark, checker, checker_date, affirmer, affirm_date, voucher_type, check_status,
328               wf_status, gk_hzqsd_id, fund, org_type, back_oper_id, back_oper_idea, back_oper_date, back_checker_id,
329               back_checker_idea, back_checker_date, zf_item_amt, zf_itemno, zf_itemname, bm_itemnos
330             from  gk_zwentry_k3_zfzxz_zfpz_temp  z     ';
331 
332 OPEN v_cur FOR v_sql;
333 
334 
335 
336 
337      close  cursor_q_vk3_zfzxzzfpz_count;/*关闭游标*/
338      close  cursor_q_vk3_zfzxzzfpz;/*关闭游标*/
339      close  cursor_zfzxz_zfpz;/*关闭游标*/
340     commit;
341 end PRO_K3_ZFZXZ_6;
342 

 

 

 

 示例10: 批量创建oracle 自带的 sequence 序列号

---SELECT GK_ZCJH_SEQ.NEXTVAL FROM DUAL ;
 
-- select  create_seq_func('GK_ZCJH_SEQ','gk_ykjh','id')   from dual;


 

CREATE OR REPLACE PACKAGE PKG_QUERY IS

  -- Author  : ADMINISTRATOR
  -- Created : 2016/12/8 星期四 10:28:37
  -- Purpose : 用做查询游标

  -- Public type declarations
  TYPE CUR_QUERY IS REF CURSOR;

END PKG_QUERY;


create or replace function create_seq_func(
   seq_name in  varchar2 ,/*seq名称*/
   bus_table_name in varchar2,/*业务表名*/
   pkcloumn_name in varchar2/*业务表主键名*/
)
return varchar2
is
result varchar2(30000);
type ref_cursor_type is ref cursor;
cursor_ids  ref_cursor_type;      
cursor_ids_1  ref_cursor_type; 
  
v_max_seq number :=1;
v_max_seq_1 number :=1;

v_max_sql varchar(4000);
v_max_sql_1 varchar(4000);

v_sql_alter varchar(4000);
v_sequence_sql varchar(4000);
begin

    v_max_sql:='select  '||seq_name||'.NEXTVAL FROM DUAL  ';
    dbms_output.put_line(v_max_sql);
    open cursor_ids for v_max_sql ;
    fetch cursor_ids   into  v_max_seq;
    /**  判断 是否有id 值查询出来  */
    if cursor_ids%found    then
       while cursor_ids%found loop
          dbms_output.put_line(v_max_seq);
       fetch cursor_ids   into  v_max_seq;
       end loop; 
    end if;
    
    v_max_sql_1:='select to_number(max('||pkcloumn_name||')+100)   from '||bus_table_name||' t   ';
    dbms_output.put_line(v_max_sql_1);
    open cursor_ids_1 for v_max_sql_1 ;
    fetch cursor_ids_1   into  v_max_seq_1;
    /**  判断 是否有id 值查询出来  */
    if cursor_ids_1%found    then
       while cursor_ids_1%found loop
          dbms_output.put_line(v_max_seq_1);
       fetch cursor_ids_1   into  v_max_seq_1;
     --   exit when cursor_ids%notfound or cursor_ids%notfound is null ;
       end loop;
    end if;
    v_sql_alter :='ALTER SEQUENCE GK_ZCJH_SEQ INCREMENT BY '|| v_max_seq_1;
    dbms_output.put_line(v_sql_alter);
    execute immediate v_sql_alter;


return  v_max_seq;
EXCEPTION
  WHEN OTHERS THEN
    v_sequence_sql :='create sequence '||seq_name||' minvalue  1 maxvalue 9999999999999999999999999999 start with  1 increment by 1 cache 20';
    dbms_output.put_line(v_sequence_sql);
    execute immediate v_sequence_sql;   

    v_max_sql_1:='select to_number(max('||pkcloumn_name||')+100)   from '||bus_table_name||' t   ';
    dbms_output.put_line(v_max_sql_1);
    open cursor_ids_1 for v_max_sql_1 ;
    fetch cursor_ids_1   into  v_max_seq_1;
    /**  判断 是否有id 值查询出来  */
    if cursor_ids_1%found    then
       while cursor_ids_1%found loop
          dbms_output.put_line(v_max_seq_1);
       fetch cursor_ids_1   into  v_max_seq_1;
     --   exit when cursor_ids%notfound or cursor_ids%notfound is null ;
       end loop;
    end if;
    v_sql_alter :='ALTER SEQUENCE GK_ZCJH_SEQ INCREMENT BY '|| v_max_seq_1;
    dbms_output.put_line(v_sql_alter);
    execute immediate v_sql_alter;

    
    RETURN v_max_seq_1;
end;

 

 

 

 

 

 

 

 

 

 

 

 

 

——————————————————————————————————————————————————————————————————————————————————————————————

posted @ 2018-04-09 19:26  一品堂.技术学习笔记  阅读(770)  评论(1编辑  收藏  举报