Ampersand(&) Issue on Oracle/PLSQL

Wednesday, June 11, 2008

Have you ever tried to insert a value to a column that contains ampersand(&) character? I have, and it's not working when i use the usual way. Ampersand character is made for input variable, so If you write query like
insert into tbl_name(column1, column2) values('me & you', 'him & her' )
a menu popup will show up asking you for a value.

A workaround for this annoying problem is using SET DEFINE OFF before the query, or using the SET ESCAPE, or editing the [orahome]/sqlplus/admin/glogin.sql to SET SCAN OFF, but those methods only work on SQL*Plus,unfortunately.

Other simple solution for this is by putting the ampersand at the end nex to a single quote, so the the previous query above would rather be insert into tbl_name(column1, column2) values('me &'||' you', 'him &'||' her). Don't ask me why.

If you're using ASP/PHP/{insert your favorite programming language here}, don't forget to replace the ampersand with the %26 character. It would be even better if you double check it on client side and server side. I believe every programming language out there have a built-in function for string replacement, eh ?

Anyway, hope this helps,

0 comments: