Additional logic to answered question

This is based off of question ID: 28683827. I had a question on how to return the last value in a string after any variations of LCF in between company names. I want to add some additional logic to the function.

If the string ends with any of the variations of LCF and there is no company name after the last LCF I want to identify it somehow and I will write it to a table. Im thinking that if this happens I want something returned that I can look for(lets say the string '999' for now) and Ill write the bad value to a table.

Just so you know, the table with the bad records will be sent to the department that handles these names and they will enter the correct company and we will fix the data.
Who is Participating?

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

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:
Small tweak to make the end in LCF work.  It will not return a NULL if there is nothing after the LCF.

WITH mydata 
     AS (SELECT 
     'MyText lost content for Company A LCF COMPANY B L/C/F COMPANY  C' col1 FROM   dual 
         UNION ALL 
         UNION ALL 
	SELECT 'end with L/C/F' col1 FROM   dual 
         UNION ALL 
         SELECT 'HEllo' FROM   dual) 
		Regexp_replace (Regexp_replace(col1, '[^[:alnum:] ]', NULL 
                                      , 1, 0, 
                                            'LOST CONTENT FOR|LOST CONTRACT_FOR' 
                      , 'LCF' 
                             , 1, 0, 'i')
		, '(.*LCF ?)(.*$)', '\2') 
FROM   mydata 


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
jknj72Author Commented:
>>It will not return a NULL if there is nothing after the LCF.

Did you mean that it will return a NULL? Which is fine because I can simply evaluate that.
slightwv (䄆 Netminder) Commented:
Yes, it WILL return a null...  or at least I hope...  since I can't type, I'm not sure.  ;)
jknj72Author Commented:
Don't worry I know what you meant....And I think you nailed it. Let me do additional testing and will let you know.

jknj72Author Commented:
great job
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.