views:

813

answers:

5

Does anyone know a SQL command to replace MS Office smart quotes with their ASCII cousins? I'm using an oracle database and the fields are of type varchar2

+2  A: 
REPLACE(REPLACE(str, '`', ''''), '´', '''')

Or am I missing your question?

erikkallen
A: 
update table set column = replace( column, string_to_replace, [ replacement_string ] )
cdonner
+2  A: 

update table set column = replace(replace(column, chr(147),'"'), chr(148), '"')

Rich
This is right if the character set in the database is code page 1252 (Western European) or a few similar code pages. For other charsets, smart quotes may be encoded differently.
bobince
code pages schmode pages...You are correct, of course.
Rich
A: 

TRANSLATE would be more appropriate than REPLACE.

TRANSLATE(str, '`´', '''''')

http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions204.htm#sthref2477

David Aldridge
A: 

Hi, I have had a similar problem. For me after the quotes were stored in the database they appeared thus "Â’".

SELECT abstract FROM foo WHERE version = '1.0' and newscode = 'au20309';

MaeÂ’r ffordd gynaliadwy y mae bwyd yn cael ei dyfu, ei brynu aÂ’i baratoi ...

This is how I replaced them. First find the ascii value for that unusual "Â" character.

SELECT ascii('Â') FROM DUAL; -- returns 50050

Then use the chr function to render the "Â". The || function concatenate the two characters. The q function is useful to 'quote' the smart quote string..

SELECT REPLACE(abstract,chr(50050) || q'#’#' , q'#'#') 
FROM foo 
WHERE version = '1.0' and newscode = 'au20309';

Mae'r ffordd gynaliadwy y mae bwyd yn cael ei dyfu, ei brynu a'i baratoi ...

This worked just fine for me on our Oracle 10 system.

aberpaul