remove html tags [message #486309] |
Tue, 14 December 2010 12:32  |
miroconnect@yahoo.com
Messages: 202 Registered: April 2006
|
Senior Member |
|
|
is there any function in oracle which removes all html tags
our web pages uses rich text editor, when user enters text into editorand saves it, the database will have text with formatting ie all html tags. this works fine as long we display this text in web pages , but some time we have to provide reports to user just by running sql and ouptut in excel, in this case I want to strip out all html tags within the text please suggest me if there is any function which can strip all html tags ?
|
|
|
|
|
|
|
|
Re: remove html tags [message #486331 is a reply to message #486330] |
Tue, 14 December 2010 21:42  |
 |
Barbara Boehmer
Messages: 9106 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
Oracle Text has a ctx_policy.filter procedure that converts a blob to a plain-text clob, stripping any html. However, it only works on blobs, not clobs or varchar2. As a workaround, you can convert a text string to a blob, then apply the ctx_policy.filter, as demonstrated below.
SCOTT@orcl_11gR2> BEGIN
2 CTX_DDL.CREATE_POLICY ('test_policy', 'CTXSYS.AUTO_FILTER');
3 END;
4 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> CREATE OR REPLACE FUNCTION no_html
2 (p_clob IN CLOB)
3 RETURN CLOB
4 AS
5 v_blob BLOB;
6 v_clob CLOB;
7 v_dest_offset NUMBER := 1;
8 v_src_offset NUMBER := 1;
9 v_lang NUMBER := 0;
10 v_warning VARCHAR2 (1000);
11 BEGIN
12 DBMS_LOB.CREATETEMPORARY (v_blob, FALSE);
13 DBMS_LOB.CONVERTTOBLOB
14 (v_blob,
15 p_clob,
16 DBMS_LOB.LOBMAXSIZE,
17 v_dest_offset,
18 v_src_offset,
19 DBMS_LOB.DEFAULT_CSID,
20 v_lang,
21 v_warning);
22 DBMS_LOB.CREATETEMPORARY (v_clob, TRUE);
23 CTX_DOC.POLICY_FILTER ('test_policy', v_blob, v_clob, TRUE);
24 DBMS_LOB.FREETEMPORARY (v_blob);
25 RETURN v_clob;
26 DBMS_LOB.FREETEMPORARY (v_clob);
27 END no_html;
28 /
Function created.
SCOTT@orcl_11gR2> select no_html('<p>He has to pay amount>$25 </p>') from dual
2 /
NO_HTML('<P>HEHASTOPAYAMOUNT>$25</P>')
--------------------------------------------------------------------------------
He has to pay amount>$25
1 row selected.
SCOTT@orcl_11gR2> select no_html('<p>He has to pay amount>$25 and this should be <$30 </p>') from dual
2 /
NO_HTML('<P>HEHASTOPAYAMOUNT>$25ANDTHISSHOULDBE<$30</P>')
--------------------------------------------------------------------------------
He has to pay amount>$25 and this should be <$30
1 row selected.
SCOTT@orcl_11gR2>
|
|
|