-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path31_xml_generation.sql
71 lines (63 loc) · 1.52 KB
/
31_xml_generation.sql
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
create table characters (
id integer not null primary key,
name varchar2(100) unique
);
create table favorite_food (
character_id integer not null references characters( id ),
food varchar2(4000)
);
insert into characters values (1, 'Chewbacca');
insert into characters values (2, 'Darth Vader');
insert into favorite_food values ( 1, 'Grilled Pork');
insert into favorite_food values ( 1, 'Cooked Pork');
insert into favorite_food values ( 1, 'Raw Pork');
insert into favorite_food values ( 2, 'Cheesecake');
commit;
select *
from characters c
inner join favorite_food ff on c.id = ff.character_id;
select
xmlelement("Characters",
xmlagg(
xmlelement("Character",
xmlforest(
c.name as "name"
),
xmlelement("favouriteFoods",
xmlagg(
xmlforest(
ff.food as "food"
)
)
)
)
)
)
from characters c
inner join favorite_food ff on c.id = ff.character_id
group by name
;
select
xmlelement("sam:Characters",
xmlattributes(
'http://developer-sam.de/codeexamples' as "xmlns:sam"
),
xmlagg(
xmlelement("sam:Character",
xmlforest(
c.name as "name"
),
xmlelement("favouriteFoods",
xmlagg(
xmlforest(
ff.food as "food"
)
)
)
)
)
)
from characters c
inner join favorite_food ff on c.id = ff.character_id
group by name
;