Q
Problem solve Get help with specific problems with your technologies, process and projects.

Deconcatenating a field

I have a table with two fields: id and name. The name field currently is a concatenation of varA-varB-varC. I want to convert the table so that the name field will only contain varC, i.e., delete varA-varB-. Example: from 001-a-12345, I want to update the field to only 12345. Can I do this in one update statement?

You can do this in one SQL statement. You'll have to use the INSTR function to find the last seperator character, '-' and the SUBSTR function to pull out what remains. For example:

UPDATE my_table
SET my_col=SUBSTR(my_col,INSTR(my_col,'-',-1)+1);

For More Information


Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close