@@ -42,49 +42,58 @@ create or replace type body ut_data_value_refcursor as
4242 c_bulk_rows constant integer := 1000;
4343 l_current_date_format varchar2(4000);
4444 l_ut_owner varchar2(250) := ut_utils.ut_owner;
45+ cursor_not_open exception;
4546 begin
4647 self.is_cursor_null := ut_utils.boolean_to_int(a_value is null);
4748 self.self_type := $$plsql_unit;
4849 self.data_value := sys_guid();
4950 self.data_type := 'refcursor';
50- if a_value is not null and a_value%isopen then
51- self.row_count := 0;
52- -- We use DBMS_XMLGEN in order to:
53- -- 1) be able to process data in bulks (set of rows)
54- -- 2) be able to influence the ROWSET/ROW tags
55- -- 3) be able to influence the way NULL values are handled (empty TAG)
56- -- 4) be able to influence the way TIMESTAMP is formatted.
57- -- Due to Oracle feature/bug, it is not possible to change the DATE formatting of cursor data
58- -- AFTER the cursor was opened.
59- -- The only solution for this is to change NLS settings before opening the cursor.
60- --
61- -- This would work fine if we could use DBMS_XMLGEN.restartQuery.
62- -- The restartQuery fails however if PLSQL variables of TIMESTAMP/INTERVAL or CLOB/BLOB are used.
63-
64- ut_expectation_processor.set_xml_nls_params();
65- l_ctx := dbms_xmlgen.newContext(a_value);
66- dbms_xmlgen.setNullHandling(l_ctx, dbms_xmlgen.empty_tag);
67- dbms_xmlgen.setMaxRows(l_ctx, c_bulk_rows);
68-
69- loop
70- l_xml := dbms_xmlgen.getxmltype(l_ctx);
71-
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;
75-
76- exit when sql%rowcount = 0;
77-
78- self.row_count := self.row_count + sql%rowcount;
79- end loop;
8051
81- ut_expectation_processor.reset_nls_params();
82- if a_value%isopen then
83- close a_value;
84- end if;
85- dbms_xmlgen.closeContext(l_ctx);
52+ if a_value is not null then
53+ if a_value%isopen then
54+ self.row_count := 0;
55+ -- We use DBMS_XMLGEN in order to:
56+ -- 1) be able to process data in bulks (set of rows)
57+ -- 2) be able to influence the ROWSET/ROW tags
58+ -- 3) be able to influence the way NULL values are handled (empty TAG)
59+ -- 4) be able to influence the way TIMESTAMP is formatted.
60+ -- Due to Oracle feature/bug, it is not possible to change the DATE formatting of cursor data
61+ -- AFTER the cursor was opened.
62+ -- The only solution for this is to change NLS settings before opening the cursor.
63+ --
64+ -- This would work fine if we could use DBMS_XMLGEN.restartQuery.
65+ -- The restartQuery fails however if PLSQL variables of TIMESTAMP/INTERVAL or CLOB/BLOB are used.
66+
67+ ut_expectation_processor.set_xml_nls_params();
68+ l_ctx := dbms_xmlgen.newContext(a_value);
69+ dbms_xmlgen.setNullHandling(l_ctx, dbms_xmlgen.empty_tag);
70+ dbms_xmlgen.setMaxRows(l_ctx, c_bulk_rows);
71+
72+ loop
73+ l_xml := dbms_xmlgen.getxmltype(l_ctx);
74+
75+ execute immediate 'insert into ' || l_ut_owner || '.ut_cursor_data(cursor_data_guid, row_no, row_data)
76+ select :self_guid, :self_row_count + rownum, value(a) from table( xmlsequence( extract(:l_xml,''ROWSET/*'') ) ) a'
77+ using in self.data_value, self.row_count, l_xml;
78+
79+ exit when sql%rowcount = 0;
80+
81+ self.row_count := self.row_count + sql%rowcount;
82+ end loop;
83+
84+ ut_expectation_processor.reset_nls_params();
85+ if a_value%isopen then
86+ close a_value;
87+ end if;
88+ dbms_xmlgen.closeContext(l_ctx);
89+
90+ elsif not a_value%isopen then
91+ raise cursor_not_open;
92+ end if;
8693 end if;
8794 exception
95+ when cursor_not_open then
96+ raise_application_error(-20155, 'Cursor is not open');
8897 when others then
8998 ut_expectation_processor.reset_nls_params();
9099 if a_value%isopen then
@@ -160,9 +169,9 @@ create or replace type body ut_data_value_refcursor as
160169 ucd.row_no
161170 from ' || l_ut_owner || '.ut_cursor_data ucd where ucd.cursor_data_guid = :l_other_guid) act
162171 on (exp.row_no = act.row_no)
163- where nvl(dbms_lob.compare(xmlserialize( content exp.row_data no indent), xmlserialize( content act.row_data no indent)),1) != 0'
172+ where nvl(dbms_lob.compare(xmlserialize( content exp.row_data no indent), xmlserialize( content act.row_data no indent)),1) != 0'
164173 using in l_xpath, l_xpath, self.DATA_VALUE, l_xpath, l_xpath, l_other.DATA_VALUE;
165-
174+
166175 --result is OK only if both are same
167176 if sql%rowcount = 0 and self.row_count = l_other.row_count then
168177 l_result := 0;
0 commit comments