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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
dbms_lob_read_multibyte/Fix multibyte issue with dbms_lob.read
  • Loading branch information
Dmitry Volodin committed Jun 27, 2017
commit 0f16efa584b90b359c729e4dba9ee00a3f32d128
2 changes: 1 addition & 1 deletion source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ create or replace package body ut_utils is
return l_result;
end;

function clob_to_table(a_clob clob, a_max_amount integer := 32767, a_delimiter varchar2:= chr(10)) return ut_varchar2_list is
function clob_to_table(a_clob clob, a_max_amount integer := 24575, a_delimiter varchar2:= chr(10)) return ut_varchar2_list is
l_offset integer := 1;
l_length integer := dbms_lob.getlength(a_clob);
l_amount integer;
Expand Down
5 changes: 3 additions & 2 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,20 @@ create or replace package ut_utils authid definer is
Parameters:
a_clob - the text to be split.
a_delimiter - the delimiter character or string (default chr(10) )
a_max_amount - the maximum length of returned string (default 32767)
a_max_amount - the maximum length of returned string (default 24575)

Returns:
ut_varchar2_list - table of string

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ exec ut_coverage.coverage_start_develop();
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.ManualOnFailure.sql

@@ut_utils/ut_utils.clob_to_table.sql
@@ut_utils/ut_utils.clob_to_table_multibyte.sql
@@ut_utils/ut_utils.table_to_clob.sql
@@lib/RunTest.sql ut_utils/ut_utils.append_to_clob.worksWithMultiByteChars.sql
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithInvalidValues.sql
Expand Down
23 changes: 23 additions & 0 deletions tests/ut_utils/ut_utils.clob_to_table_multibyte.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Arrange
declare
l_varchar2_byte_limit integer := 32767;
l_workaround_byte_limit integer := 24575;
l_singlebyte_string_max_size varchar2(32767 char) := rpad('x',l_varchar2_byte_limit,'x');
l_twobyte_character char(1 char) := 'ж';
l_clob_multibyte clob := l_twobyte_character||l_singlebyte_string_max_size; --here we have 32769(2+32767) bytes and 32768 chars
l_expected ut_varchar2_list := ut_varchar2_list();
l_result ut_varchar2_list;
begin
l_expected.extend(2);
l_expected(1) := l_twobyte_character||substr(l_singlebyte_string_max_size,1,l_workaround_byte_limit-1);
l_expected(2) := substr(l_singlebyte_string_max_size,l_workaround_byte_limit-1+1);
--Act
l_result := ut_utils.clob_to_table(l_clob_multibyte);
--Assert
if l_result = l_expected then
:test_result := ut_utils.tr_success;
else
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)));
end if;
end;
/