Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcf6117

Browse files
committed
Refactoring refcursor dataValue to dynamic sql
...because of owner issues
1 parent 4d33463 commit fcf6117

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ create or replace type body ut_data_value_refcursor as
4141
l_xml xmltype;
4242
c_bulk_rows constant integer := 1000;
4343
l_current_date_format varchar2(4000);
44+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
4445
begin
4546
self.is_cursor_null := ut_utils.boolean_to_int(a_value is null);
4647
self.self_type := $$plsql_unit;
@@ -68,8 +69,9 @@ create or replace type body ut_data_value_refcursor as
6869
loop
6970
l_xml := dbms_xmlgen.getxmltype(l_ctx);
7071

71-
insert into ut_cursor_data(cursor_data_guid, row_no, row_data)
72-
select self.data_value, self.row_count + rownum, value(a) from table( xmlsequence( extract(l_xml,'ROWSET/*') ) ) a;
72+
execute immediate 'insert into ' || l_ut_owner || '.ut_cursor_data(cursor_data_guid, row_no, row_data)
73+
select :self_guid, :self_row_count + rownum, value(a) from table( xmlsequence( extract(:l_xml,''ROWSET/*'') ) ) a'
74+
using in self.data_value, self.row_count, l_xml;
7375

7476
exit when sql%rowcount = 0;
7577

@@ -104,14 +106,15 @@ create or replace type body ut_data_value_refcursor as
104106
l_result clob;
105107
l_result_xml xmltype;
106108
l_result_string varchar2(32767);
109+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
107110
begin
108111
dbms_lob.createtemporary(l_result,true);
109112
--return rows which were previously marked as different
110-
select xmlserialize( content ucd.row_data no indent)
111-
bulk collect into l_results
112-
from ut_cursor_data ucd
113-
where ucd.cursor_data_guid = self.data_value
114-
and ucd.row_no in (select row_no from ut_cursor_data_diff ucdc);
113+
execute immediate 'select xmlserialize( content ucd.row_data no indent)
114+
from ' || l_ut_owner || '.ut_cursor_data ucd
115+
where ucd.cursor_data_guid = :self_guid
116+
and ucd.row_no in (select row_no from ' || l_ut_owner || '.ut_cursor_data_diff ucdc)'
117+
bulk collect into l_results using in self.data_value;
115118

116119
for i in 1 .. l_results.count loop
117120
dbms_lob.append(l_result,l_results(i));
@@ -134,21 +137,24 @@ create or replace type body ut_data_value_refcursor as
134137
l_result integer;
135138
l_other ut_data_value_refcursor;
136139
l_xpath varchar2(32767);
140+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
137141
begin
138142
l_xpath := coalesce(self.exclude_xpath, l_other.exclude_xpath);
139143
if a_other is of (ut_data_value_refcursor) then
140144
l_other := treat(a_other as ut_data_value_refcursor);
141-
insert into ut_cursor_data_diff ( row_no )
142-
select nvl(exp.row_no, act.row_no)
143-
from (select case when l_xpath is not null then deletexml( ucd.row_data, l_xpath ) else ucd.row_data end as row_data,
144-
ucd.row_no
145-
from ut_cursor_data ucd where ucd.cursor_data_guid = self.data_value) exp
146-
full outer join (select case when l_xpath is not null then deletexml( ucd.row_data, l_xpath ) else ucd.row_data end as row_data,
147-
ucd.row_no
148-
from ut_cursor_data ucd where ucd.cursor_data_guid = l_other.data_value) act
149-
on (exp.row_no = act.row_no)
150-
where nvl(dbms_lob.compare(xmlserialize( content exp.row_data no indent), xmlserialize( content act.row_data no indent)),1) != 0;
151-
select count(1) into l_result from ut_cursor_data_comp where rownum <= 1;
145+
146+
execute immediate 'insert into ' || l_ut_owner || '.ut_cursor_data_diff ( row_no )
147+
select nvl(exp.row_no, act.row_no)
148+
from (select case when :l_xpath is not null then deletexml( ucd.row_data, :l_xpath ) else ucd.row_data end as row_data,
149+
ucd.row_no
150+
from ' || l_ut_owner || '.ut_cursor_data ucd where ucd.cursor_data_guid = :self_guid) exp
151+
full outer join (select case when :l_xpath is not null then deletexml( ucd.row_data, :l_xpath ) else ucd.row_data end as row_data,
152+
ucd.row_no
153+
from ' || l_ut_owner || '.ut_cursor_data ucd where ucd.cursor_data_guid = :l_other_guid) act
154+
on (exp.row_no = act.row_no)
155+
where nvl(dbms_lob.compare(xmlserialize( content exp.row_data no indent), xmlserialize( content act.row_data no indent)),1) != 0'
156+
using in l_xpath, l_xpath, self.DATA_VALUE, l_xpath, l_xpath, l_other.DATA_VALUE;
157+
execute immediate 'select count(1) from ' || l_ut_owner || '.ut_cursor_data_diff where rownum <= 1' into l_result;
152158
else
153159
raise value_error;
154160
end if;

0 commit comments

Comments
 (0)