-
Notifications
You must be signed in to change notification settings - Fork 24
/
multiple_layers.plsql
200 lines (161 loc) · 4.47 KB
/
multiple_layers.plsql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
-- Tables {
create table tq84_a (
id number primary key,
txt varchar2(10)
);
create table tq84_b (
id number primary key,
id_a references tq84_a,
txt varchar2(10)
);
create table tq84_c (
id number primary key,
id_b references tq84_b,
txt varchar2(10)
);
-- }
-- Inserts {
insert into tq84_a values ( 1, 'one');
insert into tq84_b values ( 11, 1, 'A');
insert into tq84_c values (111, 11, '(');
insert into tq84_c values (112, 11, ')');
insert into tq84_b values ( 12, 1, 'B');
insert into tq84_c values (121, 12, '!');
insert into tq84_c values (122, 12, '?');
insert into tq84_c values (123, 12, '.');
insert into tq84_c values (124, 12, ',');
insert into tq84_b values ( 13, 1, 'C');
insert into tq84_a values ( 2, 'two');
insert into tq84_a values ( 3, 'two');
insert into tq84_b values ( 31, 3, 'Y');
insert into tq84_b values ( 32, 3, 'Z');
-- }
-- Types {
create type tq84_c_o as object (
id number,
txt varchar2(10)
);
/
create type tq84_c_t as table of tq84_c_o;
/
create type tq84_b_o as object (
id number,
txt varchar2(10),
c tq84_c_t
);
/
create type tq84_b_t as table of tq84_b_o;
/
create type tq84_a_o as object (
id number,
txt varchar2(10),
b tq84_b_t
);
/
create type tq84_a_t as table of tq84_a_o;
/
-- }
declare
complete_tree tq84_a_t;
begin
select tq84_a_o (
a.id,
a.txt,
-----
cast ( collect (tq84_b_o ( b.id, b.txt, null ) ) as tq84_b_t )
) bulk collect into complete_tree
from
tq84_a a join
tq84_b b on a.id = b.id_a
group by
a.id,
a.txt;
dbms_output.new_line;
for a in 1 .. complete_tree.count loop
dbms_output.put_line('Id: ' || complete_tree(a).id || ', txt: ' || complete_tree(a).txt);
for b in 1 .. complete_tree(a).b.count loop
dbms_output.put_line(' Id: ' || complete_tree(a).b(b).id || ', txt: ' || complete_tree(a).b(b).txt);
-- ? if complete_tree(a).b(b).c is not null then
-- ? for c in 1 .. complete_tree(a).b(b).c.count loop
-- ?
-- ? dbms_output.put_line(' Id: ' || complete_tree(a).b(b).c(c).id || ', txt: ' || complete_tree(a).b(b).c(c).txt);
-- ?
-- ? end loop;
-- ? dbms_output.new_line;
-- ? end if;
end loop;
dbms_output.new_line;
end loop;
--
-- select tq84_outer (o.i,
-- o.j,
-- cast(collect( tq84_inner(i.n, i.t) order by i.n) as tq84_inner_t)
-- )
-- bulk collect into t
-- from tq84_o o join
-- tq84_i i on o.i = i.i
-- group by o.i, o.j;
--
-- --
--
---- does not work select tq84_outer__ (o.i, -- {
---- does not work o.j,
---- does not work cast(collect( tq84_inner__(i.n, i.t) order by i.n) as tq84_inner_t__)
---- does not work )
---- does not work bulk collect into t
---- does not work from tq84_o o join
---- does not work tq84_i i on o.i = i.i
---- does not work group by o.i, o.j; -- }
--
-- --
--
-- dbms_output.put_line('Cnt: ' || t.count);
--
-- dbms_output.put_line('Cnt (2): ' || t(2).inner_.count);
--
-- dbms_output.put_line(t(3).inner_(2).t);
--
-- ----------------------------------------------------
--
-- for r in (
-- select i, j from table(t)
-- ) loop -- {
--
-- dbms_output.put_line('i: ' || r.i || ', j: ' || r.j);
--
-- end loop; -- }
--
-- ----------------------------------------------------
--
-- dbms_output.new_line;
--
-- ----------------------------------------------------
--
-- for r in (
-- select
-- outer_.i,
-- outer_.j,
-- inner_.n,
-- inner_.t
-- from
-- table(t) outer_,
-- table(outer_.inner_) inner_
-- ) loop -- {
--
-- dbms_output.put_line('i: ' || r.i || ', j: ' || r.j || ', n: ' || r.n || ', t: ' || r.t);
--
-- end loop; -- }
--
-- ----------------------------------------------------
--
end;
/
drop type tq84_a_t force;
drop type tq84_a_o force;
drop type tq84_b_t force;
drop type tq84_b_o force;
drop type tq84_c_t force;
drop type tq84_c_o force;
drop table tq84_c purge;
drop table tq84_b purge;
drop table tq84_a purge;