Skip to content

Instantly share code, notes, and snippets.

@garymanley
Created April 26, 2022 18:44
Show Gist options
  • Save garymanley/80e4bd4f890e68054a0d35a90208d5dd to your computer and use it in GitHub Desktop.
Save garymanley/80e4bd4f890e68054a0d35a90208d5dd to your computer and use it in GitHub Desktop.
create or replace procedure p_run_control(p_csl_id number) returns number
language sql as
declare
v_sql varchar2(2000);
v_year_month number(6);
begin
select period into v_year_month from KEBOOLA_7127.WORKSPACE_15661914.CURRENT_PERIOD cp ;
select sql_text into v_sql from KEBOOLA_7127.WORKSPACE_15661914.ICE_CONTROL_SOURCE_LINK where csl_id = :p_csl_id;
v_sql := 'INSERT INTO KEBOOLA_7127.WORKSPACE_15661914.ICE_AMOUNT(year_month,csl_id,amount) select ' || v_year_month || ' , ' || p_csl_id || ' , amount FROM (' || v_sql || ' ) x ' ;
execute immediate v_sql;
exception
when other then insert into KEBOOLA_7127.WORKSPACE_15661914.ICE_CONTROL_ERROR(icsl_id, year_month)
values(:p_csl_id,:v_year_month) ;
end ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment