-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathp_utils_tests.sql
49 lines (49 loc) · 1.65 KB
/
p_utils_tests.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
create or replace procedure assert_eq( tActual in varchar2, tExpected in varchar2 ) is
tExpectedReplaced varchar2( 4000 ) := replace( tExpected, '<USER>', user );
begin
if tActual = tExpectedReplaced or tActual is null and tExpectedReplaced is null then
return;
end if;
raise_application_error( -20001, 'assertion failed: ' || chr( 10 ) || tActual || chr( 10 ) || tExpectedReplaced );
end;
/
declare
tDepartments str_table;
tNames str_table;
begin
with EMPLOYEES as (
select 'Sales' as DEPARTMENT, 'John' as NAME, 'Butler' as SURNAME from dual union all
select 'Sales', 'John', 'Kelly' from dual union all
select 'Sales', 'Jane', 'Kelly' from dual union all
select 'Devs', 'Ruth', 'Ostin' from dual union all
select 'Devs', 'Gareth', 'Pink' from dual union all
select 'Devs', 'Cli''igan', 'Moorney' from dual union all
select 'Devs', 'Ruth', 'Zack' from dual
)
select DEPARTMENT,
dbms_xmlgen.convert(
substr(
replace(
replace(
p_utils.distinguishXML(
XMLAgg(
XMLElement( "elem", NAME )
order by SURNAME
)
).getStringVal(), '</elem>'
), '<elem>', ', '
), 3
), 1
) as NAMES
bulk collect into tDepartments, tNames
from EMPLOYEES
group by DEPARTMENT
order by DEPARTMENT;
assert_eq( tDepartments.count, 2 );
assert_eq( tDepartments( 1 ), 'Devs' );
assert_eq( tDepartments( 2 ), 'Sales' );
assert_eq( tNames( 1 ), 'Cli''igan, Ruth, Gareth' );
assert_eq( tNames( 2 ), 'John, Jane' );
end;
/
drop procedure assert_eq;