Не уверен, почему вы объявляете Varchar
для хранения даты. Используйте переменную DATE
для хранения даты, как показано ниже:
Таблица:
CREATE TABLE st_dti_mbr_stg
( col NUMBER,rec_lst_updt_dttm TIMESTAMP
);
SELECT * FROM st_dti_mbr_stg;
INSERT INTO st_dti_mbr_stg VALUES (1,sysdate );
INSERT INTO st_dti_mbr_stg VALUES (1,sysdate-60 );
Процедура:
create or replace PROCEDURE REC_PURGE
(
pInterfaceName IN VARCHAR2,
pInterfaceRunDate IN DATE,-- VARCHAR2, --<-- Use Date variable
PARAM_CLEANUP_DAYS IN NUMBER,
pErrorCd OUT NUMBER
)
AS
--************************************************************************************************************
--** DECLARE LOCAL VARIABLES **
--************************************************************************************************************/
LV_CLEANUP_DAYS NUMBER := 366;
-- LV_SP_RUN_DT VARCHAR2(19) := pInterfaceRunDate;
LV_SP_RUN_DT DATE := pInterfaceRunDate;
--lv_interdaceRunDate TIMESTAMP := TO_DATE(pInterfaceRunDate,'MM/DD/YYYY');
BEGIN
IF PARAM_CLEANUP_DAYS IS NOT NULL
THEN
LV_CLEANUP_DAYS := PARAM_CLEANUP_DAYS;
END IF;
dbms_output.put_line(LV_SP_RUN_DT || ' '||LV_CLEANUP_DAYS);
DELETE /*+ PARALLEL(16) */
from ST_DTI_MBR_STG
where trunc(rec_lst_updt_dttm) <= LV_SP_RUN_DT - LV_CLEANUP_DAYS;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
pErrorCd:= SQLCODE;
-- pErrorMsg := 'Failure at step ';-- || TO_CHAR(lvCurrentStep, '99.90') || ' with the message: ' || SQLCODE || '-' || SQLERRM;
END REC_PURGE;
Выполнение;
DECLARE
PINTERFACENAME VARCHAR2(200);
PINTERFACERUNDATE DATE ;--VARCHAR2(19);
PARAM_CLEANUP_RANGE NUMBER;
PERRORCD NUMBER;
BEGIN
PINTERFACENAME :='REC';
PINTERFACERUNDATE :=to_Date('03/18/2020','MM/DD/YYYY');
PARAM_CLEANUP_RANGE := 30;
REC_PURGE(
pInterfaceName => PINTERFACENAME,
pInterfaceRunDate => PINTERFACERUNDATE,
PARAM_CLEANUP_DAYS => PARAM_CLEANUP_RANGE, --<- You messed up argument name
pErrorCd => PERRORCD
);
PERRORCD := PERRORCD;
END;