Strip html using PLSQL

Referred from John’s cookbook sample app.

create or replace function striphtml(
    p_html in varchar2)
    return varchar2
is
    l_html varchar2(32767);
    l_pos pls_integer;
begin
    if length(p_html) > 0 then
        l_html := p_html;
        loop
            l_pos := regexp_instr(l_html, '<[^<>]*>');
            if l_pos > 0 then
                l_html := regexp_replace(l_html, '<[^<>]*>', null, l_pos);
            else
                exit;
            end if;
        end loop;
    end if;

   return l_html;
end striphtml;


select striphtml ('<h1> <span>Hello</span></h1>') strip, '<h1> Hello</h1>' plane from dual;
StripPlane
Hello<h1> Hello</h1>

Updates on 7th January 2023

APEX has added this as a new feature by adding this as function into APEX_ESCAPE API.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *