--1.创建一个package,包中定义两个方法,一个set值的方法,一个get值的方法
create or replace package VIEW_GET_PRODUCT_YGS is
--set值方法
function set_writeday(writeday varchar2) return varchar2;
--get值方法
function get_writeday return varchar2;
end VIEW_GET_PRODUCT_YGS;
--2.创建package body,实现package中的两个方法
create or replace package body VIEW_GET_PRODUCT_YGS is
paramValue varchar2(32);
-- 给paramValue赋值
function set_writeday(writeday varchar2) return varchar2 is
begin
paramValue := writeday;
return writeday;
end;
--返回paramValue 的值
function get_writeday return varchar2 is
begin
return paramValue;
end;
end VIEW_GET_PRODUCT_YGS;
--3.创建带参数视图 VIEW_GET_PRODUCT_YGS.get_writeday()是从方法中获取传入的参数
Create view VIEW_GET_PRODUCT_YGS_BTN
AS
SELECT YGS,Productid FROM (select NVL( TA.TIME_USED*TA.PNOXS,0) AS YGS,TA.Productid,TA.writeday
,row_number() over(partition by TA.Productid order by TA.writeday desc) FPX
from
WORKUNIT_SALARY TA --获取不同年数据视图
WHERE TO_CHAR(TA.writeday,'YYYY') <VIEW_GET_PRODUCT_YGS.get_writeday()
) TB WHERE TB.FPX=1;
Create view VIEW_GET_PRODUCT_YGS_XTN
AS
SELECT YGS,Productid FROM (select NVL( TA.TIME_USED*TA.PNOXS,0) AS YGS,TA.Productid,TA.writeday
,row_number() over(partition by TA.Productid order by TA.writeday) FPX
from
WORKUNIT_SALARY TA --获取相同年数据视图
WHERE TO_CHAR(TA.writeday,'YYYYMM') <VIEW_GET_PRODUCT_YGS.get_writeday() and TO_CHAR(TA.writeday,'YYYY')=substr(VIEW_GET_PRODUCT_YGS.get_writeday(),0,4)
) TB WHERE TB.FPX=1;
select * from VIEW_GET_PRODUCT_YGS_BTN where VIEW_GET_PRODUCT_YGS.set_writeday('202001') ='202001' ;