21.14 HTML_TRUNC Function Signature 2

This function escapes HTML and limits the returned string to p_length bytes. This function returns the first p_length bytes of an input CLOB and escapes them. You can use this function if the input CLOB is too large to fit in a VARCHAR2 variable and it is sufficient to only display the first part of it.

Syntax

APEX_ESCAPE.HTML_TRUNC (
    p_string    IN CLOB,
    p_length    IN NUMBER   DEFAULT 4000 )
    return VARCHAR2 deterministic;

Parameters

Table 21-15 HTML_TRUNC Parameters

Parameter Description
p_string The text string to be escaped (CLOB).
p_length

The number of bytes from p_string that are escaped.

For ASCII characters, a byte is a character.

For Unicode characters, a single character can take up to 4 bytes.

Example

This example generates a HTML list of of titles and text bodies. HTML entity attributes are escaped with HTML_ATTRIBUTE, whereas normal text is escaped with HTML and HTML_TRUNC.

BEGIN 
    htp.p('<ul>'); 
    for l_data in ( select title, cls, body 
        from my_topics ) 
    LOOP 
    sys.htp.p('<li><span class="'||
        apex_escape.html_attribute(l_data.cls)||'">'|| 
        apex_escape.html(l_data.title)||'</span>'); 
    sys.htp.p(apex_escape.html_trunc(l_data.body)); 
    sys.htp.p('</li>'); 
    END LOOP; 
    htp.p('</ul>'); 
END;