Extracting data from LONG datatype column that contains HTML tags.

Hi All,

While writing a report, I’m running into a road block when trying to extract data from a LONG datatype column that is stored with HTML tags.   I tried REGEXP_REPLACE but it does not accept LONG datatype column.

Here is an example of corrupted data:

1 record ….
<html>hard horn buttons</html>    

2nd record  …
<html><p class="MsoNormal">Good afternoon , on po number 57545 , part number 9362940 ,
p/s 449014 , we received 10 parts that are made incorrectly , please supply an
rma number to return these incorrect parts also I believe we should be holding
off on the remaining 115 on back order until vehicle improvements products
updates it’s product , please advise , thank you&nbsp;<o:p></o:p></p></html>

Desired Output:

1 record:  
hard horn buttons

2 record:
Good afternoon , on po number 57545 , part number 9362940 ,
p/s 449014 , we received 10 parts that are made incorrectly , please supply an
rma number to return these incorrect parts also I believe we should be holding
off on the remaining 115 on back order until vehicle improvements products
updates it’s product , please advise , thank you

Thanks in advance.
LVL 11
mohammadzahidAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
There is no 'easy' way to convert a LONG to a CLOB.

This is what I came up with.

See if it works for you:
drop table tab1 purge;
create table tab1(col1 long);

insert into tab1 values('<a>Hello</a>');
insert into tab1 values('<a><b class="q">Hello world</b></a>');
commit;

select * from tab1;

drop table tab1_clob purge;
create global temporary table tab1_clob(col1 clob) on commit preserve rows;

drop function myfunc;
create or replace function myfunc(p_rid rowid) return clob is
	v_clob clob;
	v_long long;
	PRAGMA AUTONOMOUS_TRANSACTION;

begin
	insert into tab1_clob (select to_lob(col1) from tab1 where rowid = p_rid);
	select col1 into v_clob from tab1_clob;
	delete from tab1_clob;
	commit;
	return v_clob;
end;
/

show errors

select regexp_replace(myfunc(rowid),'<[^>]*>') from tab1;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.