Friday, October 30, 2009

Escaping & in SQL

SQL *PLUS treats the '&' in queries as a substitution variable by default.
If you are using SQL Developer, you might get an unexpected resposne if you have '&' in your query.
It prompts you for a value for the string that follows. For example if you have a query like

Select * from emp where name = 'Carrol & Scott',

you will get a pop up a message like 'enter value for scott' or something like that.

In such cases, turn off substitution by using 'SET DEFINE OFF' or you can tell SQL *PLUS to use a different character for substitution like 'SET DEFINE $'

I didn't have this problem with SQL Navigator or JDBC. So, it's not a problem with Oracle.