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

Skip to content

Commit 0f16efa

Browse files
author
Dmitry Volodin
committed
dbms_lob_read_multibyte/Fix multibyte issue with dbms_lob.read
1 parent 65d0169 commit 0f16efa

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

source/core/ut_utils.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ create or replace package body ut_utils is
211211
return l_result;
212212
end;
213213

214-
function clob_to_table(a_clob clob, a_max_amount integer := 32767, a_delimiter varchar2:= chr(10)) return ut_varchar2_list is
214+
function clob_to_table(a_clob clob, a_max_amount integer := 24575, a_delimiter varchar2:= chr(10)) return ut_varchar2_list is
215215
l_offset integer := 1;
216216
l_length integer := dbms_lob.getlength(a_clob);
217217
l_amount integer;

source/core/ut_utils.pks

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,20 @@ create or replace package ut_utils authid definer is
171171
Parameters:
172172
a_clob - the text to be split.
173173
a_delimiter - the delimiter character or string (default chr(10) )
174-
a_max_amount - the maximum length of returned string (default 32767)
174+
a_max_amount - the maximum length of returned string (default 24575)
175175

176176
Returns:
177177
ut_varchar2_list - table of string
178178

179179
Splits a given string into table of string by delimiter.
180+
Default value of a_max_amount is 24575 because of code can contains multibyte character.
180181
The delimiter gets removed.
181182
If null passed as any of the parameters, empty table is returned.
182183
If split text is longer than a_max_amount it gets split into pieces of a_max_amount.
183184
If no text between delimiters found then an empty row is returned, example:
184185
string_to_table( 'a,,b', ',' ) gives table ut_varchar2_list( 'a', null, 'b' );
185186
*/
186-
function clob_to_table(a_clob clob, a_max_amount integer := 32767, a_delimiter varchar2:= chr(10)) return ut_varchar2_list;
187+
function clob_to_table(a_clob clob, a_max_amount integer := 24575, a_delimiter varchar2:= chr(10)) return ut_varchar2_list;
187188

188189
function table_to_clob(a_text_table ut_varchar2_list, a_delimiter varchar2:= chr(10)) return clob;
189190

tests/RunAll.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ exec ut_coverage.coverage_start_develop();
227227
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.ManualOnFailure.sql
228228

229229
@@ut_utils/ut_utils.clob_to_table.sql
230+
@@ut_utils/ut_utils.clob_to_table_multibyte.sql
230231
@@ut_utils/ut_utils.table_to_clob.sql
231232
@@lib/RunTest.sql ut_utils/ut_utils.append_to_clob.worksWithMultiByteChars.sql
232233
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithInvalidValues.sql
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--Arrange
2+
declare
3+
l_varchar2_byte_limit integer := 32767;
4+
l_workaround_byte_limit integer := 24575;
5+
l_singlebyte_string_max_size varchar2(32767 char) := rpad('x',l_varchar2_byte_limit,'x');
6+
l_twobyte_character char(1 char) := 'ж';
7+
l_clob_multibyte clob := l_twobyte_character||l_singlebyte_string_max_size; --here we have 32769(2+32767) bytes and 32768 chars
8+
l_expected ut_varchar2_list := ut_varchar2_list();
9+
l_result ut_varchar2_list;
10+
begin
11+
l_expected.extend(2);
12+
l_expected(1) := l_twobyte_character||substr(l_singlebyte_string_max_size,1,l_workaround_byte_limit-1);
13+
l_expected(2) := substr(l_singlebyte_string_max_size,l_workaround_byte_limit-1+1);
14+
--Act
15+
l_result := ut_utils.clob_to_table(l_clob_multibyte);
16+
--Assert
17+
if l_result = l_expected then
18+
:test_result := ut_utils.tr_success;
19+
else
20+
dbms_output.put_line('expected: lengths '||length(l_expected(1))||' and '||length(l_expected(2))||', got lengths: '||length(l_result(1))||' and '||length(l_result(2)));
21+
end if;
22+
end;
23+
/

0 commit comments

Comments
 (0)