40.10 NEXT_CHUNK Function

This function reads a fixed-length string from a clob. This is just a small wrapper around DBMS_LOB.READ, however it prevents common errors when incrementing the offset and picking the maximum chunk size.

Syntax

FUNCTION NEXT_CHUNK (
    p_str    IN            CLOB,
    p_chunk  OUT           NOCOPY VARCHAR2,
    p_offset IN OUT NOCOPY PLS_INTEGER,
    p_amount IN            PLS_INTEGER DEFAULT 8191 )
    RETURN BOOLEAN;     

Parameters

Table 40-10 NEXT_CHUNK Function Parameters

Parameters Description

p_str

The input clob.

p_chunk

The chunk value (in/out).

p_offset

The position in p_str, where the next chunk should be read from (in/out).

p_amount

The amount of characters that should be read (default 8191).

Returns

True if another chunk could be read. False if reading past the end of p_str.

Example

Print chunks of 25 bytes of the input clob.

declare
    l_input  clob := 'The quick brown fox jumps over the lazy dog';
    l_offset pls_integer;
    l_chunk  varchar2(20);
begin
    while apex_string.next_chunk (
              p_str    => l_input,
              p_chunk  => l_chunk,
              p_offset => l_offset,
              p_amount => 20 )
    loop
       sys.dbms_output.put_line(l_chunk);
    end loop;
end;

Output:
  The quick brown fox
  jumps over the lazy
  dog