Home » SQL & PL/SQL » SQL & PL/SQL » remove html tags (10g)
remove html tags [message #486309] Tue, 14 December 2010 12:32 Go to next message
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 #486311 is a reply to message #486309] Tue, 14 December 2010 12:39 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>is there any function in oracle which removes all html tags

Which part of the Posting Guidelines ( http://www.orafaq.com/forum/t/88153/0/ ) did you NOT read & follow?
Was it the part about using SEARCH ( http://www.orafaq.com/forum/s/136107/ ) or GOOGLE ( http://google.com ) before posting?

http://www.lmgtfy.com/?q=oracle+removes+html+tags

Re: remove html tags [message #486316 is a reply to message #486311] Tue, 14 December 2010 12:57 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
CREATE OR REPLACE FUNCTION no_html
  (p_string  IN CLOB)
  RETURN	CLOB
AS
  v_string_in   CLOB := p_string;
  v_string_out  CLOB;
BEGIN
  WHILE INSTR (v_string_in, '>') > 0 LOOP
    v_string_out := v_string_out
		 || SUBSTR (v_string_in, 1, INSTR (v_string_in, '<') - 1);
    v_string_in  := SUBSTR (v_string_in, INSTR (v_string_in, '>') + 1);
  END LOOP;
  v_string_out := v_string_out || v_string_in;
  RETURN v_string_out;
END no_html;
/ 

Re: remove html tags [message #486317 is a reply to message #486316] Tue, 14 December 2010 13:44 Go to previous messageGo to next message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Maybe this one:
select regexp_replace(val, '<[^>]+>', '') new_val from data

Regards
Michel
Re: remove html tags [message #486329 is a reply to message #486309] Tue, 14 December 2010 21:00 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
The above mentioned are just for giving a clue!
Based on this make your code because
--This is asktom function
SQL> select str_html('<p>He has to pay amount>$25 </p>') from dual;

STR_HTML('<P>HEHASTOPAYAMOUNT>$25</P>')
--------------------------------------------------------------------------------
He has to pay amount$25
--This is from Barbara Boehmer
SQL> select no_html('<p>He has to pay amount>$25 </p>') from dual;

NO_HTML('<P>HEHASTOPAYAMOUNT>$25</P>')
--------------------------------------------------------------------------------
He has to pay amount>$25 $25
--This is from Michel Cadot
SQL>  select regexp_replace('<p>He has to pay amount>$25 </p>', '<[^>]+>', '') new_val from dual;

NEW_VAL
-------------------------
He has to pay amount>$25

See this case if the input contains any "<" or ">" other than html tags..

SQL> select str_html('<p>He has to pay amount>$25 and this should be <$30 </p>') from dual;

STR_HTML('<P>HEHASTOPAYAMOUNT>$25ANDTHISSHOULDBE<$30</P>')
--------------------------------------------------------------------------------
He has to pay amount$25 and this should be

SQL> select no_html('<p>He has to pay amount>$25 and this should be <$30 </p>') from dual;

NO_HTML('<P>HEHASTOPAYAMOUNT>$25ANDTHISSHOULDBE<$30</P>')
--------------------------------------------------------------------------------
He has to pay amount>$25 and this should be $25 and this should be

SQL> select regexp_replace(<p>He has to pay amount>$25 and this should be <$30 </p>',
  2  '<[^>]+>', '') new_val from dual;
ERROR:
ORA-01756: quoted string not properly terminated


SQL> select regexp_replace('<p>He has to pay amount>$25 and this should be <$30 </p>',
  2  '<[^>]+>', '') new_val from dual;

NEW_VAL
--------------------------------------------
He has to pay amount>$25 and this should be

SQL> 


So make your own code based on the example provided

Sriram
Re: remove html tags [message #486330 is a reply to message #486329] Tue, 14 December 2010 21:04 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
http://www.orafaq.com/forum/mv/msg/153387/436395/136607/#msg_436395

sriram
Re: remove html tags [message #486331 is a reply to message #486330] Tue, 14 December 2010 21:42 Go to previous message
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> 

Previous Topic: Need help
Next Topic: how to get next not null value for current row
Goto Forum:
  


Current Time: Tue Sep 02 01:11:40 CDT 2025