@@ -14,29 +14,34 @@ create or replace type body ut_data_value_anydata as
1414 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515 See the License for the specific language governing permissions and
1616 limitations under the License.
17- */
18-
17+ */
1918 member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata) is
2019 l_query sys_refcursor;
2120 l_ctx number;
2221 l_ut_owner varchar2(250) := ut_utils.ut_owner;
2322 cursor_not_open exception;
2423 l_cursor_number number;
25- l_type_name varchar2(100);
26- l_schema varchar(100);
27- l_part1 varchar(30);
28- l_part2 varchar(30);
29- l_dblink varchar(30);
24+ l_anydata_type varchar2(100) := get_instance(a_value);
25+ l_element_count number;
26+
27+ --Used by dbms_utility...
28+ l_type_name varchar2(250);
29+ l_schema varchar(250);
30+ l_part1 varchar(250);
31+ l_part2 varchar(250);
32+ l_dblink varchar(250);
3033 l_part1_type number;
3134 l_objectid number;
35+
3236 begin
3337 self.data_type := case when a_value is not null then lower(a_value.gettypename()) else 'undefined' end;
34- --TODO : Move that to helper ??
3538 self.data_id := sys_guid();
3639 self.self_type := $$plsql_unit;
3740 self.cursor_details := ut_cursor_details();
3841 if a_value is not null then
42+ --TODO : Move that to helper ??
3943 dbms_utility.name_resolve(self.data_type,7, l_schema, l_part1, l_part2, l_dblink, l_part1_type, l_objectid);
44+ --TODO: Refactor into something nicer
4045 execute immediate '
4146 declare
4247 l_data '||self.data_type||';
@@ -45,12 +50,18 @@ create or replace type body ut_data_value_anydata as
4550 l_tmp_refcursor sys_refcursor;
4651 l_refcursor sys_refcursor;
4752 begin
48- l_status := l_value.get'||get_instance(a_value)||'(l_data);
49- :l_data_is_null := case when l_data is null then 1 else 0 end;
50- open l_tmp_refcursor for select l_data '||l_part1||' from dual;
51- :l_refcursor := l_tmp_refcursor;
52- end;' using in a_value, out self.is_data_null, out l_query;
53-
53+ l_status := l_value.get'||l_anydata_type||'(l_data);
54+ :l_data_is_null := case when l_data is null then 1 else 0 end; '||
55+ case when l_anydata_type = 'collection' then
56+ ' open l_tmp_refcursor for select * from table(l_data);'
57+ else
58+ ' open l_tmp_refcursor for select l_data '||l_part1||' from dual;'
59+ end ||
60+ q'[ :l_refcursor := l_tmp_refcursor;
61+ if l_data is not null then
62+ :l_count := ]'|| case when l_anydata_type = 'collection' then 'l_data.count; ' else '0; ' end ||
63+ 'end if;
64+ end;' using in a_value, out self.is_data_null, out l_query, out l_element_count;
5465 else
5566 self.is_data_null := 1;
5667 end if;
@@ -59,6 +70,10 @@ create or replace type body ut_data_value_anydata as
5970 self.elements_count := 0;
6071 if l_query%isopen then
6172 self.extract_cursor(l_query);
73+ --For collection we have to overwrite a number due to being calculated not correctly
74+ if l_anydata_type = 'collection' then
75+ self.elements_count := l_element_count;
76+ end if;
6277 l_cursor_number := dbms_sql.to_cursor_number(l_query);
6378 self.cursor_details := ut_cursor_details(l_cursor_number);
6479 dbms_sql.close_cursor(l_cursor_number);
0 commit comments