Oracle string manipulation

I have the following string...

HUMAN RESOURCES_2013_09_10_13_42_57_VCISJMK

I need to be able to take the end of it off(VCISJMK) and replace it with a constant 'BANNER' with VCSIJMK at the end. So really I just need the BANNER inserted before the VCISJMK but it would prob be easier to take that off and build it with BANNER in front of it...

Anyway, I need
HUMAN RESOURCES_2013_09_10_13_42_57_VCISJMK
to be
HUMAN RESOURCES_2013_09_10_13_42_57_BANNER_VCISJMK


Thanks
jknj72Asked:
Who is Participating?
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:
Would a simple replace not work?


replace(mydatacol,'_VCISJMK','_BANNER_VCISJMK')


If the string can actually exist elsewhere in the string then:
regexp_replace(mydatacol,'_VCISJMK$','_BANNER_VCISJMK')
0
jknj72Author Commented:
Well yes but I have to be able to do this in a stored proc and they can all be different. The first value is what is being passed in and I need to be able to insert the BANNER and everything else needs to stay the same so if I can manipulate the parameter being passed in at the beginning of the proc then I will be good to go. the last prtion of the string is the userid so it will be different everytime but I will always be putting in BANNER
0
slightwv (䄆 Netminder) Commented:
For usernames in all upper case:
regexp_replace(mydatacolumn,'([A-Z]+$)','BANNER_\1')

We will need to know your username requirements and we can tweak this.

For example, can a username be lower case?
Can it actually include an underscore?
etc...
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

slightwv (䄆 Netminder) Commented:
If the username is upper case letters and numbers:
regexp_replace(mydatacolumn,'([A-Z0-9]+$)','BANNER_\1')

If the username is upper and lower case letters and numbers:
regexp_replace(mydatacolumn,'([a-zA-Z0-9]+$)','BANNER_\1')


In the future can you provide more information in the original question?  More about the specific requirements.

The follow up paragraph you posted would have been perfect.

Maybe this would have been better:

I have a string that has a username appended to it.  I need to add a word before the username.

For example:
HUMAN RESOURCES_2013_09_10_13_42_57_VCISJMK
HUMAN RESOURCES_2013_09_10_13_42_57_BOB

Everything after the last '_' is the username.

I need to add 'BANNER' in front of it.

Expected results:
HUMAN RESOURCES_2013_09_10_13_42_57_BANNER_VCISJMK
HUMAN RESOURCES_2013_09_10_13_42_57_BANNER_BOB

Usernames will always be upper case letters.
0

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:
Everything would be upper case so we can expect that

Sorry I get a little crazy when I write these questions. I will follow your example.

Let me test this and I will get back to you...
0
jknj72Author Commented:
That worked really well slight. Thanks again for your help.
0
jknj72Author Commented:
great job
0
slightwv (䄆 Netminder) Commented:
Glad to help.
0
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.