思路:定义一个程序包,然后在视图 以及在查询视图时,分别使用 get set 方法来实现视图的传参。
案例视图
创建视图
1 2 3 4 5 6 7 8
CREATE OR REPLACE VIEW TEST AS SELECT * FROM (SELECT '1' ID,'AAA' VALUE FROM DUAL UNION SELECT '2','BBB' FROM DUAL UNION SELECT '3','CCC' FROM DUAL) WHERE ID = P_VIEW_PARAM.get_paramStr1();
查询方式
1
SELECT * FROM TEST WHERE P_VIEW_PARAM.set_paramStr1('1')='1'
create or replace PACKAGE "P_VIEW_PARAM" is --获取财务月起始日期和截止日期 function set_dateFrom(dateStr varchar2) return varchar2; function get_dateFrom return date; function set_dateTo(dateStr varchar2) return varchar2; function get_dateTo return date; function set_ndateFrom(dateStr varchar2) return varchar2; function get_ndateFrom return date; function set_ndateTo(dateStr varchar2) return varchar2; function get_ndateTo return date; --2020-12-25 function set_timestampFrom(dateStr varchar2) return varchar2; function get_timestampFrom return Timestamp; function set_timestampTo(dateStr varchar2) return varchar2; function get_timestampTo return Timestamp; --2020-12-25 --2020-12-28 function set_ndateFrom1(dateStr varchar2) return varchar2; function get_ndateFrom1 return date; function set_ndateTo1(dateStr varchar2) return varchar2; function get_ndateTo1 return date; function set_ndateFrom2(dateStr varchar2) return varchar2; function get_ndateFrom2 return date; function set_ndateTo2(dateStr varchar2) return varchar2; function get_ndateTo2 return date; function set_ndateFrom3(dateStr varchar2) return varchar2; function get_ndateFrom3 return date; function set_ndateTo3(dateStr varchar2) return varchar2; function get_ndateTo3 return date; function set_ndateFrom4(dateStr varchar2) return varchar2; function get_ndateFrom4 return date; function set_ndateTo4(dateStr varchar2) return varchar2; function get_ndateTo4 return date; function set_ndateFrom5(dateStr varchar2) return varchar2; function get_ndateFrom5 return date; function set_ndateTo5(dateStr varchar2) return varchar2; function get_ndateTo5 return date; function get_month(dateStr varchar2) return varchar2;--返回日期归属的财务月 function set_paramStr1(paramStr varchar2) return varchar2; function get_paramStr1 return varchar2; --参数1 function set_paramStr2(paramStr varchar2) return varchar2; function get_paramStr2 return varchar2; --参数2 function set_paramStr3(paramStr varchar2) return varchar2; function get_paramStr3 return varchar2; --参数3 function set_paramStr4(paramStr varchar2) return varchar2; function get_paramStr4 return varchar2; --参数4 function set_paramStr5(paramStr varchar2) return varchar2; function get_paramStr5 return varchar2; --参数5 function set_paramStr6(paramStr varchar2) return varchar2; function get_paramStr6 return varchar2; --参数6 function set_paramStr7(paramStr varchar2) return varchar2; function get_paramStr7 return varchar2; --参数7 function set_paramStr8(paramStr varchar2) return varchar2; function get_paramStr8 return varchar2; --参数8 function set_paramStr9(paramStr varchar2) return varchar2; function get_paramStr9 return varchar2; --参数9 function set_paramStr10(paramStr varchar2) return varchar2; function get_paramStr10 return varchar2; --参数10 function set_paramStr11(paramStr varchar2) return varchar2; function get_paramStr11 return varchar2; --参数11 function set_paramStr12(paramStr varchar2) return varchar2; function get_paramStr12 return varchar2; --参数12 end p_view_param;
create or replace PACKAGE BODY "P_VIEW_PARAM" is dateFrom date;--财务月起始日期 dateTo date;--财务月截止日期 ndateFrom date;--起始日期 ndateTo date;--截止日期 --2020-12-25 timestampFrom timestamp;--起始日期 timestampTo timestamp;--截止日期 --2020-12-25 --2020-12-28 ndateFrom1 date;--起始日期 ndateTo1 date;--截止日期 ndateFrom2 date;--起始日期 ndateTo2 date;--截止日期 ndateFrom3 date;--起始日期 ndateTo3 date;--截止日期 ndateFrom4 date;--起始日期 ndateTo4 date;--截止日期 ndateFrom5 date;--起始日期 ndateTo5 date;--截止日期 --2020-12-28 monthStr varchar2(10);--返回日期归属的财务月 paramStr1 varchar2(500);--参数1 paramStr2 varchar2(500);--参数2 paramStr3 varchar2(500);--参数3 paramStr4 varchar2(500);--参数4 paramStr5 varchar2(500);--参数5 paramStr6 varchar2(500);--参数6 paramStr7 varchar2(500);--参数7 paramStr8 varchar2(500);--参数8 paramStr9 varchar2(500);--参数9 paramStr10 varchar2(500);--参数10 paramStr11 varchar2(500);--参数11 paramStr12 varchar2(500);--参数12 function get_month(dateStr varchar2) return varchar2 is begin SELECT to_char(fy)||decode(length(to_char(period)),1,'0'||to_char(period),to_char(period)) into monthStr FROM DA_CLNDR where to_char(clndr_date,'yyyy/mm/dd')=dateStr; return monthStr; end; function set_dateFrom(dateStr varchar2) return varchar2 is begin --select (SELECT PD_BEGIN FROM DA_CLNDR DA WHERE da.clndr_date=to_date(dateStr||'/10','yyyy/mm/dd')) INTO dateFrom FROM DUAL; select pd_begin INTO dateFrom from da_clndr where fy=substr(datestr,1,4) and period=substr(datestr,6, 2) and rownum=1 ; return dateStr; end; function get_dateFrom return date is begin return dateFrom; end; function set_dateTo(dateStr varchar2) return varchar2 is begin --select (SELECT PD_END FROM DA_CLNDR DA WHERE da.clndr_date=to_date(dateStr||'/10','yyyy/mm/dd')) INTO dateTo FROM DUAL; select pd_end INTO dateTo from da_clndr where fy=substr(datestr,1,4) and period=substr(datestr,6, 2) and rownum=1; return dateStr; end; function get_dateTo return date is begin return dateTo; end; function set_ndateFrom(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateFrom FROM DUAL; return dateStr; end; function get_ndateFrom return date is begin return ndateFrom; end; function set_ndateTo(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateTo FROM DUAL; return dateStr; end; function get_ndateTo return date is begin return ndateTo; end; --2020-12-28 function set_ndateFrom1(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateFrom1 FROM DUAL; return dateStr; end; function get_ndateFrom1 return date is begin return ndateFrom1; end; function set_ndateTo1(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateTo1 FROM DUAL; return dateStr; end; function get_ndateTo1 return date is begin return ndateTo1; end; function set_ndateFrom2(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateFrom2 FROM DUAL; return dateStr; end; function get_ndateFrom2 return date is begin return ndateFrom2; end; function set_ndateTo2(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateTo2 FROM DUAL; return dateStr; end; function get_ndateTo2 return date is begin return ndateTo2; end; function set_ndateFrom3(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateFrom3 FROM DUAL; return dateStr; end; function get_ndateFrom3 return date is begin return ndateFrom3; end; function set_ndateTo3(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateTo3 FROM DUAL; return dateStr; end; function get_ndateTo3 return date is begin return ndateTo3; end; function set_ndateFrom4(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateFrom4 FROM DUAL; return dateStr; end; function get_ndateFrom4 return date is begin return ndateFrom4; end; function set_ndateTo4(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateTo4 FROM DUAL; return dateStr; end; function get_ndateTo4 return date is begin return ndateTo4; end; function set_ndateFrom5(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateFrom5 FROM DUAL; return dateStr; end; function get_ndateFrom5 return date is begin return ndateFrom5; end; function set_ndateTo5(dateStr varchar2) return varchar2 is begin select to_date(dateStr,'yyyy/mm/dd') INTO ndateTo5 FROM DUAL; return dateStr; end; function get_ndateTo5 return date is begin return ndateTo5; end; --2020-12-25 function set_timestampFrom(dateStr varchar2) return varchar2 is begin select to_timestamp(dateStr,'yyyy-mm-dd hh24:mi:ss:ff3') INTO timestampFrom FROM DUAL; return dateStr; end; function get_timestampFrom return timestamp is begin return timestampFrom; end; function set_timestampTo(dateStr varchar2) return varchar2 is begin select to_timestamp(dateStr,'yyyy-mm-dd hh24:mi:ss:ff3') INTO timestampTo FROM DUAL; return dateStr; end; function get_timestampTo return timestamp is begin return timestampTo; end; --2020-12-25 function set_paramStr1(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr1 FROM DUAL; return paramStr; end; function get_paramStr1 return varchar2 is begin return paramStr1; end; function set_paramStr2(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr2 FROM DUAL; return paramStr; end; function get_paramStr2 return varchar2 is begin return paramStr2; end; function set_paramStr3(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr3 FROM DUAL; return paramStr; end; function get_paramStr3 return varchar2 is begin return paramStr3; end; function set_paramStr4(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr4 FROM DUAL; return paramStr; end; function get_paramStr4 return varchar2 is begin return paramStr4; end; function set_paramStr5(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr5 FROM DUAL; return paramStr; end; function get_paramStr5 return varchar2 is begin return paramStr5; end; function set_paramStr6(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr6 FROM DUAL; return paramStr; end; function get_paramStr6 return varchar2 is begin return paramStr6; end; function set_paramStr7(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr7 FROM DUAL; return paramStr; end; function get_paramStr7 return varchar2 is begin return paramStr7; end; function set_paramStr8(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr8 FROM DUAL; return paramStr; end; function get_paramStr8 return varchar2 is begin return paramStr8; end; --2021-01-20 function set_paramStr9(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr9 FROM DUAL; return paramStr; end; function get_paramStr9 return varchar2 is begin return paramStr9; end; function set_paramStr10(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr10 FROM DUAL; return paramStr; end; function get_paramStr10 return varchar2 is begin return paramStr10; end; function set_paramStr11(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr11 FROM DUAL; return paramStr; end; function get_paramStr11 return varchar2 is begin return paramStr11; end; function set_paramStr12(paramStr varchar2) return varchar2 is begin select paramStr INTO paramStr12 FROM DUAL; return paramStr; end; function get_paramStr12 return varchar2 is begin return paramStr12; end; end p_view_param;