I am creating JavaScript based on data in Oracle. This data can be free text entered by the user. The apostrophe character breaks the generated javascript. Here's how to search and replace it with the back quote character:
SELECT replace( COLUMN_NAME, chr(39), chr(96) ) FROM MYTABLE WHERE BLAH=FOO
replace has the following syntax:
replace( 'TEXT', 'string to replace'[, 'string to replace with'])
chr returns the character with the ASCII code given as a parameter. Since Oracle uses apostrophe's to denote strings, you can't put an apostrophe inside two apostrophes and need to use chr.
No comments:
Post a Comment