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

Skip to content

Commit aa7c711

Browse files
committed
Added tests for clob_to_table, fixed one small issue found.
1 parent 457b144 commit aa7c711

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

source/core/ut_utils.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ create or replace package body ut_utils is
132132
l_result ut_output_varchar2_list := ut_output_varchar2_list();
133133
l_delimiter_position integer;
134134
begin
135-
if a_string is not null then
135+
if a_string is not null and a_delimiter is not null then
136136
l_length := length(a_string);
137137
loop
138138
l_result.extend;

source/core/ut_utils.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ create or replace package ut_utils authid definer is
122122
Splits a given string into table of string by delimiter.
123123
The delimiter gets removed.
124124
If null passed as any of the parameters, empty table is returned.
125-
If no occurence of a_delimiter found in a_text then text is returned as a single row of the table.
125+
If split text is longer than a_max_amount it gets split into pieces of a_max_amount.
126126
If no text between delimiters found then an empty row is returned, example:
127127
string_to_table( 'a,,b', ',' ) gives table ut_output_varchar2_list( 'a', null, 'b' );
128128
*/

tests/RunAll.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ create table ut$test_table (val varchar2(1));
137137
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.AutoOnFailure.sql
138138
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.Manual.sql
139139
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.ManualOnFailure.sql
140+
@@lib/RunTest.sql ut_utils/ut_utils.clob_to_table.sql
140141
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithInvalidValues.sql
141142
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithNullValue.sql
142143
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.Success.sql
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--Arrange
2+
declare
3+
l_clob clob := '&1';
4+
l_delimiter varchar2(1) := '&2';
5+
l_expected ut_output_varchar2_list := &3;
6+
l_result ut_output_varchar2_list;
7+
l_limit integer := &4;
8+
l_result_str varchar2(32767);
9+
begin
10+
--Act
11+
select column_value
12+
bulk collect into l_result
13+
from table(ut_utils.clob_to_table(l_clob, l_delimiter, l_limit));
14+
for i in 1 .. l_result.count loop
15+
if i = l_result.count then
16+
l_delimiter := null;
17+
end if;
18+
l_result_str := ''''||l_result(i)||l_delimiter||'''';
19+
end loop;
20+
--Assert
21+
if l_result = l_expected then
22+
:test_result := ut_utils.tr_success;
23+
else
24+
dbms_output.put_line('expected: '||q'[&3]'||', got: ut_output_varchar2_list('||l_result_str||')' );
25+
end if;
26+
end;
27+
/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
PROMPT Splits a given string into table of string by delimiter
2+
@@ut_utils/common/ut_utils.clob_to_table.sql 'a,b,c,d' ',' ut_output_varchar2_list('a','b','c','d') 1000
3+
4+
PROMPT If null passed as any of the parameters, empty table is returned.
5+
@@ut_utils/common/ut_utils.clob_to_table.sql '' ',' ut_output_varchar2_list() 1000
6+
@@ut_utils/common/ut_utils.clob_to_table.sql '1,b,c,d' '' ut_output_varchar2_list() 1000
7+
8+
PROMPT If split text is longer than a_max_amount it gets split into pieces of a_max_amount
9+
@@ut_utils/common/ut_utils.clob_to_table.sql 'abcdefg,hijk,axa,a' ',' ut_output_varchar2_list('abc','def','g','hij','k','axa','a') 3
10+
11+
PROMPT If no text between delimiters found then an empty row is returned
12+
@@ut_utils/common/ut_utils.clob_to_table.sql ',a,,c,d,' ',' ut_output_varchar2_list('','a','','c','d','') 1000
13+
14+

0 commit comments

Comments
 (0)