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
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
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.