143

When I try to execute this statement in Oracle SQL Developer 2.1 a dialog box "Enter Substitution Variable" pops up asking for a replacement value for TOBAGO,

update t set country = 'Trinidad and Tobago' where country = 'trinidad & tobago';

How can I avoid this without resorting to chr(38) or u'trinidad \0026 tobago' which both obscure the purpose of the statement?

1
  • 1
    That's strange, when I attempted to run a query exactly like that in SQL developer 2.1 I did not get the replacement variable window? (And my defines are most certainly set to on) Commented Feb 25, 2010 at 12:55

6 Answers 6

235

Call this before the query:

set define off

Alternatively, hacky:

update t set country = 'Trinidad and Tobago' where country = 'trinidad &' || ' tobago';

From Tuning SQL*Plus:

SET DEFINE OFF disables the parsing of commands to replace substitution variables with their values.

Sign up to request clarification or add additional context in comments.

3 Comments

What (else) does set define off; do?
SET DEFINE OFF: Invalid "set define" command
use "set escape \" instead and then escape & by doing \&
16

In SQL*Plus putting SET DEFINE ? at the top of the script will normally solve this. Might work for Oracle SQL Developer as well.

3 Comments

SET DEFINE ? does suppress the variable substitution behaviour in SQL Developer 2.1. As noted by Nick SET DEFINE OFF also works.
set define works but the DBA wont allow to use it sometimes i dont know why
Doesn't work. Invalid "set define" command
1

this will work as you asked without CHAR(38):

update t set country = 'Trinidad and Tobago' where country = 'trinidad & '|| 'tobago';

create table table99(col1 varchar(40));
insert into table99 values('Trinidad &' || '  Tobago');
insert into table99 values('Trinidad &' || '  Tobago');
insert into table99 values('Trinidad &' || '  Tobago');
insert into table99 values('Trinidad &' || '  Tobago');
SELECT * FROM table99;

update table99 set col1 = 'Trinidad and Tobago' where col1 = 'Trinidad &'||'  Tobago';

4 Comments

My question was how this could be done without using chr(38).
@JanekBogucki take it it correct now without using CHAR(38)
i gave you a different answer as you already have green ticked answer but you downvoted
Mate you cannot imagine what an agony you solved for me, sql developer does not accept set define off when you run a script. This the solution for me
1

If you use liquibase to run sql file, it will not give error. But for sql developer use this set define off; before ur sql sode

Comments

0

While set define off works, you run into the problem of not being able to use Substitution Variables in the same query as an Ampersand. A clearer way would be to turn on the Escape character and then escape the Ampersand.

e.g.,

set escape \

update t 
set country = 'Trinidad and Tobago' 
where country = 'trinidad \& tobago';

The backslash (\) is the default escape character, but it seems to be turned off by default as well.

Comments

-3

set scan off; Above command also works.

1 Comment

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you earn sufficient reputation you will be able to comment on any post. If you have a related but different question, ask a new question referencing this one if it will help provide context.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.