create or
replace FUNCTION ecisdrdm.pr_mig_stg_application_cdim
(v_Ret OUT bigint )
as $$
declare
v_ErrorCode bigint;
v_ErrorMsg varchar(512);
v_Module varchar(32) =
'pr_mig_stg_application_cdim';
begin
----
-- MERGING:
STG_APPLICATION_CDIM into APPLICATION_CDIM
----
INSERT INTO
application_cdim AS prod (prod.application_id,
prod.receipt_number,prod.init_frm_id,
prod.frm_typ_id,
prod.sbmtd_dt_id,
prod.crtd_user_id, prod.init_src_sys_id,
prod.init_svc_ctr_id, prod.mig_filename)
SELECT
stg.application_id, stg.receipt_number,
stg.init_frm_id, stg.frm_typ_id, stg.sbmtd_dt_id,
stg.crtd_user_id,
stg.init_src_sys_id,
stg.init_svc_ctr_id, stg.mig_filename
FROM
ecisdrdm.stg_application stg
ON CONFLICT
(application_id) DO UPDATE
SET (
prod.init_frm_id, prod.frm_typ_id,prod. sbmtd_dt_id,
prod.crtd_user_id,
prod.init_src_sys_id,
prod.init_svc_ctr_id, prod.mig_filename,
prod.mig_modified_dt
)
=
(SELECT
stg.init_frm_id, stg.frm_typ_id, stg.sbmtd_dt_id,
stg.crtd_user_id,
stg.init_src_sys_id,
stg.init_svc_ctr_id, stg.mig_filename,
current_timestamp
FROM
ecisdrdm.stg_application_cdim stg
WHERE
prod.receipt_number = stg.receipt_number
);
RETURN;
----
-- Set the
return code to 0
----
v_Ret :=
SQLSTATE;
----
-- Exception
error handler
----
exception
when
others then
v_ErrorCode
:= SQLSTATE;
v_ErrorMsg
:= SQLERRM;
v_Ret
:= v_ErrorCode;
----
--
Commit the record into the ErrorLog
----
PERFORM
pr_write_error_log( v_os_user, v_host, v_module,
v_ErrorCode, v_ErrorMsg );
----
--
Intentionally leaving the "commit" to application
----
end;
$$ language
plpgsql;