Skip to Main Content

SQL Developer

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Escaping ampersand (&) in queries

51564Jan 23 2007 — edited Oct 11 2007
How do I escape an ampersand in a query executed in the SQL Worksheet in SQL Developer? For example if my query is:

SELECT * FROM EMPLOYEES WHERE status = 'Hired &Fired';

If I execute this query now in SQLD, it asks me to enter a parameter for &Fired, whereas in this case, ampersand is a value in the column status in this table.

Thanks for all the help,
Alex

Comments

484267
I would call this a bug.. Here is what I found for a workaround:

SELECT 'Free &' || ' Clear' FROM DUAL;
448576
set define off
works (as long as you are happy for it to never ask for bind variables)
441662
Like GaryM said,

SET DEFINE OFF;

Will work to turn the prompting for variable off..

See this for other sqlplus commands that work in Oracle SQL Developer.
http://www.oracle.com/technology/products/database/sql_developer/files/sql_worksheet_commands_v1_1.html

And I think Eric may have been trying to say a query escaped but the backslash may have not shown. Sometimes web pages strip out characters.

SET ESCAPE ON;
SELECT 'blah \& blah' AS DES FROM DUAL;

'blah backslash ampersand blah'

If you set escape on, it uses an esape using the backslash. So, backslash ampersand will show you an ampersand.

SQL*Plus User's Guide and Reference
Release 9.2
http://download-east.oracle.com/docs/cd/B10501_01/server.920/a90842/toc.htm

Hope this helps.
SueHarper
Alex,

I have logged the need to support the SQL*Plus command, "Set Escape". In the meantime you'll need to use Eric's workaround.

Regards
Sue
ChrisR
Another question relating to this one.

Is it possible to set a different define character using SQL Developer preferences or do I have to use the SET DEFINE ¬ (for example) command in the SQL Worksheet ?

It would be nice to have a preferences section to control how SQL Worksheet behaves within SQL Developer. Something like the Options -> Environment in the GUI version of SQL*Plus.

Thanks

Chris
277980
Hi, I've installed version 1.1.2 and in documentation i've found that "SET ESCAPE" is now supported (see http://www.oracle.com/technology/products/database/sql_developer/files/relnotes_v112.html)
I've tried but without success (I want to see "TEST1&TEST2 in field1):

SET ESCAPE ON
UPDATE TABLE1 SET FIELD1='TEST1\&TEST2';

Sqldeveloper still ask me for variable TEST2. If I try to use SET DEFINE OFF the result in FIELD1 is "TEST1\&TEST2"

I need SET ESCAPE ON features because I need full compatibility with SQL*PLUS

Thank
SueHarper
Works for me. I'm on 1.1.2.25.79

I did 2 tests:

SET ESCAPE ON
select 'TEST1\&TEST2'
from dual;

UPDATE TABLE1
SET FIELD1='TEST1\&TEST2';

The update added TEST1&TEST2 in the field and the select from dual worked too. No prompting.

Sue
277980
I'm also on 1.1.2.25.79 but my result is:

SET ESCAPE ON
select 'TEST1\&TEST2' from dual;

'TEST1\&TEST2'
--------------
TEST1\&TEST2

1 rows selected

Have you any idea?

Thanks in advance
SueHarper
It looks like setting the command is not picking up the default escape of \.

Try adding SET ESCAPE \ before your query.

Sue
277980
Works fine!!!

Thank Sue. I'ven't tried this because in TOAD e in SQL*PLUS is probably the default and I don't remember to SET ESCAPE \

Bye
277980
Hi, I've found another stange behaviour in escaping ampersand (&):

set ESCAPE \
select 'TEST1\&TEST2\&TEST3' from dual;

'TEST1&TEST2\&TEST3'
--------------------
TEST1&TEST2\&TEST3

Only first occurency of & was substituted. Help me!!

Thanks
Looks like a bug (now logged as bug
Bug No: 6494839 SET ESCAPE \SELECT 'TEST1\&TEST2\&TEST3' FROM DUAL;
in the escape processing.)
Can you use something like:

set define off
select 'TEST1&TEST2&TEST3' from dual;

-Turloch
277980
Ok. Work around works. I'll wait for bug correction

Thanks
Fixed in code in development, escape was switched on but never switched off for the statement, this has been fixed to reset the escape flag back to off/false.

-Turloch
1 - 14
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 8 2007
Added on Jan 23 2007
14 comments
302,245 views