@@ -17,7 +17,7 @@ create or replace package body ut_compound_data_helper is
1717 */
1818
1919 g_user_defined_type pls_integer := dbms_sql.user_defined_type;
20- gc_diff_count integer;
20+ g_diff_count integer;
2121
2222 function get_column_info_xml(a_column_details ut_key_anyval_pair) return xmltype is
2323 l_result varchar2(4000);
@@ -182,46 +182,53 @@ create or replace package body ut_compound_data_helper is
182182 l_act_col_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath,'ucd','act_item_data');
183183 l_exp_col_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath,'ucd','exp_item_data');
184184
185- execute immediate q'[with diff_info as
186- ( select act_data_id, exp_data_id,]'
187- ||l_act_col_filter||','|| l_exp_col_filter||q'[, :join_by join_by, item_no
188- from ut_compound_data_diff_tmp ucd
189- where diff_id = :diff_id ),
190- exp as (
185+ execute immediate q'[with exp as (
191186 select exp_item_data, exp_data_id, item_no rn,rownum col_no,
192187 nvl2(exp_item_data,ut3.ut_compound_data_helper.get_pk_value(i.join_by,exp_item_data),null) pk_value,
193188 s.column_value col, s.column_value.getRootElement() col_name, s.column_value.getclobval() col_val
194- from diff_info i,
189+ from (
190+ select exp_data_id, ]'||l_exp_col_filter||q'[, :join_by join_by, item_no
191+ from ut_compound_data_diff_tmp ucd
192+ where diff_id = :diff_id
193+ and ucd.exp_data_id = :self_guid) i,
195194 table( xmlsequence( extract(i.exp_item_data,'/*/*') ) ) s
196- where i.exp_data_id = :self_guid ),
195+ ),
197196 act as (
198197 select act_item_data, act_data_id, item_no rn, rownum col_no,
199198 nvl2(act_item_data,ut3.ut_compound_data_helper.get_pk_value(i.join_by,act_item_data),null) pk_value,
200199 s.column_value col, s.column_value.getRootElement() col_name, s.column_value.getclobval() col_val
201- from diff_info i,
200+ from (
201+ select act_data_id, ]'||l_act_col_filter||q'[, :join_by join_by, item_no
202+ from ut_compound_data_diff_tmp ucd
203+ where diff_id = :diff_id
204+ and ucd.exp_data_id = :other_guid ) i,
202205 table( xmlsequence( extract(i.act_item_data,'/*/*') ) ) s
203- where i.act_data_id = :other_guid )
206+ )
204207 select rn, diff_type, diffed_row, pk_value pk_value
205208 from (
206- select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, pk_value pk_value
207- from (
208- select nvl(exp.rn, act.rn) rn, nvl(exp.pk_value, act.pk_value) pk_value, exp.col exp_item, act.col act_item
209- from exp join act
210- on exp.rn = act.rn and exp.col_name = act.col_name
211- where dbms_lob.compare(exp.col_val, act.col_val) != 0)
212- unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
209+ select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, pk_value pk_value
210+ from
211+ ( select nvl(exp.rn, act.rn) rn, nvl(exp.pk_value, act.pk_value) pk_value, exp.col exp_item, act.col act_item
212+ from exp join act on exp.rn = act.rn and exp.col_name = act.col_name
213+ where dbms_lob.compare( exp.col_val, act.col_val) != 0)
214+ unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:')
215+ )
213216 union all
214- select item_no as rn, case when exp_data_id is null then 'Extra:' else 'Missing:' end as diff_type,
217+ select
218+ item_no as rn, case when exp_data_id is null then 'Extra:' else 'Missing:' end as diff_type,
215219 xmlserialize(content (case when exp_data_id is null then act_item_data else exp_item_data end) no indent) diffed_row,
216- nvl2(i.join_by,ut3.ut_compound_data_helper.get_pk_value(i.join_by,case when exp_data_id is null then act_item_data else exp_item_data end),null) pk_value
217- from diff_info i
218- where act_data_id is null or exp_data_id is null
220+ nvl2(:join_by,ut3.ut_compound_data_helper.get_pk_value(:join_by,case when exp_data_id is null then act_item_data else exp_item_data end),null) pk_value
221+ from ut_compound_data_diff_tmp i
222+ where diff_id = :diff_id
223+ and act_data_id is null or exp_data_id is null
219224 )
220225 order by 2, 1]'
221226 bulk collect into l_results
222- using a_exclude_xpath,a_include_xpath,
223- a_exclude_xpath,a_include_xpath,
224- a_join_by_xpath, a_diff_id, a_expected_dataset_guid,a_actual_dataset_guid;
227+ using a_exclude_xpath, a_include_xpath, a_join_by_xpath,
228+ a_diff_id, a_expected_dataset_guid,
229+ a_exclude_xpath,a_include_xpath, a_join_by_xpath,
230+ a_diff_id, a_actual_dataset_guid,
231+ a_join_by_xpath,a_join_by_xpath, a_diff_id;
225232
226233 return l_results;
227234 end;
@@ -700,17 +707,17 @@ create or replace package body ut_compound_data_helper is
700707
701708 procedure set_rows_diff(a_rows_diff integer) is
702709 begin
703- gc_diff_count := a_rows_diff;
710+ g_diff_count := a_rows_diff;
704711 end;
705712
706713 procedure cleanup_diff is
707714 begin
708- gc_diff_count := 0;
715+ g_diff_count := 0;
709716 end;
710717
711718 function get_rows_diff return integer is
712719 begin
713- return gc_diff_count ;
720+ return g_diff_count ;
714721 end;
715722
716723end;
0 commit comments