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

Skip to content

Commit c997616

Browse files
committed
Added cursor info code
1 parent 5b46ab0 commit c997616

8 files changed

Lines changed: 275 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
create or replace type ut_column_info as object (
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2018 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
column_name varchar2(100),
19+
xml_valid_name varchar2(100),
20+
21+
)
22+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
create or replace type body ut_column_info as
2+
member function get_data_type(a_type_code in integer,a_user_defined in boolean) return varchar2 is
3+
begin
4+
return ut_curr_usr_compound_helper.get_column_type(a_type_code,a_user_defined);
5+
end;
6+
7+
member procedure init(self in out nocopy ut_column_info,
8+
a_col_type binary_integer,
9+
a_col_name varchar2,
10+
a_col_schema_name varchar2,
11+
a_col_type_name varchar2,
12+
a_col_prec integer,
13+
a_col_scale integer,
14+
a_col_len integer,
15+
a_dbms_sql_desc boolean := false) is
16+
begin
17+
self.is_user_defined := 0;
18+
self.column_prec := a_col_prec;
19+
self.column_len := a_col_len;
20+
self.column_scale := a_col_scale;
21+
self.xml_valid_name := '"'||a_col_name||'"';
22+
self.column_name := a_col_name;
23+
self.column_type := get_data_type(a_col_type,a_dbms_sql_desc);
24+
self.column_schema := a_col_schema_name;
25+
self.is_sql_diffable := ut_utils.boolean_to_int(ut_curr_usr_compound_helper.is_sql_compare_allowed(self.column_type));
26+
self.is_collection := 0;
27+
end;
28+
end;
29+
/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
create or replace type ut_column_info force authid current_user as object
2+
(
3+
xml_valid_name varchar2(100),
4+
column_name varchar2(100),
5+
column_type varchar2(100),
6+
column_schema varchar2(100),
7+
column_prec integer,
8+
column_len integer,
9+
column_scale integer,
10+
is_sql_diffable number(1, 0),
11+
is_collection number(1, 0),
12+
is_user_defined number(1, 0),
13+
member function get_data_type(a_type_code in integer,a_user_defined in boolean) return varchar2,
14+
member procedure init(self in out nocopy ut_column_info,
15+
a_col_type binary_integer,
16+
a_col_name varchar2,
17+
a_col_schema_name varchar2,
18+
a_col_type_name varchar2,
19+
a_col_prec integer,
20+
a_col_scale integer,
21+
a_col_len integer,
22+
a_dbms_sql_desc boolean := false)
23+
)
24+
not final not instantiable
25+
/
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
create or replace type body ut_column_info_rec as
2+
3+
member function get_anytype_attributes_info(a_anytype anytype)
4+
return ut_column_info_tab is
5+
l_result ut_column_info_tab := ut_column_info_tab();
6+
l_attribute_typecode pls_integer;
7+
l_aname varchar2(32767);
8+
l_prec pls_integer;
9+
l_scale pls_integer;
10+
l_len pls_integer;
11+
l_csid pls_integer;
12+
l_csfrm pls_integer;
13+
l_attr_elt_type anytype;
14+
15+
function get_anytype_attribute_count(a_anytype anytype) return pls_integer is
16+
l_attribute_typecode pls_integer;
17+
l_schema_name varchar2(32767);
18+
l_version varchar2(32767);
19+
l_type_name varchar2(32767);
20+
l_attributes pls_integer;
21+
l_prec pls_integer;
22+
l_scale pls_integer;
23+
l_len pls_integer;
24+
l_csid pls_integer;
25+
l_csfrm pls_integer;
26+
begin
27+
l_attribute_typecode := a_anytype.getinfo(prec => l_prec,
28+
scale => l_scale,
29+
len => l_len,
30+
csid => l_csid,
31+
csfrm => l_csfrm,
32+
schema_name => l_schema_name,
33+
type_name => l_type_name,
34+
version => l_version,
35+
numelems => l_attributes);
36+
return l_attributes;
37+
end;
38+
39+
begin
40+
for i in 1 .. get_anytype_attribute_count(a_anytype) loop
41+
l_attribute_typecode := a_anytype.getattreleminfo(pos => i, --First attribute
42+
prec => l_prec,
43+
scale => l_scale,
44+
len => l_len,
45+
csid => l_csid,
46+
csfrm => l_csfrm,
47+
attr_elt_type => l_attr_elt_type,
48+
aname => l_aname);
49+
50+
l_result.extend;
51+
l_result(l_result.last) := ut_column_info_rec(l_attribute_typecode,
52+
l_aname,
53+
null,
54+
null,
55+
l_prec,
56+
l_scale,
57+
l_len);
58+
end loop;
59+
return l_result;
60+
end;
61+
62+
member function get_user_defined_type(a_owner varchar2, a_type_name varchar2)
63+
return anytype is
64+
l_anydata anydata;
65+
l_anytype anytype;
66+
l_typecode pls_integer;
67+
68+
begin
69+
execute immediate 'declare
70+
l_v ' || a_owner || '.' ||
71+
a_type_name || ';
72+
begin
73+
:anydata := anydata.convertobject(l_v);
74+
end;'
75+
using in out l_anydata;
76+
77+
l_typecode := l_anydata.gettype(l_anytype);
78+
79+
return l_anytype;
80+
end;
81+
82+
overriding member procedure init(self in out nocopy ut_column_info_rec,
83+
a_col_type binary_integer,
84+
a_col_name varchar2,
85+
a_col_schema_name varchar2,
86+
a_col_type_name varchar2,
87+
a_col_prec integer,
88+
a_col_scale integer,
89+
a_col_len integer,
90+
a_dbms_sql_desc boolean := false) is
91+
l_anytype anytype;
92+
begin
93+
self.column_prec := a_col_prec;
94+
self.column_len := a_col_len;
95+
self.column_scale := a_col_scale;
96+
self.xml_valid_name := '"'||a_col_name||'"';
97+
self.column_name := a_col_name;
98+
self.column_type := a_col_type_name;
99+
self.column_schema := a_col_schema_name;
100+
self.is_sql_diffable := 0;
101+
self.is_collection := ut_utils.boolean_to_int(ut_curr_usr_compound_helper.is_collection(a_col_schema_name,a_col_type_name));
102+
self.is_user_defined := 1;
103+
104+
l_anytype := get_user_defined_type(a_col_schema_name, a_col_type_name);
105+
self.nested_details := get_anytype_attributes_info(l_anytype);
106+
end;
107+
108+
constructor function ut_column_info_rec(self in out nocopy ut_column_info_rec,
109+
a_col_type binary_integer,
110+
a_col_name varchar2,
111+
a_col_schema_name varchar2,
112+
a_col_type_name varchar2,
113+
a_col_prec integer,
114+
a_col_scale integer,
115+
a_col_len integer,
116+
a_dbms_sql_desc boolean := false)
117+
return self as result is
118+
begin
119+
if a_col_type = dbms_sql.user_defined_type then
120+
self.init(a_col_type, a_col_name, a_col_schema_name, a_col_type_name,a_col_prec,a_col_scale,a_col_len);
121+
else
122+
(self as ut_column_info).init(a_col_type,
123+
a_col_name,
124+
a_col_schema_name,
125+
a_col_type_name,a_col_prec,a_col_scale,a_col_len,
126+
a_dbms_sql_desc);
127+
end if;
128+
return;
129+
end;
130+
end;
131+
/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
create or replace type ut_column_info_rec under ut_column_info
2+
(
3+
nested_details ut_column_info_tab,
4+
member function get_anytype_attributes_info(a_anytype anytype)
5+
return ut_column_info_tab,
6+
member function get_user_defined_type(a_owner varchar2, a_type_name varchar2)
7+
return anytype,
8+
overriding member procedure init(self in out nocopy ut_column_info_rec,
9+
a_col_type binary_integer,
10+
a_col_name varchar2,
11+
a_col_schema_name varchar2,
12+
a_col_type_name varchar2,
13+
a_col_prec integer,
14+
a_col_scale integer,
15+
a_col_len integer,
16+
a_dbms_sql_desc boolean := false),
17+
constructor function ut_column_info_rec(self in out nocopy ut_column_info_rec,
18+
a_col_type binary_integer,
19+
a_col_name varchar2,
20+
a_col_schema_name varchar2,
21+
a_col_type_name varchar2,
22+
a_col_prec integer,
23+
a_col_scale integer,
24+
a_col_len integer,
25+
a_dbms_sql_desc boolean := false)
26+
return self as result
27+
)
28+
/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE OR REPLACE TYPE ut_column_info_tab FORCE AS TABLE OF ut_column_info;
2+
/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
create or replace type body ut_cursor_info as
2+
constructor function ut_cursor_info(self in out nocopy ut_cursor_info,
3+
a_cursor in out nocopy sys_refcursor)
4+
return self as result is
5+
l_cursor_number integer;
6+
l_columns_count pls_integer;
7+
l_columns_desc dbms_sql.desc_tab3;
8+
begin
9+
self.cursor_info := ut_column_info_tab();
10+
l_cursor_number := dbms_sql.to_cursor_number(a_cursor);
11+
dbms_sql.describe_columns3(l_cursor_number,
12+
l_columns_count,
13+
l_columns_desc);
14+
a_cursor := dbms_sql.to_refcursor(l_cursor_number);
15+
16+
for i in 1 .. l_columns_count loop
17+
self.cursor_info.extend;
18+
self.cursor_info(cursor_info.last) := ut_column_info_rec(l_columns_desc(i).col_type,
19+
l_columns_desc(i).col_name,
20+
l_columns_desc(i).col_schema_name,
21+
l_columns_desc(i).col_type_name,
22+
l_columns_desc(i).col_precision,
23+
l_columns_desc(i).col_scale,
24+
l_columns_desc(i).col_name_len,
25+
true);
26+
end loop;
27+
28+
return;
29+
end ut_cursor_info;
30+
end;
31+
/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
create or replace type ut_cursor_info force authid current_user as object
2+
(
3+
cursor_info ut_column_info_tab,
4+
constructor function ut_cursor_info(self in out nocopy ut_cursor_info,a_cursor in out nocopy sys_refcursor)
5+
return self as result
6+
)
7+
/

0 commit comments

Comments
 (0)