Unix Technical Forum

SQL problem: How replace all ' with " from a column in a table?

This is a discussion on SQL problem: How replace all ' with " from a column in a table? within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hello, we have Oracle 9, and now I'm faced with this problem: I have to update an entire column ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 10:57 AM
John
 
Posts: n/a
Default SQL problem: How replace all ' with " from a column in a table?

Hello,
we have Oracle 9, and now I'm faced with this problem:

I have to update an entire column from a table which contains the
character

' (single quotes)

and replace it with

" (double quotes)

The column is about "Descriptions", and now the customer wants to
replace all occurences of the single quote with the double quote.

If it can help you I give you the names:

- table name: EVENT_LOGS
- column name: DESCRIPTION
- current character (eliminate): '
- to replace character: "

Can somebody please indicate me an SQL statement for updating the table
a replace all single quotes with double quotes?

Thank you very much for your help and have a good day
John

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 10:57 AM
Charles Hooper
 
Posts: n/a
Default Re: SQL problem: How replace all ' with " from a column in a table?

John wrote:
> Hello,
> we have Oracle 9, and now I'm faced with this problem:
>
> I have to update an entire column from a table which contains the
> character
>
> ' (single quotes)
>
> and replace it with
>
> " (double quotes)
>
> The column is about "Descriptions", and now the customer wants to
> replace all occurences of the single quote with the double quote.
>
> If it can help you I give you the names:
>
> - table name: EVENT_LOGS
> - column name: DESCRIPTION
> - current character (eliminate): '
> - to replace character: "
>
> Can somebody please indicate me an SQL statement for updating the table
> a replace all single quotes with double quotes?
>
> Thank you very much for your help and have a good day
> John


Try executing the following:
SELECT
CHR(39) SINGLE_QUOTE,
CHR(34) DOUBLE_QUOTE,
CHR(39) || 'TEST' || CHR(39) TEST,
REPLACE(CHR(39) || 'TEST' || CHR(39), CHR(39), CHR(34)) REPLACEMENT
FROM
DUAL;

If it works correctly, the first column should be a single quote, the
second column should be a double quote, the third column should be the
word TEST inside single quotes, and the forth column replaces the
single quotes in the third column with double quotes.

If the above works, try this to make certain that the replacement is
correctly taking place:
SELECT
REPLACE(CHR(39) || DESCRIPTION || CHR(39), CHR(39), CHR(34))
REPLACEMENT
FROM
EVENT_LOGS
WHERE
DESCRIPTION LIKE '%' || CHR(39) || '%';

If the above works, try this:
UPDATE
EVENT_LOGS
SET
DESCRIPTION=REPLACE(CHR(39) || DESCRIPTION || CHR(39), CHR(39),
CHR(34))
WHERE
DESCRIPTION LIKE '%' || CHR(39) || '%';

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com