@@ -135,7 +135,7 @@ create or replace type body ut_data_value_refcursor as
135135 return true;
136136 end;
137137
138- overriding member function diff( a_other ut_data_value ) return varchar2 is
138+ overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2 is
139139 c_max_rows constant integer := 50;
140140 c_pad_depth constant integer := 5;
141141 l_results ut_utils.t_clob_tab;
@@ -145,26 +145,66 @@ create or replace type body ut_data_value_refcursor as
145145 l_diff_row_count integer;
146146 l_other ut_data_value_refcursor;
147147 l_diff_id raw(16);
148+ l_sql varchar2(32767);
148149 begin
149150 if not a_other is of (ut_data_value_refcursor) then
150151 raise value_error;
151152 end if;
152153 l_other := treat(a_other as ut_data_value_refcursor);
153- l_diff_id := dbms_crypto.hash(self.data_set_guid||l_other.data_set_guid,2);
154+
154155 dbms_lob.createtemporary(l_result,true);
156+
157+ if not self.is_null and not l_other.is_null then
158+ l_sql :=
159+ 'with ' ||
160+ ' self_cols as (' ||
161+ ' select r.column_value.getstringval() col, rownum rn ' ||
162+ ' from ( select '||ut_refcursor_helper.get_columns_filter(a_exclude_xpath, a_include_xpath)||
163+ ' from ( select :columns_info as item_data from dual ) ucd' ||
164+ ' ) s, ' ||
165+ ' table( xmlsequence(extract(s.item_data,''/ROW/*'')) ) r' ||
166+ ' ),'||
167+ ' other_cols as (' ||
168+ ' select r.column_value.getstringval() col, rownum rn ' ||
169+ ' from ( select '||ut_refcursor_helper.get_columns_filter(a_exclude_xpath, a_include_xpath)||
170+ ' from (select :columns_info as item_data from dual ) ucd' ||
171+ ' ) s, ' ||
172+ ' table( xmlsequence(extract(s.item_data,''/ROW/*'')) ) r' ||
173+ ' ) ' ||
174+ q'[select case when e.rn is null then '+' else '-' end
175+ ||'Col No. '||rpad( nvl(a.rn,e.rn), :c_pad_depth)
176+ ||' '||nvl(e.col, a.col)]' ||
177+ ' from self_cols e' ||
178+ ' full outer join other_cols a ' ||
179+ ' on a.rn = e.rn and a.col = e.col' ||
180+ ' where a.rn is null or e.rn is null' ||
181+ ' order by NVL(a.rn,e.rn), a.rn';
182+ execute immediate l_sql bulk collect into l_results
183+ using a_exclude_xpath, a_include_xpath, self.columns_info,
184+ a_exclude_xpath, a_include_xpath, l_other.columns_info, c_pad_depth;
185+
186+ if l_results.count > 0 then
187+ ut_utils.append_to_clob(l_result,chr(10) || 'Columns:' || chr(10));
188+ ut_utils.append_to_clob(l_result,l_results);
189+ end if;
190+ end if;
191+
192+ l_diff_id := dbms_crypto.hash(self.data_set_guid||l_other.data_set_guid,2);
155193 -- First tell how many rows are different
156194 execute immediate 'select count(*) from ' || l_ut_owner || '.ut_data_set_diff_tmp where diff_id = :diff_id' into l_diff_row_count using l_diff_id;
157195
158- --return rows which were previously marked as different
159- execute immediate q'[select 'row_no: '||rpad( ucd.item_no, :c_pad_depth )||' '||xmlserialize( content ucd.item_data no indent)
160- from ]' || l_ut_owner || '.ut_data_set_tmp ucd
161- where ucd.data_set_guid = :self_guid
162- and ucd.item_no in (select item_no from ' || l_ut_owner || '.ut_data_set_diff_tmp ucdc where diff_id = :diff_id)
163- and rownum <= :max_rows'
196+ if l_diff_row_count > 0 then
197+ --return rows which were previously marked as different
198+ execute immediate
199+ q'[select 'Row No. '||rpad( ucd.item_no, :c_pad_depth )||' '||xmlserialize( content ucd.item_data no indent)
200+ from ]' || l_ut_owner || '.ut_data_set_tmp ucd
201+ where ucd.data_set_guid = :self_guid
202+ and ucd.item_no in (select item_no from ' || l_ut_owner || '.ut_data_set_diff_tmp ucdc where diff_id = :diff_id)
203+ and rownum <= :max_rows'
164204 bulk collect into l_results using c_pad_depth, self.data_set_guid, l_diff_id, c_max_rows;
165-
166- ut_utils.append_to_clob(l_result,'[ count = ' || to_char(l_diff_row_count) ||' ]' || chr(10) );
167- ut_utils.append_to_clob(l_result,l_results) ;
205+ ut_utils.append_to_clob(l_result,chr(10) || 'Rows: [ diff count = ' || to_char(l_diff_row_count) ||' ]' || chr(10));
206+ ut_utils.append_to_clob(l_result,l_results );
207+ end if ;
168208
169209 l_result_string := ut_utils.to_string(l_result,null);
170210 dbms_lob.freetemporary(l_result);
0 commit comments