saas script first version
This commit is contained in:
248
retail_model/script/fw_ods_rollup.sql
Normal file
248
retail_model/script/fw_ods_rollup.sql
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION fw_ods_rollup (
|
||||||
|
rollup_type in varchar default 'daily',
|
||||||
|
exclude_name1 in varchar default null,
|
||||||
|
exclude_name2 in varchar default null,
|
||||||
|
exclude_name3 in varchar default null,
|
||||||
|
exclude_name4 in varchar default null
|
||||||
|
)
|
||||||
|
RETURNS text
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $function$
|
||||||
|
declare
|
||||||
|
|
||||||
|
_query_string varchar;
|
||||||
|
_query_insert varchar;
|
||||||
|
_select_clause varchar;
|
||||||
|
_where_clause varchar;
|
||||||
|
_group_by_clause varchar;
|
||||||
|
_order_by_clause varchar;
|
||||||
|
_rollup_type varchar;
|
||||||
|
_target_table varchar;
|
||||||
|
_from_clause varchar;
|
||||||
|
|
||||||
|
_message_text varchar;
|
||||||
|
_returned_sqlstate varchar;
|
||||||
|
_error_message_text varchar;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
_query_insert := '';
|
||||||
|
_select_clause := '';
|
||||||
|
_query_string := '';
|
||||||
|
_where_clause := ' where ';
|
||||||
|
_order_by_clause := '';
|
||||||
|
_group_by_clause := ' group by ';
|
||||||
|
_rollup_type := lower(rollup_type);
|
||||||
|
_from_clause := '';
|
||||||
|
|
||||||
|
/* Validating rollup type and restricting the value to 'daily', 'weekly' or 'monthly' */
|
||||||
|
|
||||||
|
if (_rollup_type not in ('daily', 'weekly', 'monthly')) then
|
||||||
|
return 'Invalid rollup type, please check';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
/* Setting target table according to rollup type */
|
||||||
|
|
||||||
|
if (_rollup_type = 'daily') then
|
||||||
|
_target_table := 'fw_ods_daily';
|
||||||
|
_from_clause := _from_clause || 'from fw_ods_tli tl join fw_ods_txn tx ';
|
||||||
|
_from_clause := _from_clause || ' on tl.d0l1_src_id = tx.d0l1_src_id';
|
||||||
|
elseif (_rollup_type = 'weekly') then
|
||||||
|
_target_table := 'fw_ods_weekly';
|
||||||
|
_from_clause := _from_clause || 'from fw_ods_daily tl ';
|
||||||
|
elseif (_rollup_type = 'monthly') then
|
||||||
|
_target_table := 'fw_ods_monthly';
|
||||||
|
_from_clause := _from_clause || 'from fw_ods_daily tl ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
/* Checking whether specified exclude dimenstion name is valid or not */
|
||||||
|
|
||||||
|
if (lower(exclude_name1) not in ('d1', 'd2', 'd3', 'd4', 'd5')) then
|
||||||
|
return 'Invalid exclude_name1, it is suppose to be one among (d1, d2, d3, d4, d5)';
|
||||||
|
end if;
|
||||||
|
if (lower(exclude_name2) not in ('d1', 'd2', 'd3', 'd4', 'd5')) then
|
||||||
|
return 'Invalid exclude_name2, it is suppose to be one among (d1, d2, d3, d4, d5)';
|
||||||
|
end if;
|
||||||
|
if (lower(exclude_name3) not in ('d1', 'd2', 'd3', 'd4', 'd5')) then
|
||||||
|
return 'Invalid exclude_name3, it is suppose to be one among (d1, d2, d3, d4, d5)';
|
||||||
|
end if;
|
||||||
|
if (lower(exclude_name4) not in ('d1', 'd2', 'd3', 'd4', 'd5')) then
|
||||||
|
return 'Invalid exclude_name4, it is suppose to be one among (d1, d2, d3, d4, d5)';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
|
||||||
|
if (exclude_name1 is not null and exclude_name1 != '') then
|
||||||
|
exclude_name1 := lower(exclude_name1);
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name2 is not null and exclude_name2 != '') then
|
||||||
|
exclude_name2 := lower(exclude_name2);
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name3 is not null and exclude_name3 != '') then
|
||||||
|
exclude_name3 := lower(exclude_name3);
|
||||||
|
else
|
||||||
|
exclude_name3 := null;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name4 is not null and exclude_name4 != '') then
|
||||||
|
exclude_name4:= lower(exclude_name4);
|
||||||
|
end if;
|
||||||
|
|
||||||
|
_query_insert := 'insert into ' || _target_table || ' (client_id, function_id, txna01_name, txna02_name, txna03_name, txna04_name, ';
|
||||||
|
_query_insert := _query_insert || 'txna05_name, txna06_name, txna07_name, txna08_name, txna09_name, txna10_name, tlia01_name, tlia02_name, ';
|
||||||
|
|
||||||
|
_select_clause := 'select tl.client_id, tl.function_id, tl.txna01_name, tl.txna02_name, tl.txna03_name, tl.txna04_name, ';
|
||||||
|
_select_clause := _select_clause || 'tl.txna05_name, tl.txna06_name, tl.txna07_name, tl.txna08_name, tl.txna09_name, tl.txna10_name, tl.tlia01_name, tl.tlia02_name, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.client_id, tl.function_id, tl.txna01_name, tl.txna02_name, tl.txna03_name, tl.txna04_name, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.txna05_name, tl.txna06_name, tl.txna07_name, tl.txna08_name, tl.txna09_name, tl.txna10_name, tl.tlia01_name, tl.tlia02_name, ';
|
||||||
|
|
||||||
|
|
||||||
|
if (exclude_name1 = 'd1' or exclude_name2 = 'd1' or exclude_name3 = 'd1' or exclude_name4 = 'd1') then
|
||||||
|
_query_insert := _query_insert;
|
||||||
|
else
|
||||||
|
_query_insert := _query_insert || 'd1_unique_id, d1_src_id, d1_unique_id_name, d1l01_id, d1l01_src_id, d1l01_name, d1l02_id, d1l02_src_id, ';
|
||||||
|
_query_insert := _query_insert || 'd1l02_name, d1l03_id, d1l03_src_id, d1l03_name, d1l04_id, d1l04_src_id, d1l04_name, d1l05_id, d1l05_src_id, ';
|
||||||
|
_query_insert := _query_insert || 'd1l05_name, d1a01, d1a02, d1a03, d1a04, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'tl.d1_unique_id, tl.d1_src_id, tl.d1_unique_id_name, tl.d1l01_id, tl.d1l01_src_id, tl.d1l01_name, tl.d1l02_id, tl.d1l02_src_id, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d1l02_name, tl.d1l03_id, tl.d1l03_src_id, tl.d1l03_name, tl.d1l04_id, tl.d1l04_src_id, tl.d1l04_name, tl.d1l05_id, tl.d1l05_src_id, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d1l05_name, tl.d1a01, tl.d1a02, tl.d1a03, tl.d1a04, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d1_unique_id, tl.d1_src_id, tl.d1_unique_id_name, tl.d1l01_id, tl.d1l01_src_id, tl.d1l01_name, tl.d1l02_id, tl.d1l02_src_id, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d1l02_name, tl.d1l03_id, tl.d1l03_src_id, tl.d1l03_name, tl.d1l04_id, tl.d1l04_src_id, tl.d1l04_name, tl.d1l05_id, tl.d1l05_src_id, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d1l05_name, tl.d1a01, tl.d1a02, tl.d1a03, tl.d1a04, ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name1 = 'd2' or exclude_name2 = 'd2' or exclude_name3 = 'd2' or exclude_name4 = 'd2') then
|
||||||
|
_query_insert := _query_insert;
|
||||||
|
else
|
||||||
|
_query_insert := _query_insert || 'd2_unique_id, d2_src_id, d2_unique_id_name, d2l01_id, d2l01_src_id, ';
|
||||||
|
_query_insert := _query_insert || 'd2l01_name, d2l02_id, d2l02_src_id, d2l02_name, d2l03_id, d2l03_src_id, d2l03_name, d2l04_id, d2l04_src_id, ';
|
||||||
|
_query_insert := _query_insert || 'd2l04_name, d2l05_id, d2l05_src_id, d2l05_name, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'tl.d2_unique_id, tl.d2_src_id, tl.d2_unique_id_name, tl.d2l01_id, tl.d2l01_src_id, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d2l01_name, tl.d2l02_id, tl.d2l02_src_id, tl.d2l02_name, tl.d2l03_id, tl.d2l03_src_id, tl.d2l03_name, tl.d2l04_id, tl.d2l04_src_id, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d2l04_name, tl.d2l05_id, tl.d2l05_src_id, tl.d2l05_name, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d2_unique_id, tl.d2_src_id, tl.d2_unique_id_name, tl.d2l01_id, tl.d2l01_src_id, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d2l01_name, tl.d2l02_id, tl.d2l02_src_id, tl.d2l02_name, tl.d2l03_id, tl.d2l03_src_id, tl.d2l03_name, tl.d2l04_id, tl.d2l04_src_id, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d2l04_name, tl.d2l05_id, tl.d2l05_src_id, tl.d2l05_name, ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name1 = 'd3' or exclude_name2 = 'd3' or exclude_name3 = 'd3' or exclude_name4 = 'd3') then
|
||||||
|
_query_insert := _query_insert;
|
||||||
|
else
|
||||||
|
_query_insert := _query_insert || 'd3_unique_id, d3_src_id, d3_unique_id_name, d3a01, d3a02, ';
|
||||||
|
_query_insert := _query_insert || 'd3_geo_id, d3_country, d3_region, d3_state, d3_district, d3_city_town, d3_location_area, d3_zipcode, ';
|
||||||
|
_query_insert := _query_insert || 'd3_locality_type, d3_latitude, d3_longitude, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'tl.d3_unique_id, tl.d3_src_id, tl.d3_unique_id_name, tl.d3a01, tl.d3a02, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d3_geo_id, tl.d3_country, tl.d3_region, tl.d3_state, tl.d3_district, tl.d3_city_town, tl.d3_location_area, tl.d3_zipcode, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d3_locality_type, tl.d3_latitude, tl.d3_longitude, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d3_unique_id, tl.d3_src_id, tl.d3_unique_id_name, tl.d3a01, tl.d3a02, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d3_geo_id, tl.d3_country, tl.d3_region, tl.d3_state, tl.d3_district, tl.d3_city_town, tl.d3_location_area, tl.d3_zipcode, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d3_locality_type, tl.d3_latitude, tl.d3_longitude, ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name1 = 'd4' or exclude_name2 = 'd4' or exclude_name3 = 'd4' or exclude_name4 = 'd4') then
|
||||||
|
_query_insert := _query_insert;
|
||||||
|
else
|
||||||
|
_query_insert := _query_insert || 'd4_unique_id, d4_src_id, d4_unique_id_name, d4a02, d4a03, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d4_unique_id, tl.d4_src_id, tl.d4_unique_id_name, tl.d4a02, tl.d4a03, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d4_unique_id, tl.d4_src_id, tl.d4_unique_id_name, tl.d4a02, tl.d4a03, ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if (exclude_name1 = 'd5' or exclude_name2 = 'd5' or exclude_name3 = 'd5' or exclude_name4 = 'd5') then
|
||||||
|
_query_insert := _query_insert;
|
||||||
|
else
|
||||||
|
_query_insert := _query_insert || 'd5_unique_id, d5_src_id, d5_unique_id_name, d5a01, d5a02, d5a03, ';
|
||||||
|
_select_clause := _select_clause || 'tl.d5_unique_id, tl.d5_src_id, tl.d5_unique_id_name, tl.d5a01, tl.d5a02, tl.d5a03, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.d5_unique_id, tl.d5_src_id, tl.d5_unique_id_name, tl.d5a01, tl.d5a02, tl.d5a03, ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
/* selecting columns based on rollup type */
|
||||||
|
|
||||||
|
if (_rollup_type = 'daily') then
|
||||||
|
_query_insert := _query_insert || 'date_field, date_yyyy, date_qq, date_mm, date_yyyymm, date_ww, ';
|
||||||
|
_query_insert := _query_insert || 'date_dd, date_fy_yyyy, date_fy_qq, date_fy_mm, date_fy_yyyymm, date_fy_ww, ';
|
||||||
|
_query_insert := _query_insert || 'date_weekday, date_weekend, date_lunarmonth, date_lunarday, date_holiday, date_festival, date_special, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'tl.date_field, tl.date_yyyy, tl.date_qq, tl.date_mm, tl.date_yyyymm, tl.date_ww, ';
|
||||||
|
_select_clause := _select_clause || 'tl.date_dd, tl.date_fy_yyyy, tl.date_fy_qq, tl.date_fy_mm, tl.date_fy_yyyymm, tl.date_fy_ww, ';
|
||||||
|
_select_clause := _select_clause || 'tl.date_weekday, tl.date_weekend, tl.date_lunarmonth, tl.date_lunarday, tl.date_holiday, tl.date_festival, tl.date_special, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_field, tl.date_yyyy, tl.date_qq, tl.date_mm, tl.date_yyyymm, tl.date_ww, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_dd, tl.date_fy_yyyy, tl.date_fy_qq, tl.date_fy_mm, tl.date_fy_yyyymm, tl.date_fy_ww, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_weekday, tl.date_weekend, tl.date_lunarmonth, tl.date_lunarday, tl.date_holiday, tl.date_festival, tl.date_special, ';
|
||||||
|
elseif (_rollup_type = 'weekly') then
|
||||||
|
_query_insert := _query_insert || 'date_yyyy, date_qq, date_mm, date_yyyymm, date_ww, ';
|
||||||
|
_query_insert := _query_insert || 'date_fy_yyyy, date_fy_qq, date_fy_mm, date_fy_yyyymm, date_fy_ww, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'tl.date_yyyy, tl.date_qq, tl.date_mm, tl.date_yyyymm, tl.date_ww, ';
|
||||||
|
_select_clause := _select_clause || 'tl.date_fy_yyyy, tl.date_fy_qq, tl.date_fy_mm, tl.date_fy_yyyymm, tl.date_fy_ww, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_yyyy, tl.date_qq, tl.date_mm, tl.date_yyyymm, tl.date_ww, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_fy_yyyy, tl.date_fy_qq, tl.date_fy_mm, tl.date_fy_yyyymm, tl.date_fy_ww, ';
|
||||||
|
else
|
||||||
|
_query_insert := _query_insert || 'date_yyyy, date_qq, date_mm, date_yyyymm, ';
|
||||||
|
_query_insert := _query_insert || 'date_fy_yyyy, date_fy_qq, date_fy_mm, date_fy_yyyymm, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'tl.date_yyyy, tl.date_qq, tl.date_mm, tl.date_yyyymm, ';
|
||||||
|
_select_clause := _select_clause || 'tl.date_fy_yyyy, tl.date_fy_qq, tl.date_fy_mm, tl.date_fy_yyyymm, ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_yyyy, tl.date_qq, tl.date_mm, tl.date_yyyymm, ';
|
||||||
|
_group_by_clause := _group_by_clause || 'tl.date_fy_yyyy, tl.date_fy_qq, tl.date_fy_mm, tl.date_fy_yyyymm, ';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
--_query_insert := _query_insert || 'm1101, m1102, m1103, m1104, m1105, m1106, m1107, m1108, ';
|
||||||
|
_query_insert := _query_insert || 'm1101, ';
|
||||||
|
|
||||||
|
_query_insert := _query_insert || 'm1201, m1202, m1203, m1204, m1205, m1206, m1207, m1208)';
|
||||||
|
|
||||||
|
--_select_clause := _select_clause || 'sum(m1101) m1101, sum(m1102) m1102, sum(m1103) m1103, sum(m1104) m1104, ';
|
||||||
|
--_select_clause := _select_clause || 'sum(m1105) m1105, sum(m1106) m1106, sum(m1107) m1107, sum(m1108) m1108, ';
|
||||||
|
_select_clause := _select_clause || 'count(m1101) m1101, ';
|
||||||
|
|
||||||
|
_select_clause := _select_clause || 'm1201, m1202, sum(m1203) m1203, sum(m1204) m1204, ';
|
||||||
|
_select_clause := _select_clause || 'sum(m1205) m1205, sum(m1206) m1206, sum(m1207) m1207, sum(m1208) m1208 ';
|
||||||
|
|
||||||
|
_group_by_clause := _group_by_clause || 'm1201, m1202 ';
|
||||||
|
|
||||||
|
|
||||||
|
_query_insert := trim(_query_insert);
|
||||||
|
_select_clause := trim(_select_clause);
|
||||||
|
_where_clause := trim(_where_clause);
|
||||||
|
_group_by_clause := trim(_group_by_clause);
|
||||||
|
|
||||||
|
if (_where_clause = 'where') then
|
||||||
|
_query_string := _query_insert || ' ' || _select_clause || ' ' || _from_clause || ' ' || _group_by_clause || ';';
|
||||||
|
else
|
||||||
|
_query_string := _query_insert || ' ' || _select_clause || ' ' || _from_clause || ' ' || _where_clause || ' ' || _group_by_clause || ';';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
_error_message_text := 'Query formation error';
|
||||||
|
--return _query_string;
|
||||||
|
|
||||||
|
_error_message_text := 'Data population to ' || _target_table;
|
||||||
|
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$
|
||||||
|
;
|
||||||
814
retail_model/script/fw_ods_tli_load.sql
Normal file
814
retail_model/script/fw_ods_tli_load.sql
Normal file
@@ -0,0 +1,814 @@
|
|||||||
|
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$
|
||||||
|
;
|
||||||
514
retail_model/script/fw_ods_txn_load.sql
Normal file
514
retail_model/script/fw_ods_txn_load.sql
Normal file
@@ -0,0 +1,514 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION fw_ods_txn_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_txn
|
||||||
|
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.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;
|
||||||
|
|
||||||
|
---- 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.m1101_src_col is not null and _record.m1101_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1101';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1101_src_col || ' m1101';
|
||||||
|
if (position(_search_quote in _record.m1101_src_col) = '0' and position(_open_brace in _record.m1101_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1101_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1102_src_col is not null and _record.m1102_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1102';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1102_src_col || ' m1102';
|
||||||
|
if (position(_search_quote in _record.m1102_src_col) = '0' and position(_open_brace in _record.m1102_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1102_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1103_src_col is not null and _record.m1103_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1103';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1103_src_col || ' m1103';
|
||||||
|
if (position(_search_quote in _record.m1103_src_col) = '0' and position(_open_brace in _record.m1103_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1103_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1104_src_col is not null and _record.m1104_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1104';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1104_src_col || ' m1104';
|
||||||
|
if (position(_search_quote in _record.m1104_src_col) = '0' and position(_open_brace in _record.m1104_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1104_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1105_src_col is not null and _record.m1105_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1105';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1105_src_col || ' m1105';
|
||||||
|
if (position(_search_quote in _record.m1105_src_col) = '0' and position(_open_brace in _record.m1105_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1105_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1106_src_col is not null and _record.m1106_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1106';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1106_src_col || ' m1106';
|
||||||
|
if (position(_search_quote in _record.m1106_src_col) = '0' and position(_open_brace in _record.m1106_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1106_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1107_src_col is not null and _record.m1107_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1107';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1107_src_col || ' m1107';
|
||||||
|
if (position(_search_quote in _record.m1107_src_col) = '0' and position(_open_brace in _record.m1107_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1107_src_col;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if (_record.m1108_src_col is not null and _record.m1108_src_col != '') then
|
||||||
|
_query_insert := _query_insert || ', m1108';
|
||||||
|
_select_clause := _select_clause || ', ' || _record.m1108_src_col || ' m1108';
|
||||||
|
if (position(_search_quote in _record.m1108_src_col) = '0' and position(_open_brace in _record.m1108_src_col) = '0') then
|
||||||
|
_group_by_clause := _group_by_clause || ', ' || _record.m1108_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$
|
||||||
|
;
|
||||||
Reference in New Issue
Block a user