存储过程传参使用技巧

1.当传的某个参数为空时,使其在sql的条件中不生效,该如何处理

当存储过程传参如:actual_number_create_exception(analyseDate in date,typeName in varchar2,comp3Code in varchar2)

  可做如下处理:AND ((comp3Code is not null and excf.excf_comp3_code=comp3Code) or (comp3Code is null and 0=0))
  这样便可以做到,传入的公司四位码,有时生效,没传时,不生效。

  注意:excf.excf_comp3_code是一个表的字段,没发全哦

2.当想批量传入参数时,也想做到,传入时生效,不传入时不生效,改如何处理

当存储过程传参如:proc_finance_inter_data_check1(area in varchar2,escoId in varchar2,comp3Code varchar2,lebapCode in varchar2,tebapCode in varchar2)

可做如下处理:and ((escoId is not null and esco.esco_id in (select column_value from table(strsplit(escoId,',')))) or (escoId is null and 0=0))
这样便可以做到,批量传入的公司id('1111,2222,3333,4444'),有传时生效,没传时,不生效。

  注意:esco.esco_id是一个表的字段,没发全哦

 

posted @ 2021-01-19 14:18  小胡666  阅读(885)  评论(0编辑  收藏  举报
39
0