Tag Archives: html stripping

Stripping HTML from a field in Oracle

Hi everyone, If you happen to save text that contains HTML in you database column and you don’t know how to get the raw text without the HTML tags, well here is a hack which i’ve found very handy.

Example

Table: Comments
Column name: COMMENT_TEXT

SQL >  Select comment_text from comments;
Result > <p><strong>Hi everyone</strong>, this is a example on how to <span> strip HTML tags</span> from a SQL query in oracle</p>

Hack:
SQL >
select replace(replace(replace(replace(replace(REGEXP_REPLACE(COMMENT_TEXT, ‘< (.|\n)*?>’, ”), ‘&’||’nbsp;’, ‘ ‘), ‘&’||’ldquo;’, ‘”‘),’&’||’rdquo;’, ‘”‘),’&’||’ndash;’, ‘-‘),’&’||’amp;’, ‘&’) from comments;

Result > Hi everyone, this is a example on how to strip HTML tags from a SQL query in oracle

Hope this helps someone 🙂