815 lines
43 KiB
PL/PgSQL
815 lines
43 KiB
PL/PgSQL
CREATE OR REPLACE FUNCTION fw_ods_tli_load()
|
|
RETURNS text
|
|
LANGUAGE plpgsql
|
|
AS $function$
|
|
declare
|
|
|
|
_record record;
|
|
_query_string varchar;
|
|
_query_insert varchar;
|
|
_select_clause varchar;
|
|
_where_clause varchar;
|
|
_group_by_clause varchar;
|
|
_order_by_clause varchar;
|
|
_table_name varchar;
|
|
_search_quote varchar;
|
|
_fy_start_month int;
|
|
_open_brace varchar; --used to check whether the column contains aggregate functions.
|
|
|
|
_message_text varchar;
|
|
_returned_sqlstate varchar;
|
|
_error_message_text varchar;
|
|
|
|
|
|
begin
|
|
|
|
for _record in select * from fw_config_etl_mapping_tli
|
|
loop
|
|
|
|
_query_insert := '';
|
|
_select_clause := '';
|
|
_query_string := '';
|
|
_where_clause := '';
|
|
_order_by_clause := '';
|
|
_group_by_clause := ' group by ';
|
|
_search_quote := '''';
|
|
_fy_start_month := 4;
|
|
_table_name := _record.target_table_name;
|
|
_open_brace := '(';
|
|
|
|
_query_insert := 'insert into ' || _record.target_table_name || '(client_id, function_id';
|
|
_select_clause := 'select ' || _record.client_id || ' client_id, ' || _record.function_id || ' function_id';
|
|
|
|
_group_by_clause := _group_by_clause || 'client_id, function_id';
|
|
|
|
if (_record.d0l1_src_id_src_col is not null and _record.d0l1_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d0l1_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d0l1_src_id_src_col || ' d0l1_src_id';
|
|
if (position(_search_quote in _record.d0l1_src_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d0l1_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d0l2_src_id_src_col is not null and _record.d0l2_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d0l2_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d0l2_src_id_src_col || ' d0l2_src_id';
|
|
if (position(_search_quote in _record.d0l2_src_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d0l2_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.date_timestamp_src_col is not null and _record.date_timestamp_src_col != '') then
|
|
_query_insert := _query_insert || ', date_timestamp';
|
|
_select_clause := _select_clause || ', ' || _record.date_timestamp_src_col || ' date_timestamp';
|
|
_group_by_clause := _group_by_clause || ', ' || _record.date_timestamp_src_col;
|
|
end if;
|
|
|
|
if (_record.txna01_name_src_col is not null and _record.txna01_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna01_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna01_name_src_col || ' txna01_name';
|
|
if (position(_search_quote in _record.txna01_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna01_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna02_name_src_col is not null and _record.txna02_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna02_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna02_name_src_col || ' txna02_name';
|
|
if (position(_search_quote in _record.txna02_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna02_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna03_name_src_col is not null and _record.txna03_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna03_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna03_name_src_col || ' txna03_name';
|
|
if (position(_search_quote in _record.txna03_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna03_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna04_name_src_col is not null and _record.txna04_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna04_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna04_name_src_col || ' txna04_name';
|
|
if (position(_search_quote in _record.txna04_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna04_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna05_name_src_col is not null and _record.txna05_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna05_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna05_name_src_col || ' txna05_name';
|
|
if (position(_search_quote in _record.txna05_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna05_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna06_name_src_col is not null and _record.txna06_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna06_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna06_name_src_col || ' txna06_name';
|
|
if (position(_search_quote in _record.txna06_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna06_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna07_name_src_col is not null and _record.txna07_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna07_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna07_name_src_col || ' txna07_name';
|
|
if (position(_search_quote in _record.txna07_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna07_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna08_name_src_col is not null and _record.txna08_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna08_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna08_name_src_col || ' txna08_name';
|
|
if (position(_search_quote in _record.txna08_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna08_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna09_name_src_col is not null and _record.txna09_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna09_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna09_name_src_col || ' txna09_name';
|
|
if (position(_search_quote in _record.txna09_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna09_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.txna10_name_src_col is not null and _record.txna10_name_src_col != '') then
|
|
_query_insert := _query_insert || ', txna10_name';
|
|
_select_clause := _select_clause || ', ' || _record.txna10_name_src_col || ' txna10_name';
|
|
if (position(_search_quote in _record.txna10_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.txna10_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.tlia01_name_src_col is not null and _record.tlia01_name_src_col != '') then
|
|
_query_insert := _query_insert || ', tlia01_name';
|
|
_select_clause := _select_clause || ', ' || _record.tlia01_name_src_col || ' tlia01_name';
|
|
if (position(_search_quote in _record.tlia01_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.tlia01_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.tlia02_name_src_col is not null and _record.tlia02_name_src_col != '') then
|
|
_query_insert := _query_insert || ', tlia02_name';
|
|
_select_clause := _select_clause || ', ' || _record.tlia02_name_src_col || ' tlia02_name';
|
|
if (position(_search_quote in _record.tlia02_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.tlia02_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
|
|
|
|
|
|
---- dim d1 --------
|
|
if (_record.d1_unique_id_src_col is not null and _record.d1_unique_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1_unique_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1_unique_id_src_col || ' d1_unique_id';
|
|
if (position(_search_quote in _record.d1_unique_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1_unique_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1_src_id_src_col is not null and _record.d1_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1_src_id_src_col || ' d1_src_id';
|
|
if (position(_search_quote in _record.d1_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1_unique_id_name_src_col is not null and _record.d1_unique_id_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d1_unique_id_name';
|
|
_select_clause := _select_clause || ', ' || _record.d1_unique_id_name_src_col || ' d1_unique_id_name';
|
|
if (position(_search_quote in _record.d1_unique_id_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1_unique_id_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
|
|
|
|
if (_record.d1l01_id_src_col is not null and _record.d1l01_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l01_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l01_id_src_col || ' d1l01_id';
|
|
if (position(_search_quote in _record.d1l01_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l01_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l01_src_id_src_col is not null and _record.d1l01_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l01_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l01_src_id_src_col || ' d1l01_src_id';
|
|
if (position(_search_quote in _record.d1l01_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l01_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l01_name_src_col is not null and _record.d1l01_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l01_name';
|
|
_select_clause := _select_clause || ', ' || _record.d1l01_name_src_col || ' d1l01_name';
|
|
if (position(_search_quote in _record.d1l01_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l01_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l02_id_src_col is not null and _record.d1l02_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l02_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l02_id_src_col || ' d1l02_id';
|
|
if (position(_search_quote in _record.d1l02_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l02_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l02_src_id_src_col is not null and _record.d1l02_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l02_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l02_src_id_src_col || ' d1l02_src_id';
|
|
if (position(_search_quote in _record.d1l02_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l02_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l02_name_src_col is not null and _record.d1l02_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l02_name';
|
|
_select_clause := _select_clause || ', ' || _record.d1l02_name_src_col || ' d1l02_name';
|
|
if (position(_search_quote in _record.d1l02_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l02_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l03_id_src_col is not null and _record.d1l03_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l03_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l03_id_src_col || ' d1l03_id';
|
|
if (position(_search_quote in _record.d1l03_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l03_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l03_src_id_src_col is not null and _record.d1l03_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l03_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l03_src_id_src_col || ' d1l03_src_id';
|
|
if (position(_search_quote in _record.d1l03_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l03_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l03_name_src_col is not null and _record.d1l03_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l03_name';
|
|
_select_clause := _select_clause || ', ' || _record.d1l03_name_src_col || ' d1l03_name';
|
|
if (position(_search_quote in _record.d1l03_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l03_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l04_id_src_col is not null and _record.d1l04_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l04_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l04_id_src_col || ' d1l04_id';
|
|
if (position(_search_quote in _record.d1l04_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l04_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l04_src_id_src_col is not null and _record.d1l04_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l04_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l04_src_id_src_col || ' d1l04_src_id';
|
|
if (position(_search_quote in _record.d1l04_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l04_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l04_name_src_col is not null and _record.d1l04_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l04_name';
|
|
_select_clause := _select_clause || ', ' || _record.d1l04_name_src_col || ' d1l04_name';
|
|
if (position(_search_quote in _record.d1l04_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l04_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d1l05_id_src_col is not null and _record.d1l05_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l05_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l05_id_src_col || ' d1l05_id';
|
|
if (position(_search_quote in _record.d1l05_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l05_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l05_src_id_src_col is not null and _record.d1l05_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l05_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d1l05_src_id_src_col || ' d1l05_src_id';
|
|
if (position(_search_quote in _record.d1l05_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l05_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d1l05_name_src_col is not null and _record.d1l05_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d1l05_name';
|
|
_select_clause := _select_clause || ', ' || _record.d1l05_name_src_col || ' d1l05_name';
|
|
if (position(_search_quote in _record.d1l05_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d1l05_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
---- dim d2 --------
|
|
if (_record.d2_unique_id_src_col is not null and _record.d2_unique_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2_unique_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2_unique_id_src_col || ' d2_unique_id';
|
|
if (position(_search_quote in _record.d2_unique_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2_unique_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2_src_id_src_col is not null and _record.d2_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2_src_id_src_col || ' d2_src_id';
|
|
if (position(_search_quote in _record.d2_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2_unique_id_name_src_col is not null and _record.d2_unique_id_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d2_unique_id_name';
|
|
_select_clause := _select_clause || ', ' || _record.d2_unique_id_name_src_col || ' d2_unique_id_name';
|
|
if (position(_search_quote in _record.d2_unique_id_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2_unique_id_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d2l01_id_src_col is not null and _record.d2l01_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l01_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l01_id_src_col || ' d2l01_id';
|
|
if (position(_search_quote in _record.d2l01_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l01_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l01_src_id_src_col is not null and _record.d2l01_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l01_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l01_src_id_src_col || ' d2l01_src_id';
|
|
if (position(_search_quote in _record.d2l01_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l01_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l01_name_src_col is not null and _record.d2l01_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l01_name';
|
|
_select_clause := _select_clause || ', ' || _record.d2l01_name_src_col || ' d2l01_name';
|
|
if (position(_search_quote in _record.d2l01_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l01_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d2l02_id_src_col is not null and _record.d2l02_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l02_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l02_id_src_col || ' d2l02_id';
|
|
if (position(_search_quote in _record.d2l02_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l02_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l02_src_id_src_col is not null and _record.d2l02_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l02_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l02_src_id_src_col || ' d2l02_src_id';
|
|
if (position(_search_quote in _record.d2l02_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l02_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l02_name_src_col is not null and _record.d2l02_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l02_name';
|
|
_select_clause := _select_clause || ', ' || _record.d2l02_name_src_col || ' d2l02_name';
|
|
if (position(_search_quote in _record.d2l02_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l02_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d2l03_id_src_col is not null and _record.d2l03_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l03_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l03_id_src_col || ' d2l03_id';
|
|
if (position(_search_quote in _record.d2l03_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l03_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l03_src_id_src_col is not null and _record.d2l03_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l03_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l03_src_id_src_col || ' d2l03_src_id';
|
|
if (position(_search_quote in _record.d2l03_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l03_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l03_name_src_col is not null and _record.d2l03_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l03_name';
|
|
_select_clause := _select_clause || ', ' || _record.d2l03_name_src_col || ' d2l03_name';
|
|
if (position(_search_quote in _record.d2l03_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l03_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d2l04_id_src_col is not null and _record.d2l04_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l04_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l04_id_src_col || ' d2l04_id';
|
|
if (position(_search_quote in _record.d2l04_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l04_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l04_src_id_src_col is not null and _record.d2l04_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l04_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l04_src_id_src_col || ' d2l04_src_id';
|
|
if (position(_search_quote in _record.d2l04_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l04_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l04_name_src_col is not null and _record.d2l04_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l04_name';
|
|
_select_clause := _select_clause || ', ' || _record.d2l04_name_src_col || ' d2l04_name';
|
|
if (position(_search_quote in _record.d2l04_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l04_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d2l05_id_src_col is not null and _record.d2l05_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l05_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l05_id_src_col || ' d2l05_id';
|
|
if (position(_search_quote in _record.d2l05_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l05_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l05_src_id_src_col is not null and _record.d2l05_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l05_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d2l05_src_id_src_col || ' d2l05_src_id';
|
|
if (position(_search_quote in _record.d2l05_src_id_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l05_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d2l05_name_src_col is not null and _record.d2l05_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d2l05_name';
|
|
_select_clause := _select_clause || ', ' || _record.d2l05_name_src_col || ' d2l05_name';
|
|
if (position(_search_quote in _record.d2l05_name_src_col) = 0) then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d2l05_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
|
|
---- dim d3 --------
|
|
|
|
if (_record.d3_unique_id_src_col is not null and _record.d3_unique_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_unique_id';
|
|
_select_clause := _select_clause || ', ' || _record.d3_unique_id_src_col || ' d3_unique_id';
|
|
if (position(_search_quote in _record.d3_unique_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_unique_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_src_id_src_col is not null and _record.d3_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d3_src_id_src_col || ' d3_src_id';
|
|
if (position(_search_quote in _record.d3_src_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_unique_id_name_src_col is not null and _record.d3_unique_id_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_unique_id_name';
|
|
_select_clause := _select_clause || ', ' || _record.d3_unique_id_name_src_col || ' d3_unique_id_name';
|
|
if (position(_search_quote in _record.d3_unique_id_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_unique_id_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3a01_src_col is not null and _record.d3a01_src_col != '') then
|
|
_query_insert := _query_insert || ', d3a01';
|
|
_select_clause := _select_clause || ', ' || _record.d3a01_src_col || ' d3a01';
|
|
if (position(_search_quote in _record.d3a01_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3a01_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3a02_src_col is not null and _record.d3a02_src_col != '') then
|
|
_query_insert := _query_insert || ', d3a02';
|
|
_select_clause := _select_clause || ', ' || _record.d3a02_src_col || ' d3a02';
|
|
if (position(_search_quote in _record.d3a02_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3a02_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_geo_id_src_col is not null and _record.d3_geo_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_geo_id';
|
|
_select_clause := _select_clause || ', ' || _record.d3_geo_id_src_col || ' d3_geo_id';
|
|
if (position(_search_quote in _record.d3_geo_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_geo_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_country_src_col is not null and _record.d3_country_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_country';
|
|
_select_clause := _select_clause || ', ' || _record.d3_country_src_col || ' d3_country';
|
|
if (position(_search_quote in _record.d3_country_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_country_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_region_src_col is not null and _record.d3_region_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_region';
|
|
_select_clause := _select_clause || ', ' || _record.d3_region_src_col || ' d3_region';
|
|
if (position(_search_quote in _record.d3_region_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_region_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_state_src_col is not null and _record.d3_state_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_state';
|
|
_select_clause := _select_clause || ', ' || _record.d3_state_src_col || ' d3_state';
|
|
if (position(_search_quote in _record.d3_state_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_state_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_district_src_col is not null and _record.d3_district_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_district';
|
|
_select_clause := _select_clause || ', ' || _record.d3_district_src_col || ' d3_district';
|
|
if (position(_search_quote in _record.d3_district_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_district_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_city_town_src_col is not null and _record.d3_city_town_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_city_town';
|
|
_select_clause := _select_clause || ', ' || _record.d3_city_town_src_col || ' d3_city_town';
|
|
if (position(_search_quote in _record.d3_city_town_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_city_town_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_location_area_src_col is not null and _record.d3_location_area_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_location_area';
|
|
_select_clause := _select_clause || ', ' || _record.d3_location_area_src_col || ' d3_location_area';
|
|
if (position(_search_quote in _record.d3_location_area_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_location_area_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_zipcode_src_col is not null and _record.d3_zipcode_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_zipcode';
|
|
_select_clause := _select_clause || ', ' || _record.d3_zipcode_src_col || ' d3_zipcode';
|
|
if (position(_search_quote in _record.d3_zipcode_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_zipcode_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_locality_type_src_col is not null and _record.d3_locality_type_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_locality_type';
|
|
_select_clause := _select_clause || ', ' || _record.d3_locality_type_src_col || ' d3_locality_type';
|
|
if (position(_search_quote in _record.d3_locality_type_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_locality_type_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_latitude_src_col is not null and _record.d3_latitude_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_latitude_src_col';
|
|
_select_clause := _select_clause || ', ' || _record.d3_latitude_src_col || ' d3_latitude_src_col';
|
|
if (position(_search_quote in _record.d3_latitude_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_latitude_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d3_longitude_src_col is not null and _record.d3_longitude_src_col != '') then
|
|
_query_insert := _query_insert || ', d3_longitude';
|
|
_select_clause := _select_clause || ', ' || _record.d3_longitude_src_col || ' d3_longitude';
|
|
if (position(_search_quote in _record.d3_longitude_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d3_longitude_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
---- dim d4 --------
|
|
|
|
if (_record.d4_unique_id_src_col is not null and _record.d4_unique_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d4_unique_id';
|
|
_select_clause := _select_clause || ', ' || _record.d4_unique_id_src_col || ' d4_unique_id';
|
|
if (position(_search_quote in _record.d4_unique_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d4_unique_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d4_src_id_src_col is not null and _record.d4_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d4_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d4_src_id_src_col || ' d4_src_id';
|
|
if (position(_search_quote in _record.d4_src_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d4_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d4_unique_id_name_src_col is not null and _record.d4_unique_id_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d4_unique_id_name';
|
|
_select_clause := _select_clause || ', ' || _record.d4_unique_id_name_src_col || ' d4_unique_id_name';
|
|
if (position(_search_quote in _record.d4_unique_id_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d4_unique_id_name_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
if (_record.d4a02_src_col is not null and _record.d4a02_src_col != '') then
|
|
_query_insert := _query_insert || ', d4a02';
|
|
_select_clause := _select_clause || ', ' || _record.d4a02_src_col || ' d4a02';
|
|
if (position(_search_quote in _record.d4a02_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d4a02_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d4a03_src_col is not null and _record.d4a03_src_col != '') then
|
|
_query_insert := _query_insert || ', d4a03';
|
|
_select_clause := _select_clause || ', ' || _record.d4a03_src_col || ' d4a03';
|
|
if (position(_search_quote in _record.d4a03_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d4a03_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
---- dim d5 --------
|
|
|
|
if (_record.d5_unique_id_src_col is not null and _record.d5_unique_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d5_unique_id';
|
|
_select_clause := _select_clause || ', ' || _record.d5_unique_id_src_col || ' d5_unique_id';
|
|
if (position(_search_quote in _record.d5_unique_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d5_unique_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d5_src_id_src_col is not null and _record.d5_src_id_src_col != '') then
|
|
_query_insert := _query_insert || ', d5_src_id';
|
|
_select_clause := _select_clause || ', ' || _record.d5_src_id_src_col || ' d5_src_id';
|
|
if (position(_search_quote in _record.d5_src_id_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d5_src_id_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d5_unique_id_name_src_col is not null and _record.d5_unique_id_name_src_col != '') then
|
|
_query_insert := _query_insert || ', d5_unique_id_name';
|
|
_select_clause := _select_clause || ', ' || _record.d5_unique_id_name_src_col || ' d5_unique_id_name';
|
|
if (position(_search_quote in _record.d5_unique_id_name_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d5_unique_id_name_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d5a01_src_col is not null and _record.d5a01_src_col != '') then
|
|
_query_insert := _query_insert || ', d5a01';
|
|
_select_clause := _select_clause || ', ' || _record.d5a01_src_col || ' d5a01';
|
|
if (position(_search_quote in _record.d5a01_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d5a01_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d5a02_src_col is not null and _record.d5a02_src_col != '') then
|
|
_query_insert := _query_insert || ', d5a02';
|
|
_select_clause := _select_clause || ', ' || _record.d5a02_src_col || ' d5a02';
|
|
if (position(_search_quote in _record.d5a02_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d5a02_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.d5a03_src_col is not null and _record.d5a03_src_col != '') then
|
|
_query_insert := _query_insert || ', d5a03';
|
|
_select_clause := _select_clause || ', ' || _record.d5a03_src_col || ' d5a03';
|
|
if (position(_search_quote in _record.d5a03_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.d5a03_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
---- dim time --------
|
|
|
|
if (_record.date_timestamp_src_col is not null and _record.date_timestamp_src_col != '') then
|
|
_query_insert := _query_insert || ', time_hh';
|
|
_select_clause := _select_clause || ', ' || 'to_char(' || _record.date_timestamp_src_col || ',''HH24'')::int time_hh';
|
|
end if;
|
|
|
|
---- dim date --------
|
|
|
|
if (_record.date_timestamp_src_col is not null and _record.date_timestamp_src_col != '') then
|
|
_query_insert := _query_insert || ', date_field';
|
|
_query_insert := _query_insert || ', date_yyyy';
|
|
_query_insert := _query_insert || ', date_qq';
|
|
_query_insert := _query_insert || ', date_mm';
|
|
_query_insert := _query_insert || ', date_yyyymm';
|
|
_query_insert := _query_insert || ', date_ww';
|
|
_query_insert := _query_insert || ', date_dd';
|
|
_query_insert := _query_insert || ', date_fy_yyyy';
|
|
_query_insert := _query_insert || ', date_fy_qq';
|
|
_query_insert := _query_insert || ', date_fy_mm';
|
|
_query_insert := _query_insert || ', date_fy_yyyymm';
|
|
|
|
_query_insert := _query_insert || ', date_weekday';
|
|
_query_insert := _query_insert || ', date_weekend';
|
|
|
|
_select_clause := _select_clause || ', ' || 'date(' || _record.date_timestamp_src_col || ') date_field';
|
|
_select_clause := _select_clause || ', ' || 'date_part(''year''::text,' || _record.date_timestamp_src_col || ')::int date_yyyy';
|
|
_select_clause := _select_clause || ', ' || 'date_part(''quarter''::text,' || _record.date_timestamp_src_col || ')::int date_qq';
|
|
_select_clause := _select_clause || ', ' || 'date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int date_mm';
|
|
_select_clause := _select_clause || ', ' || 'to_char(' || _record.date_timestamp_src_col || ',''YYYYMM'')::int date_yyyymm';
|
|
_select_clause := _select_clause || ', ' || 'date_part(''week''::text,' || _record.date_timestamp_src_col || ')::int date_ww';
|
|
_select_clause := _select_clause || ', ' || 'date_part(''day''::text,' || _record.date_timestamp_src_col || ')::int date_dd';
|
|
|
|
_select_clause := _select_clause || ', case when ' || '(date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) >= ' || _fy_start_month;
|
|
_select_clause := _select_clause || ' then date_part(''year''::text,' || _record.date_timestamp_src_col || ')::int ';
|
|
_select_clause := _select_clause || ' else (date_part(''year''::text,' || _record.date_timestamp_src_col || ')::int) -1 end date_fy_yyyy';
|
|
|
|
_select_clause := _select_clause || ', case when ' || '(date_part(''quarter''::text,' || _record.date_timestamp_src_col || ')::int) in (2,3,4)';
|
|
_select_clause := _select_clause || ' then (date_part(''quarter''::text,' || _record.date_timestamp_src_col || ')::int) -1';
|
|
_select_clause := _select_clause || ' else (date_part(''quarter''::text,' || _record.date_timestamp_src_col || ')::int) +3 end date_fy_qq';
|
|
|
|
_select_clause := _select_clause || ', case when ' || '(date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) >= ' || _fy_start_month;
|
|
_select_clause := _select_clause || ' then (date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) -3';
|
|
_select_clause := _select_clause || ' else (date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) +9 end date_fy_mm';
|
|
|
|
_select_clause := _select_clause || ', case when ' || '(date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) >= ' || _fy_start_month;
|
|
_select_clause := _select_clause || ' then concat(date_part(''year''::text,' || _record.date_timestamp_src_col || '), lpad(((date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) -3)::text,2,''0''))';
|
|
_select_clause := _select_clause || ' else concat((date_part(''year''::text,' || _record.date_timestamp_src_col || ')::int) -1, (date_part(''month''::text,' || _record.date_timestamp_src_col || ')::int) +9) end::int date_fy_yyyymm';
|
|
|
|
|
|
_select_clause := _select_clause || ', ' || 'to_char(' || _record.date_timestamp_src_col || ',''dy'') date_weekday';
|
|
_select_clause := _select_clause || ', ' || 'case when extract(dow from ' || _record.date_timestamp_src_col || ') in (0,6)';
|
|
_select_clause := _select_clause || ' then ''Y'' else ''N'' end date_weekend';
|
|
end if;
|
|
|
|
if (_record.date_lunarmonth_src_col is not null and _record.date_lunarmonth_src_col != '') then
|
|
_query_insert := _query_insert || ', date_lunarmonth';
|
|
_select_clause := _select_clause || ', ' || _record.date_lunarmonth_src_col || ' date_lunarmonth';
|
|
end if;
|
|
if (_record.date_lunarday_src_col is not null and _record.date_lunarday_src_col != '') then
|
|
_query_insert := _query_insert || ', date_lunarday';
|
|
_select_clause := _select_clause || ', ' || _record.date_lunarday_src_col || ' date_lunarday';
|
|
end if;
|
|
if (_record.date_holiday_src_col is not null and _record.date_holiday_src_col != '') then
|
|
_query_insert := _query_insert || ', date_holiday';
|
|
_select_clause := _select_clause || ', ' || _record.date_holiday_src_col || ' date_holiday';
|
|
end if;
|
|
if (_record.date_festival_src_col is not null and _record.date_festival_src_col != '') then
|
|
_query_insert := _query_insert || ', date_festival';
|
|
_select_clause := _select_clause || ', ' || _record.date_festival_src_col || ' date_festival';
|
|
end if;
|
|
if (_record.date_special_src_col is not null and _record.date_special_src_col != '') then
|
|
_query_insert := _query_insert || ', date_special';
|
|
_select_clause := _select_clause || ', ' || _record.date_special_src_col || ' date_special';
|
|
end if;
|
|
|
|
---- metrics --------
|
|
|
|
if (_record.m1201_src_col is not null and _record.m1201_src_col != '') then
|
|
_query_insert := _query_insert || ', m1201';
|
|
_select_clause := _select_clause || ', ' || _record.m1201_src_col || ' m1201';
|
|
if (position(_search_quote in _record.m1201_src_col) = '0' and position(_open_brace in _record.m1201_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1201_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1202_src_col is not null and _record.m1202_src_col != '') then
|
|
_query_insert := _query_insert || ', m1202';
|
|
_select_clause := _select_clause || ', ' || _record.m1202_src_col || ' m1202';
|
|
if (position(_search_quote in _record.m1202_src_col) = '0' and position(_open_brace in _record.m1202_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1202_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1203_src_col is not null and _record.m1203_src_col != '') then
|
|
_query_insert := _query_insert || ', m1203';
|
|
_select_clause := _select_clause || ', ' || _record.m1203_src_col || ' m1203';
|
|
if (position(_search_quote in _record.m1203_src_col) = '0' and position(_open_brace in _record.m1203_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1203_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1204_src_col is not null and _record.m1204_src_col != '') then
|
|
_query_insert := _query_insert || ', m1204';
|
|
_select_clause := _select_clause || ', ' || _record.m1204_src_col || ' m1204';
|
|
if (position(_search_quote in _record.m1204_src_col) = '0' and position(_open_brace in _record.m1204_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1204_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1205_src_col is not null and _record.m1205_src_col != '') then
|
|
_query_insert := _query_insert || ', m1205';
|
|
_select_clause := _select_clause || ', ' || _record.m1205_src_col || ' m1205';
|
|
if (position(_search_quote in _record.m1205_src_col) = '0' and position(_open_brace in _record.m1205_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1205_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1206_src_col is not null and _record.m1206_src_col != '') then
|
|
_query_insert := _query_insert || ', m1206';
|
|
_select_clause := _select_clause || ', ' || _record.m1206_src_col || ' m1206';
|
|
if (position(_search_quote in _record.m1206_src_col) = '0' and position(_open_brace in _record.m1206_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1206_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1207_src_col is not null and _record.m1207_src_col != '') then
|
|
_query_insert := _query_insert || ', m1207';
|
|
_select_clause := _select_clause || ', ' || _record.m1207_src_col || ' m1207';
|
|
if (position(_search_quote in _record.m1207_src_col) = '0' and position(_open_brace in _record.m1207_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1207_src_col;
|
|
end if;
|
|
end if;
|
|
if (_record.m1208_src_col is not null and _record.m1208_src_col != '') then
|
|
_query_insert := _query_insert || ', m1208';
|
|
_select_clause := _select_clause || ', ' || _record.m1208_src_col || ' m1208';
|
|
if (position(_search_quote in _record.m1208_src_col) = '0' and position(_open_brace in _record.m1208_src_col) = '0') then
|
|
_group_by_clause := _group_by_clause || ', ' || _record.m1208_src_col;
|
|
end if;
|
|
end if;
|
|
|
|
|
|
if (_record.where_join_condition is not null and _record.where_join_condition != '') then
|
|
_where_clause := trim(_record.where_join_condition);
|
|
end if;
|
|
|
|
if (_record.order_by_clause is not null and _record.order_by_clause != '') then
|
|
_order_by_clause := ' order by ' || trim(_record.order_by_clause);
|
|
end if;
|
|
|
|
|
|
|
|
_query_insert := trim(_query_insert);
|
|
_select_clause := trim(_select_clause);
|
|
|
|
if (right(trim(_query_insert),1) = ',') then
|
|
_query_insert := substring(_query_insert, 1, length(_query_insert)-1);
|
|
end if;
|
|
|
|
if (right(trim(_select_clause),1) = ',') then
|
|
_select_clause := substring(_select_clause, 1, length(_select_clause)-1);
|
|
end if;
|
|
|
|
_query_insert := _query_insert || ')';
|
|
|
|
_query_string := _query_insert || ' ' || _select_clause || ' from ' || _where_clause || _group_by_clause || _order_by_clause || ';';
|
|
|
|
--return _query_string;
|
|
|
|
end loop;
|
|
|
|
_error_message_text := 'Query formation error';
|
|
|
|
return _query_string;
|
|
_error_message_text := 'Data population to ' || _table_name;
|
|
|
|
--execute(_query_string);
|
|
|
|
return 'Success';
|
|
|
|
exception when others then
|
|
_message_text := '';
|
|
_returned_sqlstate := '';
|
|
_error_message_text := '';
|
|
|
|
GET STACKED DIAGNOSTICS _message_text = MESSAGE_TEXT,
|
|
_returned_sqlstate = RETURNED_SQLSTATE;
|
|
return 'Failed: ' || _error_message_text || ' - ' || _returned_sqlstate || ' : ' || _message_text;
|
|
|
|
end
|
|
$function$
|
|
;
|