Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update column 2

Status
Not open for further replies.

GROKING

Programmer
Mar 8, 2005
26
US

I have a column called NAMES with data that looks like this:
google
google - content
google
google - content


I need to run an update to remove the ' - content' from the column.

here is what I have so far.
UPDATE TABLE
SET COLUMN NAMES = DECODE(NAMES,' - CONTENT', '')
WHERE NAMES LIKE '%CONTENT';

Is this the best function to use to remove the - content from each row??

Thanks for the help!!
 
The DECODE will not do what you want. Try:
Code:
UPDATE TABLE
SET    NAMES = SUBSTR(NAMES,1,LENGTH(NAMES) - 10)
WHERE  NAMES LIKE '% - CONTENT';

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~George Bernard Shaw[/sup]
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: Emu Products Plus
 
Just an FYI,
If you want to remove " - content" if it is anywhere in the string, you could do the following

UPDATE TABLE
SET NAMES = replace(NAMES,' - content')
WHERE NAMES LIKE '% - content%';

Bill
Oracle DBA/Developer
New York State, USA
 
Bill,

Here is a slight brain teaser: what code would you use to remove ' - content', regardless of the case of its characters, and still regardless of its position in the NAMES column?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
Assuming that there is only one "- content" in the string, then

Code:
 select DECODE(INSTR(UPPER(NAMES),' - CONTENT'),0,NAMES,
        DECODE(INSTR(UPPER(NAMES),' - CONTENT'),1,
               SUBSTR(NAMES,INSTR(UPPER(NAMES),' - CONTENT')+10),
               SUBSTR(NAMES,1,INSTR(UPPER(NAMES),' - CONTENT')-1)||
               SUBSTR(NAMES,INSTR(UPPER(NAMES),' - CONTENT')+10))) NAMES
 FROM TABLE;

Bill
Oracle DBA/Developer
New York State, USA
 
Great work, Bill, but Oracle doesn't allow one to make this one look "pretty", do they?

Have a star for all of the work that you've put in on this thread today. [2thumbsup]

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
Thanks for the star. It is always nice to get a star from someone as good as you. Absolutely no sarcasm intended.

Bill
Oracle DBA/Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top