drop function if exists mmt_staging2.fn_DBOECD_RUN; CREATE OR REPLACE FUNCTION mmt_staging2.fn_DBOECD_RUN() RETURNS void AS $$ declare f record; w_file_syspk int; status text; begin for f in select distinct a.file_syspk from mmt_staging1.mmt_staging_generic_table a where file_format = 'DBOECD' order by file_syspk loop select f.file_syspk into w_file_syspk; perform mmt_staging2.fn_dboecd_test_block(1,2,'DBOECD','DBOECD_TEST',w_file_syspk); select e.status from mmt_staging2.mmt_DB_Run_Status e where file_syspk = w_file_syspk and sheet_mnemonic ='DBOECD_TEST' into status; if status = 'success' then perform mmt_ods.fn_dboecd_test_ods(w_file_syspk); end if; end loop; end; $$ LANGUAGE plpgsql; --select mmt_staging2.fn_DBOECD_RUN()